playe-developer-sdk 1.0.0
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/CHANGELOG.md +68 -0
- package/README.md +341 -0
- package/dist/index.cjs.js +759 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +458 -0
- package/dist/index.esm.js +748 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/playe-sdk.umd.js +765 -0
- package/dist/playe-sdk.umd.js.map +1 -0
- package/dist/playe-sdk.umd.min.js +2 -0
- package/dist/playe-sdk.umd.min.js.map +1 -0
- package/examples/basic-usage.ts +170 -0
- package/examples/browser-example.html +520 -0
- package/examples/cdn-usage.html +425 -0
- package/package.json +90 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the Playe Developer SDK will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2024-08-04
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of the Playe Developer SDK
|
|
12
|
+
- Core game session management functionality
|
|
13
|
+
- Initialize, start, update progress, and complete game sessions
|
|
14
|
+
- Automatic heartbeat mechanism for session validation
|
|
15
|
+
- Session abandonment with cleanup
|
|
16
|
+
- Campaign integration features
|
|
17
|
+
- Campaign status retrieval
|
|
18
|
+
- Live leaderboards with player rankings
|
|
19
|
+
- Player attempt history and statistics
|
|
20
|
+
- Anti-cheat and validation systems
|
|
21
|
+
- Game session validation
|
|
22
|
+
- Score validation with basic cheat detection
|
|
23
|
+
- Device fingerprinting and information collection
|
|
24
|
+
- Developer tools and utilities
|
|
25
|
+
- Test game session creation for development
|
|
26
|
+
- Debug mode with comprehensive logging
|
|
27
|
+
- Device feature detection and capability checking
|
|
28
|
+
- Browser optimization
|
|
29
|
+
- Lightweight bundle size
|
|
30
|
+
- Native fetch API usage
|
|
31
|
+
- Custom event emission for tracking
|
|
32
|
+
- Automatic retry mechanism with exponential backoff
|
|
33
|
+
- Comprehensive TypeScript support
|
|
34
|
+
- Full type definitions for all interfaces
|
|
35
|
+
- Strongly typed API responses
|
|
36
|
+
- Generic error handling with specific error types
|
|
37
|
+
- Examples and documentation
|
|
38
|
+
- Basic usage examples in TypeScript
|
|
39
|
+
- Interactive browser example with HTML/JavaScript
|
|
40
|
+
- Comprehensive README with API documentation
|
|
41
|
+
- Error handling patterns and best practices
|
|
42
|
+
|
|
43
|
+
### Features
|
|
44
|
+
- **Game Session Management**: Complete lifecycle management of game sessions from initialization to completion
|
|
45
|
+
- **Campaign Integration**: Support for all campaign styles (SingleWinner, FixedPool, Leaderboard, RewardForAll)
|
|
46
|
+
- **Real-time Updates**: Live progress tracking and leaderboard updates
|
|
47
|
+
- **Anti-cheat Protection**: Built-in validation mechanisms and heartbeat monitoring
|
|
48
|
+
- **Device Detection**: Automatic device information gathering and fingerprinting
|
|
49
|
+
- **Error Handling**: Comprehensive error types with context and debugging information
|
|
50
|
+
- **Browser Events**: Custom DOM events for game lifecycle tracking
|
|
51
|
+
- **Offline Support**: Configurable offline mode for development and testing
|
|
52
|
+
|
|
53
|
+
### Technical Details
|
|
54
|
+
- Built with TypeScript 5.9 for modern JavaScript features and type safety
|
|
55
|
+
- Uses native Fetch API for HTTP requests with automatic retries
|
|
56
|
+
- Implements exponential backoff for failed requests
|
|
57
|
+
- Supports both ESM and CommonJS module formats
|
|
58
|
+
- Includes source maps and declaration files for debugging
|
|
59
|
+
- Zero external dependencies for core functionality
|
|
60
|
+
- Browser compatibility: Chrome 60+, Firefox 55+, Safari 12+, Edge 79+
|
|
61
|
+
|
|
62
|
+
### Developer Experience
|
|
63
|
+
- Comprehensive TypeScript definitions
|
|
64
|
+
- Debug mode with detailed logging
|
|
65
|
+
- Interactive browser example for testing
|
|
66
|
+
- Clear error messages with context
|
|
67
|
+
- Automatic cleanup and resource management
|
|
68
|
+
- Configurable timeout and retry settings
|
package/README.md
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
# Playe Developer SDK
|
|
2
|
+
|
|
3
|
+
A comprehensive browser-based SDK for integrating games with the Playe platform. This SDK provides easy-to-use APIs for game session management, campaign integration, leaderboards, and anti-cheat validation.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎮 **Game Session Management** - Initialize, start, update, and complete game sessions
|
|
8
|
+
- 🏆 **Campaign Integration** - Access campaign information, leaderboards, and player attempts
|
|
9
|
+
- 🛡️ **Anti-Cheat Protection** - Built-in validation and heartbeat mechanisms
|
|
10
|
+
- 📱 **Device Detection** - Automatic device information and fingerprinting
|
|
11
|
+
- 🔧 **Developer Tools** - Test game sessions and debugging utilities
|
|
12
|
+
- 📊 **Real-time Updates** - Progress tracking and live leaderboards
|
|
13
|
+
- ⚡ **Browser Optimized** - Lightweight and fast for web games
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
### NPM (Recommended)
|
|
18
|
+
```bash
|
|
19
|
+
npm install playe-developer-sdk
|
|
20
|
+
# or
|
|
21
|
+
yarn add playe-developer-sdk
|
|
22
|
+
# or
|
|
23
|
+
pnpm add playe-developer-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### CDN (No build tools required)
|
|
27
|
+
```html
|
|
28
|
+
<!-- For production -->
|
|
29
|
+
<script src="https://unpkg.com/playe-developer-sdk@latest/dist/playe-sdk.umd.min.js"></script>
|
|
30
|
+
|
|
31
|
+
<!-- Alternative CDN -->
|
|
32
|
+
<script src="https://cdn.jsdelivr.net/npm/playe-developer-sdk@latest/dist/playe-sdk.umd.min.js"></script>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Workspace (Internal development)
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@workspace/playe-developer-sdk": "workspace:*"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Quick Start
|
|
45
|
+
|
|
46
|
+
### NPM Usage
|
|
47
|
+
```typescript
|
|
48
|
+
import { createPlayeSDK } from 'playe-developer-sdk';
|
|
49
|
+
|
|
50
|
+
// Initialize the SDK
|
|
51
|
+
const sdk = createPlayeSDK({
|
|
52
|
+
apiBaseUrl: 'https://api.playe.com',
|
|
53
|
+
apiKey: 'your-api-key',
|
|
54
|
+
enableDebugMode: true, // Enable for development
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Initialize a game session
|
|
58
|
+
const session = await sdk.initializeGameSession({
|
|
59
|
+
campaignId: 'campaign-123',
|
|
60
|
+
gameId: 'game-456',
|
|
61
|
+
playerFingerprint: 'unique-player-fingerprint',
|
|
62
|
+
playerEmail: 'player@example.com',
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Start the game
|
|
66
|
+
await sdk.startGameSession(session.sessionId);
|
|
67
|
+
|
|
68
|
+
// Update progress during gameplay
|
|
69
|
+
await sdk.updateGameProgress(session.sessionId, {
|
|
70
|
+
currentScore: 1500,
|
|
71
|
+
elapsedTime: 120, // seconds
|
|
72
|
+
gameState: { level: 3, lives: 2 },
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Complete the game
|
|
76
|
+
const result = await sdk.completeGame(session.sessionId, {
|
|
77
|
+
finalScore: 2500,
|
|
78
|
+
gameMetrics: {
|
|
79
|
+
totalPlayTime: 300,
|
|
80
|
+
actionsPerformed: 150,
|
|
81
|
+
powerUpsUsed: 5,
|
|
82
|
+
levelsCompleted: 5,
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
console.log('Game completed!', {
|
|
87
|
+
isWinner: result.isWinner,
|
|
88
|
+
finalRank: result.finalRank,
|
|
89
|
+
prizeAmount: result.prizeAmount,
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### CDN Usage
|
|
94
|
+
```html
|
|
95
|
+
<script src="https://unpkg.com/playe-developer-sdk@latest/dist/playe-sdk.umd.min.js"></script>
|
|
96
|
+
<script>
|
|
97
|
+
// SDK is available as global PlayeSDK
|
|
98
|
+
const sdk = PlayeSDK.createPlayeSDK({
|
|
99
|
+
apiBaseUrl: 'https://api.playe.com',
|
|
100
|
+
apiKey: 'your-api-key',
|
|
101
|
+
enableDebugMode: true,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// All utilities are available
|
|
105
|
+
const fingerprint = PlayeSDK.DeviceUtils.generateFingerprint();
|
|
106
|
+
|
|
107
|
+
// Same API as NPM version
|
|
108
|
+
const session = await sdk.initializeGameSession({
|
|
109
|
+
campaignId: 'campaign-123',
|
|
110
|
+
gameId: 'game-456',
|
|
111
|
+
playerFingerprint: fingerprint,
|
|
112
|
+
});
|
|
113
|
+
</script>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## API Reference
|
|
117
|
+
|
|
118
|
+
### SDK Configuration
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
interface SDKConfig {
|
|
122
|
+
apiBaseUrl: string; // Required: API base URL
|
|
123
|
+
apiKey?: string; // Optional: API key for authentication
|
|
124
|
+
enableDebugMode?: boolean; // Optional: Enable debug logging
|
|
125
|
+
retryAttempts?: number; // Optional: Number of retry attempts (default: 3)
|
|
126
|
+
timeoutMs?: number; // Optional: Request timeout in ms (default: 30000)
|
|
127
|
+
enableOfflineMode?: boolean; // Optional: Enable offline mode (default: false)
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Core Methods
|
|
132
|
+
|
|
133
|
+
#### Game Session Management
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
// Initialize a new game session
|
|
137
|
+
await sdk.initializeGameSession({
|
|
138
|
+
campaignId: string;
|
|
139
|
+
gameId: string;
|
|
140
|
+
playerFingerprint: string;
|
|
141
|
+
playerEmail?: string;
|
|
142
|
+
deviceInfo?: DeviceInfo;
|
|
143
|
+
receiptImage?: string; // Base64 encoded
|
|
144
|
+
geolocationData?: GeolocationData;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Start the game session
|
|
148
|
+
await sdk.startGameSession(sessionId: string, config?: Record<string, any>);
|
|
149
|
+
|
|
150
|
+
// Update game progress
|
|
151
|
+
await sdk.updateGameProgress(sessionId: string, {
|
|
152
|
+
currentScore: number;
|
|
153
|
+
gameState?: Record<string, any>;
|
|
154
|
+
elapsedTime: number;
|
|
155
|
+
achievements?: Achievement[];
|
|
156
|
+
clientTimestamp?: string;
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Complete the game
|
|
160
|
+
await sdk.completeGame(sessionId: string, {
|
|
161
|
+
finalScore: number;
|
|
162
|
+
gameMetrics?: GameMetrics;
|
|
163
|
+
finalGameState?: Record<string, any>;
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Abandon the game
|
|
167
|
+
await sdk.abandonGame(sessionId: string, reason?: string, lastKnownScore?: number);
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### Campaign Information
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
// Get campaign status
|
|
174
|
+
await sdk.getCampaignStatus(campaignId: string, playerId?: string);
|
|
175
|
+
|
|
176
|
+
// Get leaderboard
|
|
177
|
+
await sdk.getLeaderboard(campaignId: string, limit?: number, playerId?: string);
|
|
178
|
+
|
|
179
|
+
// Get player attempts
|
|
180
|
+
await sdk.getPlayerAttempts(campaignId: string, playerId: string);
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
#### Validation & Anti-Cheat
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
// Validate game session
|
|
187
|
+
await sdk.validateGameSession(sessionId: string, validationData?: Record<string, any>);
|
|
188
|
+
|
|
189
|
+
// Send heartbeat (usually handled automatically)
|
|
190
|
+
await sdk.sendHeartbeat(sessionId: string, currentScore?: number);
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Utility Methods
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
// Test SDK functionality
|
|
197
|
+
sdk.test('Custom test message');
|
|
198
|
+
|
|
199
|
+
// Check if running in demo mode
|
|
200
|
+
const isDemoMode = sdk.isDemo();
|
|
201
|
+
|
|
202
|
+
// Game lifecycle events
|
|
203
|
+
sdk.gameLoadingStart();
|
|
204
|
+
sdk.gameLoadingFinished();
|
|
205
|
+
sdk.gamePlayStop();
|
|
206
|
+
|
|
207
|
+
// Clean up resources
|
|
208
|
+
sdk.destroy();
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Device Utilities
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
import { DeviceUtils } from '@workspace/playe-developer-sdk';
|
|
215
|
+
|
|
216
|
+
// Get device information
|
|
217
|
+
const deviceInfo = DeviceUtils.getDeviceInfo();
|
|
218
|
+
|
|
219
|
+
// Get geolocation
|
|
220
|
+
const location = await DeviceUtils.getGeolocationData();
|
|
221
|
+
|
|
222
|
+
// Generate fingerprint
|
|
223
|
+
const fingerprint = DeviceUtils.generateFingerprint();
|
|
224
|
+
|
|
225
|
+
// Check browser support
|
|
226
|
+
const isSupported = DeviceUtils.isBrowser();
|
|
227
|
+
const features = DeviceUtils.getFeatureSupport();
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Error Handling
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
import {
|
|
234
|
+
PlayeSDKError,
|
|
235
|
+
ValidationError,
|
|
236
|
+
NetworkError,
|
|
237
|
+
AuthenticationError,
|
|
238
|
+
GameSessionError
|
|
239
|
+
} from '@workspace/playe-developer-sdk';
|
|
240
|
+
|
|
241
|
+
try {
|
|
242
|
+
await sdk.initializeGameSession(params);
|
|
243
|
+
} catch (error) {
|
|
244
|
+
if (error instanceof ValidationError) {
|
|
245
|
+
console.error('Validation failed:', error.message);
|
|
246
|
+
} else if (error instanceof NetworkError) {
|
|
247
|
+
console.error('Network error:', error.message);
|
|
248
|
+
} else if (error instanceof AuthenticationError) {
|
|
249
|
+
console.error('Authentication failed:', error.message);
|
|
250
|
+
} else if (error instanceof PlayeSDKError) {
|
|
251
|
+
console.error('SDK error:', error.toJSON());
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Campaign Styles
|
|
257
|
+
|
|
258
|
+
The SDK supports different campaign styles:
|
|
259
|
+
|
|
260
|
+
- **SingleWinner**: One winner takes all
|
|
261
|
+
- **FixedPool**: Fixed number of winners
|
|
262
|
+
- **Leaderboard**: Winners based on ranking
|
|
263
|
+
- **RewardForAll**: Everyone gets rewards
|
|
264
|
+
|
|
265
|
+
## Events
|
|
266
|
+
|
|
267
|
+
The SDK emits custom browser events for tracking:
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
// Listen for SDK events
|
|
271
|
+
window.addEventListener('playe:game-loading-start', () => {
|
|
272
|
+
console.log('Game loading started');
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
window.addEventListener('playe:game-loading-finished', () => {
|
|
276
|
+
console.log('Game loading finished');
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
window.addEventListener('playe:game-play-stop', () => {
|
|
280
|
+
console.log('Game play stopped');
|
|
281
|
+
});
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Development
|
|
285
|
+
|
|
286
|
+
### Testing
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
// Create a test game session for development
|
|
290
|
+
const testSession = await sdk.createTestGameSession({
|
|
291
|
+
mockCampaign: true,
|
|
292
|
+
mockPlayers: 10,
|
|
293
|
+
testScenario: 'leaderboard',
|
|
294
|
+
});
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Debug Mode
|
|
298
|
+
|
|
299
|
+
Enable debug mode to see detailed logging:
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
const sdk = createPlayeSDK({
|
|
303
|
+
apiBaseUrl: 'https://api.playe.com',
|
|
304
|
+
enableDebugMode: true, // This will log all API calls and responses
|
|
305
|
+
});
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
## Browser Compatibility
|
|
309
|
+
|
|
310
|
+
- Chrome 60+
|
|
311
|
+
- Firefox 55+
|
|
312
|
+
- Safari 12+
|
|
313
|
+
- Edge 79+
|
|
314
|
+
|
|
315
|
+
## Distribution
|
|
316
|
+
|
|
317
|
+
The SDK is available in multiple formats:
|
|
318
|
+
|
|
319
|
+
- **NPM Package**: `npm install playe-developer-sdk`
|
|
320
|
+
- **CDN (UMD)**: `https://unpkg.com/playe-developer-sdk@latest/dist/playe-sdk.umd.min.js`
|
|
321
|
+
- **Workspace**: `@workspace/playe-developer-sdk` (internal development)
|
|
322
|
+
|
|
323
|
+
### Bundle Sizes
|
|
324
|
+
- ESM: 27.3KB (8KB gzipped)
|
|
325
|
+
- CommonJS: 27.6KB (8KB gzipped)
|
|
326
|
+
- UMD: 30.8KB (9KB gzipped)
|
|
327
|
+
- UMD Minified: 13.7KB (5KB gzipped)
|
|
328
|
+
|
|
329
|
+
For detailed distribution information, see [DISTRIBUTION.md](./DISTRIBUTION.md).
|
|
330
|
+
|
|
331
|
+
## TypeScript Support
|
|
332
|
+
|
|
333
|
+
This SDK is written in TypeScript and includes full type definitions. No additional `@types` packages are needed.
|
|
334
|
+
|
|
335
|
+
## License
|
|
336
|
+
|
|
337
|
+
MIT License - see LICENSE file for details.
|
|
338
|
+
|
|
339
|
+
## Support
|
|
340
|
+
|
|
341
|
+
For support, please contact the Playe development team or create an issue in the repository.
|