@playcademy/sdk 0.0.4 → 0.0.6
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/dist/index.d.ts +3998 -7
- package/dist/index.js +1770 -1750
- package/dist/types.d.ts +4224 -28
- package/dist/types.js +1 -748
- package/package.json +5 -3
- package/dist/core/auth/flows/popup.d.ts +0 -14
- package/dist/core/auth/flows/redirect.d.ts +0 -15
- package/dist/core/auth/flows/unified.d.ts +0 -11
- package/dist/core/auth/login.d.ts +0 -20
- package/dist/core/auth/oauth.d.ts +0 -115
- package/dist/core/auth/utils.d.ts +0 -23
- package/dist/core/cache/cooldown-cache.d.ts +0 -31
- package/dist/core/cache/index.d.ts +0 -14
- package/dist/core/cache/permanent-cache.d.ts +0 -39
- package/dist/core/cache/singleton-cache.d.ts +0 -29
- package/dist/core/cache/ttl-cache.d.ts +0 -54
- package/dist/core/cache/types.d.ts +0 -23
- package/dist/core/client.d.ts +0 -520
- package/dist/core/errors.d.ts +0 -11
- package/dist/core/namespaces/achievements.d.ts +0 -84
- package/dist/core/namespaces/admin.d.ts +0 -385
- package/dist/core/namespaces/auth.d.ts +0 -54
- package/dist/core/namespaces/character.d.ts +0 -205
- package/dist/core/namespaces/credits.d.ts +0 -51
- package/dist/core/namespaces/dev.d.ts +0 -323
- package/dist/core/namespaces/games.d.ts +0 -173
- package/dist/core/namespaces/identity.d.ts +0 -91
- package/dist/core/namespaces/index.d.ts +0 -19
- package/dist/core/namespaces/leaderboard.d.ts +0 -48
- package/dist/core/namespaces/levels.d.ts +0 -90
- package/dist/core/namespaces/maps.d.ts +0 -93
- package/dist/core/namespaces/realtime.client.d.ts +0 -129
- package/dist/core/namespaces/realtime.d.ts +0 -90
- package/dist/core/namespaces/runtime.d.ts +0 -222
- package/dist/core/namespaces/scores.d.ts +0 -55
- package/dist/core/namespaces/shop.d.ts +0 -25
- package/dist/core/namespaces/sprites.d.ts +0 -35
- package/dist/core/namespaces/telemetry.d.ts +0 -28
- package/dist/core/namespaces/timeback.d.ts +0 -111
- package/dist/core/namespaces/users.d.ts +0 -172
- package/dist/core/request.d.ts +0 -24
- package/dist/core/static/identity.d.ts +0 -37
- package/dist/core/static/index.d.ts +0 -3
- package/dist/core/static/init.d.ts +0 -21
- package/dist/core/static/login.d.ts +0 -34
- package/dist/messaging.d.ts +0 -544
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { PlaycademyClient, ShopViewResponse } from '../../types';
|
|
2
|
-
/**
|
|
3
|
-
* Creates the shop namespace for the PlaycademyClient.
|
|
4
|
-
* Provides methods for viewing shop listings and items available for purchase.
|
|
5
|
-
*
|
|
6
|
-
* @param client - The PlaycademyClient instance
|
|
7
|
-
* @returns Shop namespace with view methods
|
|
8
|
-
*/
|
|
9
|
-
export declare function createShopNamespace(client: PlaycademyClient): {
|
|
10
|
-
/**
|
|
11
|
-
* Retrieves the current shop view with available listings.
|
|
12
|
-
* Returns all items currently available for purchase in the shop.
|
|
13
|
-
*
|
|
14
|
-
* @returns Promise resolving to shop view data with listings
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* const shopData = await client.shop.view()
|
|
19
|
-
* shopData.listings.forEach(listing => {
|
|
20
|
-
* console.log(`${listing.item.name}: ${listing.price} ${listing.currency.symbol}`)
|
|
21
|
-
* })
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
view: () => Promise<ShopViewResponse>;
|
|
25
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { SpriteTemplateData } from '@playcademy/data/types';
|
|
2
|
-
import type { PlaycademyClient } from '../../types';
|
|
3
|
-
/**
|
|
4
|
-
* Creates the sprites namespace for the PlaycademyClient.
|
|
5
|
-
* Provides methods for managing sprite templates and related data.
|
|
6
|
-
*
|
|
7
|
-
* @param client - The PlaycademyClient instance
|
|
8
|
-
* @returns Sprites namespace with template methods
|
|
9
|
-
*/
|
|
10
|
-
export declare function createSpritesNamespace(client: PlaycademyClient): {
|
|
11
|
-
/**
|
|
12
|
-
* Sprite templates sub-namespace
|
|
13
|
-
*/
|
|
14
|
-
templates: {
|
|
15
|
-
/**
|
|
16
|
-
* Gets a sprite template by its slug.
|
|
17
|
-
*
|
|
18
|
-
* CACHING ARCHITECTURE:
|
|
19
|
-
* - SDK caches the API response (URL mapping) - permanent cache
|
|
20
|
-
* - Frontend (assetStore) caches the actual JSON content
|
|
21
|
-
* This maintains clean separation: SDK caches API data, frontend caches static assets
|
|
22
|
-
*
|
|
23
|
-
* @param slug - The template slug to fetch
|
|
24
|
-
* @returns Promise resolving to the sprite template data
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* const template = await client.sprites.templates.get('hero-idle')
|
|
29
|
-
* console.log('Template frames:', template.frames?.length || 0)
|
|
30
|
-
* console.log('Template animations:', Object.keys(template.animations || {}))
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
get: (slug: string) => Promise<SpriteTemplateData>;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { PlaycademyClient } from '../../types';
|
|
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
|
-
};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import type { TodayXpResponse, TotalXpResponse, XpHistoryResponse } from '@playcademy/data/types';
|
|
2
|
-
import type { PlaycademyClient } from '../../types';
|
|
3
|
-
/**
|
|
4
|
-
* Combined response type for summary method
|
|
5
|
-
*/
|
|
6
|
-
export type XpSummaryResponse = {
|
|
7
|
-
today: TodayXpResponse;
|
|
8
|
-
total: TotalXpResponse;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Creates the timeback namespace for the PlaycademyClient.
|
|
12
|
-
* Provides methods for retrieving TimeBack XP data.
|
|
13
|
-
*
|
|
14
|
-
* @param client - The PlaycademyClient instance
|
|
15
|
-
* @returns TimeBack namespace with XP query methods
|
|
16
|
-
*/
|
|
17
|
-
export declare function createTimebackNamespace(client: PlaycademyClient): {
|
|
18
|
-
/**
|
|
19
|
-
* XP-related methods
|
|
20
|
-
*/
|
|
21
|
-
xp: {
|
|
22
|
-
/**
|
|
23
|
-
* Get today's XP for the current user.
|
|
24
|
-
*
|
|
25
|
-
* @param options - Optional parameters
|
|
26
|
-
* @param options.date - Specific date to get XP for (ISO string)
|
|
27
|
-
* @param options.timezone - IANA timezone (e.g., 'America/New_York', 'Europe/London')
|
|
28
|
-
* @returns Promise resolving to today's XP data
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* // Get today's XP in default timezone (EST)
|
|
33
|
-
* const todayXp = await client.timeback.xp.today()
|
|
34
|
-
*
|
|
35
|
-
* // Get today's XP in user's timezone
|
|
36
|
-
* const userTz = Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
37
|
-
* const todayXp = await client.timeback.xp.today({ timezone: userTz })
|
|
38
|
-
*
|
|
39
|
-
* // Get XP for specific date in London timezone
|
|
40
|
-
* const londonXp = await client.timeback.xp.today({
|
|
41
|
-
* date: '2025-01-15T14:30:00.000Z',
|
|
42
|
-
* timezone: 'Europe/London'
|
|
43
|
-
* })
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
today: (options?: {
|
|
47
|
-
date?: string;
|
|
48
|
-
timezone?: string;
|
|
49
|
-
}) => Promise<TodayXpResponse>;
|
|
50
|
-
/**
|
|
51
|
-
* Get total accumulated XP for the current user.
|
|
52
|
-
*
|
|
53
|
-
* @returns Promise resolving to total XP data
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```typescript
|
|
57
|
-
* const totalXp = await client.timeback.xp.total()
|
|
58
|
-
* console.log('Total XP earned:', totalXp.totalXp)
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
total: () => Promise<TotalXpResponse>;
|
|
62
|
-
/**
|
|
63
|
-
* Get XP history with optional date filtering.
|
|
64
|
-
*
|
|
65
|
-
* @param options - Optional filtering parameters
|
|
66
|
-
* @param options.startDate - Start date for filtering (YYYY-MM-DD format)
|
|
67
|
-
* @param options.endDate - End date for filtering (YYYY-MM-DD format)
|
|
68
|
-
* @returns Promise resolving to XP history data
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* // Get all XP history
|
|
73
|
-
* const history = await client.timeback.xp.history()
|
|
74
|
-
*
|
|
75
|
-
* // Get XP for January 2025
|
|
76
|
-
* const januaryXp = await client.timeback.xp.history({
|
|
77
|
-
* startDate: '2025-01-01',
|
|
78
|
-
* endDate: '2025-01-31'
|
|
79
|
-
* })
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
history: (options?: {
|
|
83
|
-
startDate?: string;
|
|
84
|
-
endDate?: string;
|
|
85
|
-
}) => Promise<XpHistoryResponse>;
|
|
86
|
-
/**
|
|
87
|
-
* Get both today's XP and total XP in a single call.
|
|
88
|
-
* More efficient than calling today() and total() separately.
|
|
89
|
-
*
|
|
90
|
-
* @param options - Optional parameters for today's XP
|
|
91
|
-
* @param options.date - Specific date to get today's XP for (ISO string)
|
|
92
|
-
* @param options.timezone - IANA timezone (e.g., 'America/New_York', 'Europe/London')
|
|
93
|
-
* @returns Promise resolving to combined XP data
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```typescript
|
|
97
|
-
* // Get both today's and total XP in default timezone
|
|
98
|
-
* const xpData = await client.timeback.xp.summary()
|
|
99
|
-
* console.log('Today:', xpData.today.xp)
|
|
100
|
-
* console.log('Total:', xpData.total.totalXp)
|
|
101
|
-
*
|
|
102
|
-
* // Get summary with custom timezone
|
|
103
|
-
* const londonXp = await client.timeback.xp.summary({ timezone: 'Europe/London' })
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
summary: (options?: {
|
|
107
|
-
date?: string;
|
|
108
|
-
timezone?: string;
|
|
109
|
-
}) => Promise<XpSummaryResponse>;
|
|
110
|
-
};
|
|
111
|
-
};
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import type { AuthenticatedUser, 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 with authentication context.
|
|
22
|
-
*
|
|
23
|
-
* @returns Promise resolving to user profile data including auth provider info
|
|
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
|
-
* console.log('Has Timeback Account:', user.hasTimebackAccount)
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
me: () => Promise<AuthenticatedUser>;
|
|
34
|
-
/**
|
|
35
|
-
* Inventory management methods for the current user.
|
|
36
|
-
*/
|
|
37
|
-
inventory: {
|
|
38
|
-
/**
|
|
39
|
-
* Retrieves the user's complete inventory.
|
|
40
|
-
*
|
|
41
|
-
* @returns Promise resolving to array of inventory items with item details
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```typescript
|
|
45
|
-
* const inventory = await client.users.inventory.get()
|
|
46
|
-
* inventory.forEach(item => {
|
|
47
|
-
* console.log(`${item.item.name}: ${item.quantity}`)
|
|
48
|
-
* })
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
get: () => Promise<InventoryItemWithItem[]>;
|
|
52
|
-
/**
|
|
53
|
-
* Adds items to the user's inventory.
|
|
54
|
-
* Accepts either an item UUID or slug.
|
|
55
|
-
* Emits an 'inventoryChange' event when successful.
|
|
56
|
-
*
|
|
57
|
-
* @param identifier - The item UUID or slug
|
|
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
|
-
* // Using slug
|
|
64
|
-
* const result = await client.users.inventory.add('gold-coin', 100)
|
|
65
|
-
*
|
|
66
|
-
* // Using UUID
|
|
67
|
-
* const result = await client.users.inventory.add('550e8400-e29b-41d4-a716-446655440000', 100)
|
|
68
|
-
*
|
|
69
|
-
* console.log('New total:', result.newTotal)
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
add: (identifier: string, qty: number) => Promise<InventoryMutationResponse>;
|
|
73
|
-
/**
|
|
74
|
-
* Removes items from the user's inventory.
|
|
75
|
-
* Accepts either an item UUID or slug.
|
|
76
|
-
* Emits an 'inventoryChange' event when successful.
|
|
77
|
-
*
|
|
78
|
-
* @param identifier - The item UUID or slug
|
|
79
|
-
* @param qty - The quantity to remove (must be positive)
|
|
80
|
-
* @returns Promise resolving to mutation response with new total
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```typescript
|
|
84
|
-
* // Using slug
|
|
85
|
-
* const result = await client.users.inventory.remove('HEALTH_POTION', 1)
|
|
86
|
-
*
|
|
87
|
-
* // Using UUID
|
|
88
|
-
* const result = await client.users.inventory.remove('uuid-456-789', 1)
|
|
89
|
-
*
|
|
90
|
-
* console.log('Remaining:', result.newTotal)
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
remove: (identifier: string, qty: number) => Promise<InventoryMutationResponse>;
|
|
94
|
-
/**
|
|
95
|
-
* Gets the current quantity of an item.
|
|
96
|
-
* Accepts either an item UUID or slug.
|
|
97
|
-
*
|
|
98
|
-
* @param identifier - The item UUID or slug
|
|
99
|
-
* @returns Promise resolving to the current quantity (0 if not owned)
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```typescript
|
|
103
|
-
* const qty = await client.users.inventory.quantity('health-potion')
|
|
104
|
-
* const qty2 = await client.users.inventory.quantity('uuid-123-456')
|
|
105
|
-
* console.log('Health potions:', qty)
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
quantity: (identifier: string) => Promise<number>;
|
|
109
|
-
/**
|
|
110
|
-
* Checks if the user has at least the specified quantity of an item.
|
|
111
|
-
* Accepts either an item UUID or slug.
|
|
112
|
-
*
|
|
113
|
-
* @param identifier - The item UUID or slug
|
|
114
|
-
* @param minQuantity - Minimum quantity required (defaults to 1)
|
|
115
|
-
* @returns Promise resolving to true if user has enough of the item
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```typescript
|
|
119
|
-
* const hasKey = await client.users.inventory.has('gold-coin')
|
|
120
|
-
* const hasEnoughGold = await client.users.inventory.has('gold-coin', 100)
|
|
121
|
-
* const hasPotion = await client.users.inventory.has('uuid-123-456', 5)
|
|
122
|
-
*
|
|
123
|
-
* if (hasKey && hasEnoughGold) {
|
|
124
|
-
* console.log('Can enter premium dungeon!')
|
|
125
|
-
* }
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
has: (identifier: string, minQuantity?: number) => Promise<boolean>;
|
|
129
|
-
};
|
|
130
|
-
/**
|
|
131
|
-
* User scores management methods.
|
|
132
|
-
*/
|
|
133
|
-
scores: {
|
|
134
|
-
/**
|
|
135
|
-
* Gets scores for a user across all games.
|
|
136
|
-
*
|
|
137
|
-
* @param userIdOrOptions - User ID or options object. If omitted, gets scores for the current user.
|
|
138
|
-
* @param options - Optional filtering options
|
|
139
|
-
* @param options.limit - Maximum number of scores to return
|
|
140
|
-
* @param options.gameId - Filter scores by specific game
|
|
141
|
-
* @returns Promise resolving to array of user scores
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* ```typescript
|
|
145
|
-
* // Get all scores for current user
|
|
146
|
-
* const myScores = await client.users.scores.get()
|
|
147
|
-
*
|
|
148
|
-
* // Get scores for current user with options
|
|
149
|
-
* const myGameScores = await client.users.scores.get({
|
|
150
|
-
* gameId: 'game-456',
|
|
151
|
-
* limit: 20
|
|
152
|
-
* })
|
|
153
|
-
*
|
|
154
|
-
* // Get scores for a specific user
|
|
155
|
-
* const userScores = await client.users.scores.get('user-123')
|
|
156
|
-
*
|
|
157
|
-
* // Get scores for a specific user with options
|
|
158
|
-
* const userGameScores = await client.users.scores.get('user-123', {
|
|
159
|
-
* gameId: 'game-789',
|
|
160
|
-
* limit: 10
|
|
161
|
-
* })
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
get: (userIdOrOptions?: string | {
|
|
165
|
-
limit?: number;
|
|
166
|
-
gameId?: string;
|
|
167
|
-
}, options?: {
|
|
168
|
-
limit?: number;
|
|
169
|
-
gameId?: string;
|
|
170
|
-
}) => Promise<UserScore[]>;
|
|
171
|
-
};
|
|
172
|
-
};
|
package/dist/core/request.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { ManifestV1 } from '@playcademy/data/types';
|
|
2
|
-
/** Permitted HTTP verbs */
|
|
3
|
-
export type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
4
|
-
export interface RequestOptions {
|
|
5
|
-
path: string;
|
|
6
|
-
baseUrl: string;
|
|
7
|
-
token?: string | null;
|
|
8
|
-
method?: Method;
|
|
9
|
-
body?: unknown;
|
|
10
|
-
extraHeaders?: Record<string, string>;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Thin wrapper around `fetch` that:
|
|
14
|
-
* • attaches Bearer token if provided
|
|
15
|
-
* • stringifies JSON bodies and sets Content‑Type
|
|
16
|
-
* • passes FormData untouched so the browser adds multipart boundary
|
|
17
|
-
* • normalises non‑2xx responses into ApiError
|
|
18
|
-
* • auto‑parses JSON responses, falls back to text/void
|
|
19
|
-
*/
|
|
20
|
-
export declare function request<T = unknown>({ path, baseUrl, token, method, body, extraHeaders, }: RequestOptions): Promise<T>;
|
|
21
|
-
/**
|
|
22
|
-
* Fetches, parses, and validates the playcademy.manifest.json file from a given base URL.
|
|
23
|
-
*/
|
|
24
|
-
export declare function fetchManifest(assetBundleBase: string): Promise<ManifestV1>;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { parseOAuthState } from '../auth/oauth';
|
|
2
|
-
/**
|
|
3
|
-
* Static identity-related utilities for the Playcademy SDK.
|
|
4
|
-
* These methods can be used without instantiating a PlaycademyClient.
|
|
5
|
-
*/
|
|
6
|
-
export declare const identity: {
|
|
7
|
-
/**
|
|
8
|
-
* Parses an OAuth state parameter to extract CSRF token and custom data.
|
|
9
|
-
* Use this in your server callback to retrieve the data encoded in the state.
|
|
10
|
-
*
|
|
11
|
-
* @param state - The OAuth state parameter from the callback
|
|
12
|
-
* @returns Object containing the CSRF token and optional custom data
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* // In your server callback endpoint
|
|
17
|
-
* import { PlaycademyClient } from '@playcademy/sdk'
|
|
18
|
-
*
|
|
19
|
-
* app.get('/api/auth/callback', async (req, res) => {
|
|
20
|
-
* const { csrfToken, data } = PlaycademyClient.identity.parseOAuthState(req.query.state)
|
|
21
|
-
*
|
|
22
|
-
* // Validate CSRF token
|
|
23
|
-
* if (!isValidCsrf(csrfToken)) {
|
|
24
|
-
* return res.status(403).send('Invalid state')
|
|
25
|
-
* }
|
|
26
|
-
*
|
|
27
|
-
* // Access Playcademy user ID if available
|
|
28
|
-
* const playcademyUserId = data?.playcademy_user_id
|
|
29
|
-
* const gameId = data?.game_id
|
|
30
|
-
*
|
|
31
|
-
* // Exchange code for tokens...
|
|
32
|
-
* // Link accounts...
|
|
33
|
-
* })
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
parseOAuthState: typeof parseOAuthState;
|
|
37
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
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>;
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
* @deprecated Use client.auth.login() instead for better error handling and automatic token management
|
|
9
|
-
*
|
|
10
|
-
* @param baseUrl - The base URL of the Playcademy API
|
|
11
|
-
* @param email - User's email address
|
|
12
|
-
* @param password - User's password
|
|
13
|
-
* @returns Promise resolving to authentication response with token
|
|
14
|
-
* @throws PlaycademyError if authentication fails or network error occurs
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* // Preferred approach:
|
|
19
|
-
* const client = new PlaycademyClient({ baseUrl: '/api' })
|
|
20
|
-
* const result = await client.auth.login({
|
|
21
|
-
* email: 'user@example.com',
|
|
22
|
-
* password: 'password'
|
|
23
|
-
* })
|
|
24
|
-
*
|
|
25
|
-
* // Legacy approach (still works):
|
|
26
|
-
* try {
|
|
27
|
-
* const response = await PlaycademyClient.login('/api', 'user@example.com', 'password')
|
|
28
|
-
* const client = new PlaycademyClient({ token: response.token })
|
|
29
|
-
* } catch (error) {
|
|
30
|
-
* console.error('Login failed:', error.message)
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export declare function login(baseUrl: string, email: string, password: string): Promise<LoginResponse>;
|