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.
@@ -0,0 +1,425 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Playe SDK - CDN Usage Example</title>
7
+ <style>
8
+ body {
9
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
10
+ max-width: 1200px;
11
+ margin: 0 auto;
12
+ padding: 20px;
13
+ background: #f8fafc;
14
+ }
15
+ .container {
16
+ background: white;
17
+ border-radius: 12px;
18
+ padding: 30px;
19
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
20
+ }
21
+ h1 {
22
+ color: #1e293b;
23
+ margin-bottom: 10px;
24
+ }
25
+ .subtitle {
26
+ color: #64748b;
27
+ margin-bottom: 30px;
28
+ }
29
+ .example-section {
30
+ margin: 30px 0;
31
+ padding: 20px;
32
+ background: #f8fafc;
33
+ border-radius: 8px;
34
+ border-left: 4px solid #3b82f6;
35
+ }
36
+ .code-block {
37
+ background: #1e293b;
38
+ color: #e2e8f0;
39
+ padding: 15px;
40
+ border-radius: 6px;
41
+ font-family: 'Courier New', monospace;
42
+ font-size: 14px;
43
+ overflow-x: auto;
44
+ margin: 10px 0;
45
+ }
46
+ button {
47
+ background: #3b82f6;
48
+ color: white;
49
+ border: none;
50
+ padding: 12px 24px;
51
+ border-radius: 6px;
52
+ cursor: pointer;
53
+ font-weight: 500;
54
+ margin: 5px;
55
+ transition: background-color 0.2s;
56
+ }
57
+ button:hover {
58
+ background: #2563eb;
59
+ }
60
+ button:disabled {
61
+ background: #94a3b8;
62
+ cursor: not-allowed;
63
+ }
64
+ .status {
65
+ padding: 12px;
66
+ margin: 15px 0;
67
+ border-radius: 6px;
68
+ font-weight: 500;
69
+ }
70
+ .status.success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
71
+ .status.error { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
72
+ .status.info { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }
73
+ .log-container {
74
+ background: #0f172a;
75
+ color: #e2e8f0;
76
+ padding: 15px;
77
+ border-radius: 6px;
78
+ height: 300px;
79
+ overflow-y: auto;
80
+ font-family: 'Courier New', monospace;
81
+ font-size: 12px;
82
+ margin: 15px 0;
83
+ }
84
+ .log-entry {
85
+ margin: 2px 0;
86
+ padding: 2px 0;
87
+ }
88
+ .log-entry.info { color: #60a5fa; }
89
+ .log-entry.success { color: #34d399; }
90
+ .log-entry.error { color: #f87171; }
91
+ .log-entry.warning { color: #fbbf24; }
92
+ .grid {
93
+ display: grid;
94
+ grid-template-columns: 1fr 1fr;
95
+ gap: 20px;
96
+ margin: 20px 0;
97
+ }
98
+ @media (max-width: 768px) {
99
+ .grid { grid-template-columns: 1fr; }
100
+ }
101
+ </style>
102
+ </head>
103
+ <body>
104
+ <div class="container">
105
+ <h1>🎮 Playe Developer SDK</h1>
106
+ <p class="subtitle">CDN Usage Example - No build tools required!</p>
107
+
108
+ <div class="example-section">
109
+ <h3>📦 Installation Methods</h3>
110
+
111
+ <h4>Option 1: unpkg CDN</h4>
112
+ <div class="code-block">&lt;script src="https://unpkg.com/playe-developer-sdk@latest/dist/playe-sdk.umd.min.js"&gt;&lt;/script&gt;</div>
113
+
114
+ <h4>Option 2: jsDelivr CDN</h4>
115
+ <div class="code-block">&lt;script src="https://cdn.jsdelivr.net/npm/playe-developer-sdk@latest/dist/playe-sdk.umd.min.js"&gt;&lt;/script&gt;</div>
116
+
117
+ <h4>Option 3: Local file (for development)</h4>
118
+ <div class="code-block">&lt;script src="./dist/playe-sdk.umd.min.js"&gt;&lt;/script&gt;</div>
119
+ </div>
120
+
121
+ <div class="example-section">
122
+ <h3>🚀 Quick Start</h3>
123
+ <div class="code-block">// Initialize the SDK
124
+ const sdk = PlayeSDK.createPlayeSDK({
125
+ apiBaseUrl: 'https://api.playe.com',
126
+ apiKey: 'your-api-key-here',
127
+ enableDebugMode: true
128
+ });
129
+
130
+ // Use the SDK
131
+ sdk.test('Hello from CDN!');</div>
132
+ </div>
133
+
134
+ <div class="status info" id="status">
135
+ Ready to test the SDK
136
+ </div>
137
+
138
+ <div>
139
+ <button onclick="initializeSDK()">Initialize SDK</button>
140
+ <button onclick="testSDK()" disabled id="testBtn">Test SDK</button>
141
+ <button onclick="startDemoGame()" disabled id="demoBtn">Start Demo Game</button>
142
+ <button onclick="clearLog()">Clear Log</button>
143
+ </div>
144
+
145
+ <div class="grid">
146
+ <div>
147
+ <h4>📊 SDK Status</h4>
148
+ <div id="sdkInfo">
149
+ <p><strong>Status:</strong> <span id="sdkStatus">Not initialized</span></p>
150
+ <p><strong>Version:</strong> <span id="sdkVersion">-</span></p>
151
+ <p><strong>Features:</strong> <span id="sdkFeatures">-</span></p>
152
+ </div>
153
+ </div>
154
+
155
+ <div>
156
+ <h4>🎯 Demo Game</h4>
157
+ <div id="gameInfo">
158
+ <p><strong>Session:</strong> <span id="gameSession">None</span></p>
159
+ <p><strong>Score:</strong> <span id="gameScore">0</span></p>
160
+ <p><strong>Status:</strong> <span id="gameStatus">Idle</span></p>
161
+ </div>
162
+ </div>
163
+ </div>
164
+
165
+ <div>
166
+ <h4>📝 Console Log</h4>
167
+ <div class="log-container" id="logContainer"></div>
168
+ </div>
169
+
170
+ <div class="example-section">
171
+ <h3>💡 Integration Examples</h3>
172
+
173
+ <h4>Basic Game Integration</h4>
174
+ <div class="code-block">async function startGame() {
175
+ try {
176
+ // Initialize game session
177
+ const session = await sdk.initializeGameSession({
178
+ campaignId: 'my-campaign',
179
+ gameId: 'my-game',
180
+ playerFingerprint: PlayeSDK.DeviceUtils.generateFingerprint(),
181
+ playerEmail: 'player@example.com'
182
+ });
183
+
184
+ // Start the game
185
+ await sdk.startGameSession(session.sessionId);
186
+ console.log('Game started!', session.sessionId);
187
+
188
+ // Your game logic here...
189
+
190
+ // Complete the game
191
+ const result = await sdk.completeGame(session.sessionId, {
192
+ finalScore: 1500
193
+ });
194
+
195
+ if (result.isWinner) {
196
+ alert(`You won $${result.prizeAmount}!`);
197
+ }
198
+ } catch (error) {
199
+ console.error('Game error:', error);
200
+ }
201
+ }</div>
202
+
203
+ <h4>With Error Handling</h4>
204
+ <div class="code-block">try {
205
+ const session = await sdk.initializeGameSession(params);
206
+ } catch (error) {
207
+ if (error instanceof PlayeSDK.ValidationError) {
208
+ console.error('Invalid parameters:', error.message);
209
+ } else if (error instanceof PlayeSDK.NetworkError) {
210
+ console.error('Network issue:', error.message);
211
+ } else {
212
+ console.error('Unknown error:', error);
213
+ }
214
+ }</div>
215
+ </div>
216
+ </div>
217
+
218
+ <!-- Load the SDK from local dist (fallback to CDN) -->
219
+ <script src="../dist/playe-sdk.umd.min.js"
220
+ onerror="this.onerror=null; this.src='https://unpkg.com/playe-developer-sdk@latest/dist/playe-sdk.umd.min.js';">
221
+ </script>
222
+
223
+ <script>
224
+ let sdk = null;
225
+ let currentSession = null;
226
+
227
+ // Logging function
228
+ function log(level, message) {
229
+ const timestamp = new Date().toLocaleTimeString();
230
+ const logContainer = document.getElementById('logContainer');
231
+ const entry = document.createElement('div');
232
+ entry.className = `log-entry ${level}`;
233
+ entry.innerHTML = `<span style="color: #64748b;">[${timestamp}]</span> ${message}`;
234
+ logContainer.appendChild(entry);
235
+ logContainer.scrollTop = logContainer.scrollHeight;
236
+ }
237
+
238
+ function updateStatus(message, type = 'info') {
239
+ const statusEl = document.getElementById('status');
240
+ statusEl.textContent = message;
241
+ statusEl.className = `status ${type}`;
242
+ }
243
+
244
+ function updateSDKInfo() {
245
+ document.getElementById('sdkStatus').textContent = sdk ? 'Initialized' : 'Not initialized';
246
+ document.getElementById('sdkVersion').textContent = sdk ? PlayeSDK.VERSION || '1.0.0' : '-';
247
+
248
+ if (sdk) {
249
+ const features = [];
250
+ if (PlayeSDK.DeviceUtils) features.push('Device Detection');
251
+ if (PlayeSDK.ValidationUtils) features.push('Validation');
252
+ document.getElementById('sdkFeatures').textContent = features.join(', ');
253
+ }
254
+ }
255
+
256
+ async function initializeSDK() {
257
+ try {
258
+ log('info', 'Initializing Playe Developer SDK...');
259
+
260
+ // Check if SDK is loaded
261
+ if (typeof PlayeSDK === 'undefined') {
262
+ throw new Error('PlayeSDK not loaded. Check your script tag.');
263
+ }
264
+
265
+ // Initialize SDK
266
+ sdk = PlayeSDK.createPlayeSDK({
267
+ apiBaseUrl: 'https://api.playe.com',
268
+ apiKey: 'demo-key-12345',
269
+ enableDebugMode: true
270
+ });
271
+
272
+ log('success', 'SDK initialized successfully!');
273
+ log('info', `SDK Version: ${PlayeSDK.VERSION || '1.0.0'}`);
274
+
275
+ // Test device utilities
276
+ const deviceInfo = PlayeSDK.DeviceUtils.getDeviceInfo();
277
+ log('info', `Device: ${deviceInfo.platform} - ${deviceInfo.screenResolution}`);
278
+
279
+ const fingerprint = PlayeSDK.DeviceUtils.generateFingerprint();
280
+ log('info', `Fingerprint: ${fingerprint}`);
281
+
282
+ updateStatus('SDK initialized successfully!', 'success');
283
+ updateSDKInfo();
284
+
285
+ // Enable buttons
286
+ document.getElementById('testBtn').disabled = false;
287
+ document.getElementById('demoBtn').disabled = false;
288
+ document.querySelector('button[onclick="initializeSDK()"]').disabled = true;
289
+
290
+ } catch (error) {
291
+ log('error', `Failed to initialize SDK: ${error.message}`);
292
+ updateStatus('SDK initialization failed', 'error');
293
+ }
294
+ }
295
+
296
+ function testSDK() {
297
+ if (!sdk) {
298
+ log('error', 'SDK not initialized');
299
+ return;
300
+ }
301
+
302
+ try {
303
+ // Test the SDK
304
+ sdk.test('CDN SDK test successful! 🎉');
305
+
306
+ // Test utilities
307
+ const features = PlayeSDK.DeviceUtils.getFeatureSupport();
308
+ log('info', `Browser features: ${Object.entries(features).filter(([k,v]) => v).map(([k]) => k).join(', ')}`);
309
+
310
+ // Test validation
311
+ try {
312
+ PlayeSDK.ValidationUtils.validateInitializeParams({
313
+ campaignId: 'test',
314
+ gameId: 'test',
315
+ playerFingerprint: 'test'
316
+ });
317
+ log('success', 'Validation test passed');
318
+ } catch (validationError) {
319
+ log('warning', `Validation test: ${validationError.message}`);
320
+ }
321
+
322
+ updateStatus('SDK test completed', 'success');
323
+
324
+ } catch (error) {
325
+ log('error', `SDK test failed: ${error.message}`);
326
+ updateStatus('SDK test failed', 'error');
327
+ }
328
+ }
329
+
330
+ async function startDemoGame() {
331
+ if (!sdk) {
332
+ log('error', 'SDK not initialized');
333
+ return;
334
+ }
335
+
336
+ try {
337
+ updateStatus('Starting demo game...', 'info');
338
+ document.getElementById('gameStatus').textContent = 'Starting...';
339
+
340
+ // Mock game session initialization
341
+ log('info', 'Initializing demo game session...');
342
+
343
+ const fingerprint = PlayeSDK.DeviceUtils.generateFingerprint();
344
+ const deviceInfo = PlayeSDK.DeviceUtils.getDeviceInfo();
345
+
346
+ // Since this is a demo, we'll simulate the API calls
347
+ const mockSession = {
348
+ sessionId: 'demo_' + Math.random().toString(36).substr(2, 9),
349
+ campaignId: 'demo-campaign',
350
+ gameId: 'demo-game',
351
+ status: 'initialized'
352
+ };
353
+
354
+ currentSession = mockSession;
355
+ document.getElementById('gameSession').textContent = mockSession.sessionId;
356
+ document.getElementById('gameStatus').textContent = 'Active';
357
+
358
+ log('success', `Demo game session created: ${mockSession.sessionId}`);
359
+ log('info', 'Simulating game play...');
360
+
361
+ // Simulate game progress
362
+ let score = 0;
363
+ const gameInterval = setInterval(() => {
364
+ score += Math.floor(Math.random() * 100) + 50;
365
+ document.getElementById('gameScore').textContent = score;
366
+
367
+ if (score < 1000) {
368
+ log('info', `Score update: ${score}`);
369
+ } else {
370
+ clearInterval(gameInterval);
371
+ finishDemoGame(score);
372
+ }
373
+ }, 1000);
374
+
375
+ updateStatus('Demo game in progress...', 'info');
376
+
377
+ } catch (error) {
378
+ log('error', `Failed to start demo game: ${error.message}`);
379
+ updateStatus('Demo game failed to start', 'error');
380
+ }
381
+ }
382
+
383
+ function finishDemoGame(finalScore) {
384
+ const isWinner = finalScore > 1500;
385
+
386
+ log('success', `Demo game completed! Final score: ${finalScore}`);
387
+
388
+ if (isWinner) {
389
+ log('success', '🎉 Congratulations! You won the demo game!');
390
+ updateStatus('Demo game won!', 'success');
391
+ } else {
392
+ log('info', 'Good try! Better luck next time.');
393
+ updateStatus('Demo game completed', 'info');
394
+ }
395
+
396
+ document.getElementById('gameStatus').textContent = isWinner ? 'Won!' : 'Completed';
397
+
398
+ // Reset after 5 seconds
399
+ setTimeout(() => {
400
+ document.getElementById('gameSession').textContent = 'None';
401
+ document.getElementById('gameScore').textContent = '0';
402
+ document.getElementById('gameStatus').textContent = 'Idle';
403
+ currentSession = null;
404
+ }, 5000);
405
+ }
406
+
407
+ function clearLog() {
408
+ document.getElementById('logContainer').innerHTML = '';
409
+ }
410
+
411
+ // Initialize on page load
412
+ window.addEventListener('load', () => {
413
+ log('info', '🎮 Playe Developer SDK CDN Example loaded');
414
+ log('info', 'Click "Initialize SDK" to get started');
415
+
416
+ // Check if SDK is available
417
+ if (typeof PlayeSDK !== 'undefined') {
418
+ log('success', 'PlayeSDK loaded from CDN successfully');
419
+ } else {
420
+ log('error', 'PlayeSDK not found. Check your internet connection or script tag.');
421
+ }
422
+ });
423
+ </script>
424
+ </body>
425
+ </html>
package/package.json ADDED
@@ -0,0 +1,90 @@
1
+ {
2
+ "name": "playe-developer-sdk",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "private": false,
6
+ "description": "Enhanced Game Developer SDK for browser-based projects - integrate games with campaigns, leaderboards, and anti-cheat protection",
7
+ "main": "./dist/index.cjs.js",
8
+ "module": "./dist/index.esm.js",
9
+ "browser": "./dist/playe-sdk.umd.js",
10
+ "types": "./dist/index.d.ts",
11
+ "unpkg": "./dist/playe-sdk.umd.min.js",
12
+ "jsdelivr": "./dist/playe-sdk.umd.min.js",
13
+ "scripts": {
14
+ "build": "node scripts/build.js",
15
+ "build:dev": "rollup -c --watch",
16
+ "build:prod": "NODE_ENV=production node scripts/build.js --npm",
17
+ "build:workspace": "node scripts/build.js --workspace",
18
+ "build:npm": "node scripts/build.js --npm",
19
+ "build:legacy": "tsc",
20
+ "dev": "rollup -c --watch",
21
+ "lint": "eslint . --max-warnings 0",
22
+ "type-check": "tsc --noEmit",
23
+ "prepublishOnly": "pnpm run build:npm",
24
+ "prepack": "pnpm run build:npm",
25
+ "test:build": "node scripts/build.js && node -e \"console.log('Testing imports...'); import('./dist/index.esm.js').then(() => console.log('✅ ESM import works')); require('./dist/index.cjs.js'); console.log('✅ CJS require works');\""
26
+ },
27
+ "dependencies": {},
28
+ "devDependencies": {
29
+ "@rollup/plugin-commonjs": "^28.0.6",
30
+ "@rollup/plugin-node-resolve": "^16.0.1",
31
+ "@rollup/plugin-terser": "^0.4.4",
32
+ "@rollup/plugin-typescript": "^12.1.4",
33
+ "@types/node": "^24",
34
+ "rollup": "^4.46.2",
35
+ "rollup-plugin-dts": "^6.2.1",
36
+ "typescript": "^5.9.0-beta"
37
+ },
38
+ "exports": {
39
+ ".": {
40
+ "types": "./dist/index.d.ts",
41
+ "import": "./dist/index.esm.js",
42
+ "require": "./dist/index.cjs.js",
43
+ "browser": "./dist/playe-sdk.umd.js",
44
+ "default": "./dist/index.esm.js"
45
+ },
46
+ "./package.json": "./package.json"
47
+ },
48
+ "files": [
49
+ "dist/**/*",
50
+ "README.md",
51
+ "CHANGELOG.md",
52
+ "examples/**/*"
53
+ ],
54
+ "keywords": [
55
+ "game",
56
+ "sdk",
57
+ "developer",
58
+ "browser",
59
+ "playe",
60
+ "gaming",
61
+ "campaigns",
62
+ "leaderboard",
63
+ "anti-cheat",
64
+ "typescript",
65
+ "javascript",
66
+ "web-games",
67
+ "prize-campaigns",
68
+ "gamification"
69
+ ],
70
+ "homepage": "https://github.com/playe/playe/tree/main/packages/playe-developer-sdk",
71
+ "bugs": {
72
+ "url": "https://github.com/playe/playe/issues"
73
+ },
74
+ "license": "MIT",
75
+ "engines": {
76
+ "node": ">=16.0.0"
77
+ },
78
+ "browserslist": [
79
+ "Chrome >= 60",
80
+ "Firefox >= 55",
81
+ "Safari >= 12",
82
+ "Edge >= 79"
83
+ ],
84
+ "author": "Playe Team",
85
+ "repository": {
86
+ "type": "git",
87
+ "url": "git+https://github.com/playe/playe.git",
88
+ "directory": "packages/playe-developer-sdk"
89
+ }
90
+ }