@playcademy/sdk 0.0.1-beta.16 → 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.
@@ -0,0 +1,23 @@
1
+ import type { PlaycademyClient } from '../client';
2
+ /**
3
+ * Creates the authentication namespace for the PlaycademyClient.
4
+ * Provides methods for managing user authentication state.
5
+ *
6
+ * @param client - The PlaycademyClient instance
7
+ * @returns Authentication namespace with logout method
8
+ */
9
+ export declare function createAuthNamespace(client: PlaycademyClient): {
10
+ /**
11
+ * Logs out the current user and clears the authentication token.
12
+ * Sends a logout request to the server and removes the token from the client.
13
+ *
14
+ * @returns Promise that resolves when logout is complete
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * await client.auth.logout()
19
+ * console.log('User logged out successfully')
20
+ * ```
21
+ */
22
+ logout: () => Promise<void>;
23
+ };
@@ -0,0 +1,152 @@
1
+ import type { PlaycademyClient } from '../client';
2
+ import type { Game, UpsertGameMetadataInput } from '@playcademy/types';
3
+ import type { DeveloperStatusValue } from '../../types';
4
+ /**
5
+ * Creates the developer namespace for the PlaycademyClient.
6
+ * Provides methods for developer account management, game publishing, and API key management.
7
+ *
8
+ * @param client - The PlaycademyClient instance
9
+ * @returns Developer namespace with auth, games, and keys methods
10
+ */
11
+ export declare function createDevNamespace(client: PlaycademyClient): {
12
+ /**
13
+ * Developer authentication and status methods.
14
+ */
15
+ auth: {
16
+ /**
17
+ * Applies for developer status for the current user.
18
+ *
19
+ * @returns Promise that resolves when application is submitted
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * await client.dev.auth.applyForDeveloper()
24
+ * console.log('Developer application submitted')
25
+ * ```
26
+ */
27
+ applyForDeveloper: () => Promise<void>;
28
+ /**
29
+ * Gets the current developer status for the user.
30
+ *
31
+ * @returns Promise resolving to developer status value
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const status = await client.dev.auth.getDeveloperStatus()
36
+ * if (status === 'approved') {
37
+ * console.log('Developer access granted')
38
+ * }
39
+ * ```
40
+ */
41
+ getDeveloperStatus: () => Promise<DeveloperStatusValue>;
42
+ };
43
+ /**
44
+ * Game management methods for developers.
45
+ */
46
+ games: {
47
+ /**
48
+ * Creates or updates a game with metadata and asset bundle.
49
+ *
50
+ * @param slug - The game slug (URL-friendly identifier)
51
+ * @param metadata - Game metadata (title, description, etc.)
52
+ * @param file - Game asset bundle file (zip)
53
+ * @returns Promise resolving to the created/updated game
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const gameFile = new File([zipData], 'game.zip')
58
+ * const game = await client.dev.games.upsert('my-game', {
59
+ * title: 'My Awesome Game',
60
+ * description: 'A fun puzzle game'
61
+ * }, gameFile)
62
+ * ```
63
+ */
64
+ upsert: (slug: string, metadata: UpsertGameMetadataInput, file: File | Blob) => Promise<Game>;
65
+ /**
66
+ * Updates specific properties of an existing game.
67
+ *
68
+ * @param gameId - The game ID to update
69
+ * @param props - Partial game properties to update
70
+ * @returns Promise that resolves when update is complete
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * await client.dev.games.update('game-123', {
75
+ * title: 'Updated Game Title',
76
+ * isPublic: true
77
+ * })
78
+ * ```
79
+ */
80
+ update: (gameId: string, props: Partial<Game>) => Promise<void>;
81
+ /**
82
+ * Deletes a game permanently.
83
+ *
84
+ * @param gameId - The game ID to delete
85
+ * @returns Promise that resolves when deletion is complete
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * await client.dev.games.delete('game-123')
90
+ * console.log('Game deleted successfully')
91
+ * ```
92
+ */
93
+ delete: (gameId: string) => Promise<void>;
94
+ };
95
+ /**
96
+ * API key management methods for developers.
97
+ */
98
+ keys: {
99
+ /**
100
+ * Creates a new API key for a game.
101
+ *
102
+ * @param gameId - The game ID to create a key for
103
+ * @param label - Optional label for the key
104
+ * @returns Promise resolving to the created API key
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const key = await client.dev.keys.createKey('game-123', 'Production Key')
109
+ * console.log('API Key:', key.key)
110
+ * ```
111
+ */
112
+ createKey: (gameId: string, label?: string) => Promise<{
113
+ id: string;
114
+ createdAt: Date;
115
+ userId: string;
116
+ label: string | null;
117
+ keyHash: string;
118
+ }>;
119
+ /**
120
+ * Lists all API keys for a game.
121
+ *
122
+ * @param gameId - The game ID to list keys for
123
+ * @returns Promise resolving to array of API keys
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const keys = await client.dev.keys.listKeys('game-123')
128
+ * keys.forEach(key => console.log(`${key.label}: ${key.key}`))
129
+ * ```
130
+ */
131
+ listKeys: (gameId: string) => Promise<{
132
+ id: string;
133
+ createdAt: Date;
134
+ userId: string;
135
+ label: string | null;
136
+ keyHash: string;
137
+ }[]>;
138
+ /**
139
+ * Revokes (deletes) an API key.
140
+ *
141
+ * @param keyId - The key ID to revoke
142
+ * @returns Promise that resolves when key is revoked
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * await client.dev.keys.revokeKey('key-456')
147
+ * console.log('API key revoked')
148
+ * ```
149
+ */
150
+ revokeKey: (keyId: string) => Promise<void>;
151
+ };
152
+ };
@@ -0,0 +1,97 @@
1
+ import type { PlaycademyClient } from '../client';
2
+ import type { Game, GameWithManifest } from '@playcademy/types';
3
+ import type { GameState, StartSessionResponse } from '../../types';
4
+ /**
5
+ * Creates the games namespace for the PlaycademyClient.
6
+ * Provides methods for managing games, game state, and game sessions.
7
+ *
8
+ * @param client - The PlaycademyClient instance
9
+ * @returns Games namespace with fetch, list, state, and session methods
10
+ */
11
+ export declare function createGamesNamespace(client: PlaycademyClient): {
12
+ /**
13
+ * Fetches a game by ID or slug, including its manifest data.
14
+ * Combines game metadata with the game's asset manifest.
15
+ *
16
+ * @param gameIdOrSlug - The game ID or slug to fetch
17
+ * @returns Promise resolving to game data with manifest
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const game = await client.games.fetch('my-game-123')
22
+ * console.log('Game title:', game.title)
23
+ * console.log('Assets:', game.manifest.assets)
24
+ * ```
25
+ */
26
+ fetch: (gameIdOrSlug: string) => Promise<GameWithManifest>;
27
+ /**
28
+ * Lists all available games.
29
+ *
30
+ * @returns Promise resolving to array of games
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const games = await client.games.list()
35
+ * games.forEach(game => console.log(game.title))
36
+ * ```
37
+ */
38
+ list: () => Promise<Array<Game>>;
39
+ /**
40
+ * Saves the current game state to the server.
41
+ * Requires a gameId to be configured in the client.
42
+ *
43
+ * @param state - The game state object to save
44
+ * @returns Promise that resolves when state is saved
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * await client.games.saveState({
49
+ * level: 5,
50
+ * score: 1250,
51
+ * inventory: ['sword', 'potion']
52
+ * })
53
+ * ```
54
+ */
55
+ saveState: (state: Record<string, unknown>) => Promise<void>;
56
+ /**
57
+ * Loads the saved game state from the server.
58
+ * Requires a gameId to be configured in the client.
59
+ *
60
+ * @returns Promise resolving to the saved game state
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const state = await client.games.loadState()
65
+ * console.log('Current level:', state.level)
66
+ * ```
67
+ */
68
+ loadState: () => Promise<GameState>;
69
+ /**
70
+ * Starts a new game session.
71
+ *
72
+ * @param gameId - Optional game ID (uses client's gameId if not provided)
73
+ * @returns Promise resolving to session information
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const session = await client.games.startSession('game-123')
78
+ * console.log('Session ID:', session.sessionId)
79
+ * ```
80
+ */
81
+ startSession: (gameId?: string) => Promise<StartSessionResponse>;
82
+ /**
83
+ * Ends an active game session.
84
+ * Automatically clears internal session tracking if ending the client's own session.
85
+ *
86
+ * @param sessionId - The session ID to end
87
+ * @param gameId - Optional game ID (uses client's gameId if not provided)
88
+ * @returns Promise that resolves when session is ended
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * await client.games.endSession('session-456', 'game-123')
93
+ * console.log('Session ended')
94
+ * ```
95
+ */
96
+ endSession: (sessionId: string, gameId?: string) => Promise<void>;
97
+ };
@@ -0,0 +1,9 @@
1
+ export { createAuthNamespace } from './auth';
2
+ export { createRuntimeNamespace } from './runtime';
3
+ export { createGamesNamespace } from './games';
4
+ export { createUsersNamespace } from './users';
5
+ export { createDevNamespace } from './dev';
6
+ export { createMapsNamespace } from './maps';
7
+ export { createAdminNamespace } from './admin';
8
+ export { createShopNamespace } from './shop';
9
+ export { createTelemetryNamespace } from './telemetry';
@@ -0,0 +1,37 @@
1
+ import type { PlaycademyClient } from '../client';
2
+ /**
3
+ * Creates the maps namespace for the PlaycademyClient.
4
+ * Provides methods for retrieving map data and elements.
5
+ *
6
+ * @param client - The PlaycademyClient instance
7
+ * @returns Maps namespace with element retrieval methods
8
+ */
9
+ export declare function createMapsNamespace(client: PlaycademyClient): {
10
+ /**
11
+ * Retrieves all elements for a specific map.
12
+ *
13
+ * @param mapId - The ID of the map to get elements for
14
+ * @returns Promise resolving to array of map elements
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const elements = await client.maps.elements('map-123')
19
+ * elements.forEach(element => {
20
+ * console.log(`Element: ${element.type} at (${element.x}, ${element.y})`)
21
+ * })
22
+ * ```
23
+ */
24
+ elements: (mapId: string) => Promise<{
25
+ id: string;
26
+ metadata: ({
27
+ description?: string | undefined;
28
+ sourceTiledObjects?: Record<string, unknown>[] | undefined;
29
+ } & {
30
+ [k: string]: unknown;
31
+ }) | null;
32
+ gameId: string | null;
33
+ mapId: string | null;
34
+ elementSlug: string;
35
+ interactionType: "game_entry" | "game_registry" | "info" | "teleport" | "door_in" | "door_out" | "npc_interaction" | "quest_trigger";
36
+ }[]>;
37
+ };
@@ -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
+ };
@@ -0,0 +1,2 @@
1
+ export { init } from './init';
2
+ export { login } from './login';
@@ -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>;
@@ -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 { bus, BusEvents } from './bus';
9
+ export type * from './types';