@playcademy/sdk 0.0.1-beta.2 → 0.0.1-beta.21
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 +11 -7
- package/dist/core/client.d.ts +216 -38
- package/dist/core/namespaces/admin.d.ts +377 -0
- package/dist/core/namespaces/auth.d.ts +23 -0
- package/dist/core/namespaces/dev.d.ts +152 -0
- package/dist/core/namespaces/games.d.ts +97 -0
- package/dist/core/namespaces/index.d.ts +9 -0
- package/dist/core/namespaces/maps.d.ts +37 -0
- package/dist/core/namespaces/runtime.d.ts +45 -0
- package/dist/core/namespaces/shop.d.ts +26 -0
- package/dist/core/namespaces/telemetry.d.ts +28 -0
- package/dist/core/namespaces/users.d.ts +84 -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 +9 -0
- package/dist/index.js +584 -0
- package/dist/messaging.d.ts +510 -0
- package/dist/types.d.ts +31 -3
- package/package.json +11 -10
- package/dist/bus.d.ts +0 -37
- package/dist/runtime.d.ts +0 -7
- package/dist/runtime.js +0 -370
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PlaycademyClient } from '../client';
|
|
2
|
+
import type { GameTokenResponse } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the runtime namespace for the PlaycademyClient.
|
|
5
|
+
* Provides methods for managing game runtime operations and lifecycle.
|
|
6
|
+
*
|
|
7
|
+
* @param client - The PlaycademyClient instance
|
|
8
|
+
* @returns Runtime namespace with game token and exit methods
|
|
9
|
+
*/
|
|
10
|
+
export declare function createRuntimeNamespace(client: PlaycademyClient): {
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves a game token for the specified game.
|
|
13
|
+
* Optionally applies the token to the current client instance.
|
|
14
|
+
*
|
|
15
|
+
* @param gameId - The ID of the game to get a token for
|
|
16
|
+
* @param options - Optional configuration
|
|
17
|
+
* @param options.apply - Whether to automatically apply the token to this client
|
|
18
|
+
* @returns Promise resolving to game token response
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Get token without applying it
|
|
23
|
+
* const tokenResponse = await client.runtime.getGameToken('game-123')
|
|
24
|
+
*
|
|
25
|
+
* // Get token and apply it to current client
|
|
26
|
+
* const tokenResponse = await client.runtime.getGameToken('game-123', { apply: true })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
getGameToken: (gameId: string, options?: {
|
|
30
|
+
apply?: boolean;
|
|
31
|
+
}) => Promise<GameTokenResponse>;
|
|
32
|
+
/**
|
|
33
|
+
* Gracefully exits the game runtime.
|
|
34
|
+
* Automatically ends any active game session and emits an exit event.
|
|
35
|
+
*
|
|
36
|
+
* @returns Promise that resolves when exit is complete
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // Clean up and exit the game
|
|
41
|
+
* await client.runtime.exit()
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
exit: () => Promise<void>;
|
|
45
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PlaycademyClient } from '../client';
|
|
2
|
+
import type { ShopViewResponse } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the shop namespace for the PlaycademyClient.
|
|
5
|
+
* Provides methods for viewing shop listings and items available for purchase.
|
|
6
|
+
*
|
|
7
|
+
* @param client - The PlaycademyClient instance
|
|
8
|
+
* @returns Shop namespace with view methods
|
|
9
|
+
*/
|
|
10
|
+
export declare function createShopNamespace(client: PlaycademyClient): {
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves the current shop view with available listings.
|
|
13
|
+
* Returns all items currently available for purchase in the shop.
|
|
14
|
+
*
|
|
15
|
+
* @returns Promise resolving to shop view data with listings
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const shopData = await client.shop.view()
|
|
20
|
+
* shopData.listings.forEach(listing => {
|
|
21
|
+
* console.log(`${listing.item.name}: ${listing.price} ${listing.currency.symbol}`)
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
view: () => Promise<ShopViewResponse>;
|
|
26
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PlaycademyClient } from '../client';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the telemetry namespace for the PlaycademyClient.
|
|
4
|
+
* Provides methods for sending analytics and metrics data to the platform.
|
|
5
|
+
*
|
|
6
|
+
* @param client - The PlaycademyClient instance
|
|
7
|
+
* @returns Telemetry namespace with metrics methods
|
|
8
|
+
*/
|
|
9
|
+
export declare function createTelemetryNamespace(client: PlaycademyClient): {
|
|
10
|
+
/**
|
|
11
|
+
* Sends custom metrics data to the telemetry system.
|
|
12
|
+
* Useful for tracking game events, performance metrics, and analytics.
|
|
13
|
+
*
|
|
14
|
+
* @param metrics - Object containing metric names and their numeric values
|
|
15
|
+
* @returns Promise that resolves when metrics are successfully sent
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* await client.telemetry.pushMetrics({
|
|
20
|
+
* 'level_completed': 1,
|
|
21
|
+
* 'score': 1250,
|
|
22
|
+
* 'time_played_seconds': 180,
|
|
23
|
+
* 'enemies_defeated': 15
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
pushMetrics: (metrics: Record<string, number>) => Promise<void>;
|
|
28
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { InventoryItemWithItem, InventoryMutationResponse } from '../../types';
|
|
2
|
+
import type { PlaycademyClient } from '../client';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the users namespace for the PlaycademyClient.
|
|
5
|
+
* Provides methods for managing user data and inventory operations.
|
|
6
|
+
*
|
|
7
|
+
* @param client - The PlaycademyClient instance
|
|
8
|
+
* @returns Users namespace with user profile and inventory methods
|
|
9
|
+
*/
|
|
10
|
+
export declare function createUsersNamespace(client: PlaycademyClient): {
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves the current user's profile information.
|
|
13
|
+
*
|
|
14
|
+
* @returns Promise resolving to user profile data
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const user = await client.users.me()
|
|
19
|
+
* console.log('Username:', user.username)
|
|
20
|
+
* console.log('Email:', user.email)
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
me: () => Promise<{
|
|
24
|
+
id: string;
|
|
25
|
+
createdAt: Date;
|
|
26
|
+
updatedAt: Date;
|
|
27
|
+
name: string;
|
|
28
|
+
username: string | null;
|
|
29
|
+
email: string;
|
|
30
|
+
emailVerified: boolean;
|
|
31
|
+
image: string | null;
|
|
32
|
+
role: "admin" | "player" | "developer";
|
|
33
|
+
developerStatus: "none" | "pending" | "approved";
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Inventory management methods for the current user.
|
|
37
|
+
*/
|
|
38
|
+
inventory: {
|
|
39
|
+
/**
|
|
40
|
+
* Retrieves the user's complete inventory.
|
|
41
|
+
*
|
|
42
|
+
* @returns Promise resolving to array of inventory items with item details
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const inventory = await client.users.inventory.get()
|
|
47
|
+
* inventory.forEach(item => {
|
|
48
|
+
* console.log(`${item.item.name}: ${item.quantity}`)
|
|
49
|
+
* })
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
get: () => Promise<InventoryItemWithItem[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Adds items to the user's inventory.
|
|
55
|
+
* Emits an 'inventoryChange' event when successful.
|
|
56
|
+
*
|
|
57
|
+
* @param itemId - The ID of the item to add
|
|
58
|
+
* @param qty - The quantity to add (must be positive)
|
|
59
|
+
* @returns Promise resolving to mutation response with new total
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const result = await client.users.inventory.add('gold-coin', 100)
|
|
64
|
+
* console.log('New total:', result.newTotal)
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
add: (itemId: string, qty: number) => Promise<InventoryMutationResponse>;
|
|
68
|
+
/**
|
|
69
|
+
* Spends (removes) items from the user's inventory.
|
|
70
|
+
* Emits an 'inventoryChange' event when successful.
|
|
71
|
+
*
|
|
72
|
+
* @param itemId - The ID of the item to spend
|
|
73
|
+
* @param qty - The quantity to spend (must be positive)
|
|
74
|
+
* @returns Promise resolving to mutation response with new total
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const result = await client.users.inventory.spend('health-potion', 1)
|
|
79
|
+
* console.log('Remaining potions:', result.newTotal)
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
spend: (itemId: string, qty: number) => Promise<InventoryMutationResponse>;
|
|
83
|
+
};
|
|
84
|
+
};
|
package/dist/core/request.d.ts
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PlaycademyClient } from '../client';
|
|
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,9 @@
|
|
|
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';
|
|
9
|
+
export type * from './types';
|