@playcademy/sdk 0.0.1-beta.30 → 0.0.1-beta.31
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.js +25 -104
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -10,86 +10,6 @@ var __export = (target, all) => {
|
|
|
10
10
|
};
|
|
11
11
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
12
12
|
|
|
13
|
-
// ../logger/src/index.ts
|
|
14
|
-
var isBrowser = () => {
|
|
15
|
-
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
16
|
-
}, colors, getLevelColor = (level) => {
|
|
17
|
-
switch (level) {
|
|
18
|
-
case "debug":
|
|
19
|
-
return colors.blue;
|
|
20
|
-
case "info":
|
|
21
|
-
return colors.cyan;
|
|
22
|
-
case "warn":
|
|
23
|
-
return colors.yellow;
|
|
24
|
-
case "error":
|
|
25
|
-
return colors.red;
|
|
26
|
-
default:
|
|
27
|
-
return colors.reset;
|
|
28
|
-
}
|
|
29
|
-
}, logInBrowser = (level, message, context) => {
|
|
30
|
-
const timestamp = new Date().toISOString();
|
|
31
|
-
const levelUpper = level.toUpperCase();
|
|
32
|
-
const consoleMethod = getConsoleMethod(level);
|
|
33
|
-
if (context && Object.keys(context).length > 0) {
|
|
34
|
-
consoleMethod(`[${timestamp}] ${levelUpper}`, message, context);
|
|
35
|
-
} else {
|
|
36
|
-
consoleMethod(`[${timestamp}] ${levelUpper}`, message);
|
|
37
|
-
}
|
|
38
|
-
}, logOnServer = (level, message, context) => {
|
|
39
|
-
const consoleMethod = getConsoleMethod(level);
|
|
40
|
-
if (true) {
|
|
41
|
-
const timestamp = new Date().toISOString();
|
|
42
|
-
const levelColor = getLevelColor(level);
|
|
43
|
-
const levelUpper = level.toUpperCase().padEnd(5);
|
|
44
|
-
const coloredPrefix = `${colors.dim}[${timestamp}]${colors.reset} ${levelColor}${levelUpper}${colors.reset}`;
|
|
45
|
-
if (context && Object.keys(context).length > 0) {
|
|
46
|
-
consoleMethod(`${coloredPrefix} ${message}`, context);
|
|
47
|
-
} else {
|
|
48
|
-
consoleMethod(`${coloredPrefix} ${message}`);
|
|
49
|
-
}
|
|
50
|
-
} else {}
|
|
51
|
-
}, getConsoleMethod = (level) => {
|
|
52
|
-
switch (level) {
|
|
53
|
-
case "debug":
|
|
54
|
-
return console.debug;
|
|
55
|
-
case "info":
|
|
56
|
-
return console.info;
|
|
57
|
-
case "warn":
|
|
58
|
-
return console.warn;
|
|
59
|
-
case "error":
|
|
60
|
-
return console.error;
|
|
61
|
-
default:
|
|
62
|
-
return console.log;
|
|
63
|
-
}
|
|
64
|
-
}, performLog = (level, message, context) => {
|
|
65
|
-
if (level === "debug" && false) {}
|
|
66
|
-
if (isBrowser()) {
|
|
67
|
-
logInBrowser(level, message, context);
|
|
68
|
-
} else {
|
|
69
|
-
logOnServer(level, message, context);
|
|
70
|
-
}
|
|
71
|
-
}, createLogger = () => {
|
|
72
|
-
return {
|
|
73
|
-
debug: (message, context) => performLog("debug", message, context),
|
|
74
|
-
info: (message, context) => performLog("info", message, context),
|
|
75
|
-
warn: (message, context) => performLog("warn", message, context),
|
|
76
|
-
error: (message, context) => performLog("error", message, context),
|
|
77
|
-
log: performLog
|
|
78
|
-
};
|
|
79
|
-
}, log;
|
|
80
|
-
var init_src = __esm(() => {
|
|
81
|
-
colors = {
|
|
82
|
-
reset: "\x1B[0m",
|
|
83
|
-
dim: "\x1B[2m",
|
|
84
|
-
red: "\x1B[31m",
|
|
85
|
-
yellow: "\x1B[33m",
|
|
86
|
-
blue: "\x1B[34m",
|
|
87
|
-
cyan: "\x1B[36m",
|
|
88
|
-
gray: "\x1B[90m"
|
|
89
|
-
};
|
|
90
|
-
log = createLogger();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
13
|
// src/core/errors.ts
|
|
94
14
|
var PlaycademyError, ApiError;
|
|
95
15
|
var init_errors = __esm(() => {
|
|
@@ -214,6 +134,7 @@ var init_messaging = __esm(() => {
|
|
|
214
134
|
});
|
|
215
135
|
|
|
216
136
|
// src/core/namespaces/runtime.ts
|
|
137
|
+
import { log } from "@playcademy/logger";
|
|
217
138
|
function createRuntimeNamespace(client) {
|
|
218
139
|
const eventListeners = new Map;
|
|
219
140
|
const trackListener = (eventType, handler) => {
|
|
@@ -324,11 +245,11 @@ function createRuntimeNamespace(client) {
|
|
|
324
245
|
};
|
|
325
246
|
}
|
|
326
247
|
var init_runtime = __esm(() => {
|
|
327
|
-
init_src();
|
|
328
248
|
init_messaging();
|
|
329
249
|
});
|
|
330
250
|
|
|
331
251
|
// src/core/request.ts
|
|
252
|
+
import { log as log2 } from "@playcademy/logger";
|
|
332
253
|
async function request({
|
|
333
254
|
path,
|
|
334
255
|
baseUrl,
|
|
@@ -374,7 +295,7 @@ async function fetchManifest(assetBundleBase) {
|
|
|
374
295
|
try {
|
|
375
296
|
const response = await fetch(manifestUrl);
|
|
376
297
|
if (!response.ok) {
|
|
377
|
-
|
|
298
|
+
log2.error(`[fetchManifest] Failed to fetch manifest from ${manifestUrl}. Status: ${response.status}`);
|
|
378
299
|
throw new PlaycademyError(`Failed to fetch manifest: ${response.status} ${response.statusText}`);
|
|
379
300
|
}
|
|
380
301
|
return await response.json();
|
|
@@ -382,14 +303,13 @@ async function fetchManifest(assetBundleBase) {
|
|
|
382
303
|
if (error instanceof PlaycademyError) {
|
|
383
304
|
throw error;
|
|
384
305
|
}
|
|
385
|
-
|
|
306
|
+
log2.error(`[Playcademy SDK] Error fetching or parsing manifest from ${manifestUrl}:`, {
|
|
386
307
|
error
|
|
387
308
|
});
|
|
388
309
|
throw new PlaycademyError("Failed to load or parse game manifest");
|
|
389
310
|
}
|
|
390
311
|
}
|
|
391
312
|
var init_request = __esm(() => {
|
|
392
|
-
init_src();
|
|
393
313
|
init_errors();
|
|
394
314
|
});
|
|
395
315
|
|
|
@@ -1480,6 +1400,8 @@ function createSpritesNamespace(client) {
|
|
|
1480
1400
|
}
|
|
1481
1401
|
|
|
1482
1402
|
// src/core/namespaces/realtime.client.ts
|
|
1403
|
+
import { log as log3 } from "@playcademy/logger";
|
|
1404
|
+
|
|
1483
1405
|
class RealtimeChannelClient {
|
|
1484
1406
|
gameId;
|
|
1485
1407
|
_channelName;
|
|
@@ -1521,13 +1443,13 @@ class RealtimeChannelClient {
|
|
|
1521
1443
|
this.ws.addEventListener("open", onOpen);
|
|
1522
1444
|
this.ws.addEventListener("error", onError);
|
|
1523
1445
|
});
|
|
1524
|
-
|
|
1446
|
+
log3.debug("[RealtimeChannelClient] Connected to channel", {
|
|
1525
1447
|
gameId: this.gameId,
|
|
1526
1448
|
channel: this._channelName
|
|
1527
1449
|
});
|
|
1528
1450
|
return this;
|
|
1529
1451
|
} catch (error) {
|
|
1530
|
-
|
|
1452
|
+
log3.error("[RealtimeChannelClient] Connection failed", {
|
|
1531
1453
|
gameId: this.gameId,
|
|
1532
1454
|
channel: this._channelName,
|
|
1533
1455
|
error
|
|
@@ -1545,14 +1467,14 @@ class RealtimeChannelClient {
|
|
|
1545
1467
|
try {
|
|
1546
1468
|
callback(data);
|
|
1547
1469
|
} catch (error) {
|
|
1548
|
-
|
|
1470
|
+
log3.warn("[RealtimeChannelClient] Message listener error", {
|
|
1549
1471
|
channel: this._channelName,
|
|
1550
1472
|
error
|
|
1551
1473
|
});
|
|
1552
1474
|
}
|
|
1553
1475
|
});
|
|
1554
1476
|
} catch (error) {
|
|
1555
|
-
|
|
1477
|
+
log3.warn("[RealtimeChannelClient] Failed to parse message", {
|
|
1556
1478
|
channel: this._channelName,
|
|
1557
1479
|
message: event.data,
|
|
1558
1480
|
error
|
|
@@ -1560,14 +1482,14 @@ class RealtimeChannelClient {
|
|
|
1560
1482
|
}
|
|
1561
1483
|
};
|
|
1562
1484
|
this.ws.onclose = (event) => {
|
|
1563
|
-
|
|
1485
|
+
log3.debug("[RealtimeChannelClient] Connection closed", {
|
|
1564
1486
|
channel: this._channelName,
|
|
1565
1487
|
code: event.code,
|
|
1566
1488
|
reason: event.reason,
|
|
1567
1489
|
wasClean: event.wasClean
|
|
1568
1490
|
});
|
|
1569
1491
|
if (!this.isClosing && event.code !== CLOSE_CODES.TOKEN_REFRESH) {
|
|
1570
|
-
|
|
1492
|
+
log3.warn("[RealtimeChannelClient] Unexpected disconnection", {
|
|
1571
1493
|
channel: this._channelName,
|
|
1572
1494
|
code: event.code,
|
|
1573
1495
|
reason: event.reason
|
|
@@ -1575,7 +1497,7 @@ class RealtimeChannelClient {
|
|
|
1575
1497
|
}
|
|
1576
1498
|
};
|
|
1577
1499
|
this.ws.onerror = (event) => {
|
|
1578
|
-
|
|
1500
|
+
log3.error("[RealtimeChannelClient] WebSocket error", {
|
|
1579
1501
|
channel: this._channelName,
|
|
1580
1502
|
event
|
|
1581
1503
|
});
|
|
@@ -1583,13 +1505,13 @@ class RealtimeChannelClient {
|
|
|
1583
1505
|
}
|
|
1584
1506
|
setupTokenRefreshListener() {
|
|
1585
1507
|
const tokenRefreshHandler = async ({ token }) => {
|
|
1586
|
-
|
|
1508
|
+
log3.debug("[RealtimeChannelClient] Token refresh received, reconnecting", {
|
|
1587
1509
|
channel: this._channelName
|
|
1588
1510
|
});
|
|
1589
1511
|
try {
|
|
1590
1512
|
await this.reconnectWithNewToken(token);
|
|
1591
1513
|
} catch (error) {
|
|
1592
|
-
|
|
1514
|
+
log3.error("[RealtimeChannelClient] Token refresh reconnection failed", {
|
|
1593
1515
|
channel: this._channelName,
|
|
1594
1516
|
error
|
|
1595
1517
|
});
|
|
@@ -1622,14 +1544,14 @@ class RealtimeChannelClient {
|
|
|
1622
1544
|
const message = JSON.stringify(data);
|
|
1623
1545
|
this.ws.send(message);
|
|
1624
1546
|
} catch (error) {
|
|
1625
|
-
|
|
1547
|
+
log3.error("[RealtimeChannelClient] Failed to send message", {
|
|
1626
1548
|
channel: this._channelName,
|
|
1627
1549
|
error,
|
|
1628
1550
|
data
|
|
1629
1551
|
});
|
|
1630
1552
|
}
|
|
1631
1553
|
} else {
|
|
1632
|
-
|
|
1554
|
+
log3.warn("[RealtimeChannelClient] Cannot send message - connection not open", {
|
|
1633
1555
|
channel: this._channelName,
|
|
1634
1556
|
readyState: this.ws?.readyState
|
|
1635
1557
|
});
|
|
@@ -1650,7 +1572,7 @@ class RealtimeChannelClient {
|
|
|
1650
1572
|
this.ws = undefined;
|
|
1651
1573
|
}
|
|
1652
1574
|
this.listeners.clear();
|
|
1653
|
-
|
|
1575
|
+
log3.debug("[RealtimeChannelClient] Channel closed", {
|
|
1654
1576
|
channel: this._channelName
|
|
1655
1577
|
});
|
|
1656
1578
|
}
|
|
@@ -1663,7 +1585,6 @@ class RealtimeChannelClient {
|
|
|
1663
1585
|
}
|
|
1664
1586
|
var CLOSE_CODES;
|
|
1665
1587
|
var init_realtime_client = __esm(() => {
|
|
1666
|
-
init_src();
|
|
1667
1588
|
init_messaging();
|
|
1668
1589
|
CLOSE_CODES = {
|
|
1669
1590
|
NORMAL_CLOSURE: 1000,
|
|
@@ -1766,6 +1687,7 @@ var init_init = __esm(() => {
|
|
|
1766
1687
|
});
|
|
1767
1688
|
|
|
1768
1689
|
// src/core/static/login.ts
|
|
1690
|
+
import { log as log4 } from "@playcademy/logger";
|
|
1769
1691
|
async function login(baseUrl, email, password) {
|
|
1770
1692
|
let url = baseUrl;
|
|
1771
1693
|
if (baseUrl.startsWith("/") && typeof window !== "undefined") {
|
|
@@ -1785,14 +1707,13 @@ async function login(baseUrl, email, password) {
|
|
|
1785
1707
|
const errorMessage = errorData && errorData.message ? String(errorData.message) : response.statusText;
|
|
1786
1708
|
throw new PlaycademyError(errorMessage);
|
|
1787
1709
|
} catch (error) {
|
|
1788
|
-
|
|
1710
|
+
log4.error("[Playcademy SDK] Failed to parse error response JSON, using status text instead:", { error });
|
|
1789
1711
|
throw new PlaycademyError(response.statusText);
|
|
1790
1712
|
}
|
|
1791
1713
|
}
|
|
1792
1714
|
return response.json();
|
|
1793
1715
|
}
|
|
1794
1716
|
var init_login = __esm(() => {
|
|
1795
|
-
init_src();
|
|
1796
1717
|
init_errors();
|
|
1797
1718
|
});
|
|
1798
1719
|
|
|
@@ -1807,9 +1728,9 @@ var exports_client = {};
|
|
|
1807
1728
|
__export(exports_client, {
|
|
1808
1729
|
PlaycademyClient: () => PlaycademyClient
|
|
1809
1730
|
});
|
|
1731
|
+
import { log as log5 } from "@playcademy/logger";
|
|
1810
1732
|
var PlaycademyClient;
|
|
1811
1733
|
var init_client = __esm(() => {
|
|
1812
|
-
init_src();
|
|
1813
1734
|
init_errors();
|
|
1814
1735
|
init_namespaces();
|
|
1815
1736
|
init_request();
|
|
@@ -1832,7 +1753,7 @@ var init_client = __esm(() => {
|
|
|
1832
1753
|
}
|
|
1833
1754
|
if (this.gameId) {
|
|
1834
1755
|
this._initializeInternalSession().catch((error) => {
|
|
1835
|
-
|
|
1756
|
+
log5.error("[Playcademy SDK] Background initialization of auto-session failed:", {
|
|
1836
1757
|
error
|
|
1837
1758
|
});
|
|
1838
1759
|
});
|
|
@@ -1840,8 +1761,8 @@ var init_client = __esm(() => {
|
|
|
1840
1761
|
}
|
|
1841
1762
|
getBaseUrl() {
|
|
1842
1763
|
const isRelative = this.baseUrl.startsWith("/");
|
|
1843
|
-
const
|
|
1844
|
-
return isRelative &&
|
|
1764
|
+
const isBrowser = typeof window !== "undefined";
|
|
1765
|
+
return isRelative && isBrowser ? `${window.location.origin}${this.baseUrl}` : this.baseUrl;
|
|
1845
1766
|
}
|
|
1846
1767
|
ping() {
|
|
1847
1768
|
return "pong";
|
|
@@ -1887,7 +1808,7 @@ var init_client = __esm(() => {
|
|
|
1887
1808
|
const response = await this.games.startSession(this.gameId);
|
|
1888
1809
|
this.internalClientSessionId = response.sessionId;
|
|
1889
1810
|
} catch (error) {
|
|
1890
|
-
|
|
1811
|
+
log5.error("[Playcademy SDK] Auto-starting session failed for game", {
|
|
1891
1812
|
gameId: this.gameId,
|
|
1892
1813
|
error
|
|
1893
1814
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playcademy/sdk",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.31",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@playcademy/data": "0.0.1",
|
|
35
|
-
"@playcademy/sandbox": "0.1.0-beta.
|
|
35
|
+
"@playcademy/sandbox": "0.1.0-beta.14",
|
|
36
36
|
"@playcademy/test": "0.0.1",
|
|
37
37
|
"@types/bun": "latest",
|
|
38
38
|
"typescript": "^5.7.2",
|