@partylayer/sdk 0.15.0 → 0.16.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/dist/index.d.mts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +164 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +164 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.d.mts
CHANGED
|
@@ -178,6 +178,13 @@ interface PartyLayerConfig {
|
|
|
178
178
|
telemetry?: TelemetryAdapter | TelemetryConfig;
|
|
179
179
|
/** Logger adapter (optional) */
|
|
180
180
|
logger?: LoggerAdapter;
|
|
181
|
+
/**
|
|
182
|
+
* Log verbosity. Filtering happens centrally in the client before the adapter is
|
|
183
|
+
* called, so adapters never filter themselves. `silent` suppresses everything.
|
|
184
|
+
* Defaults to `info` when a logger is supplied; with no logger the client is
|
|
185
|
+
* silent regardless.
|
|
186
|
+
*/
|
|
187
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
181
188
|
/** Application metadata */
|
|
182
189
|
app: {
|
|
183
190
|
/** Application name */
|
|
@@ -349,6 +356,8 @@ declare class PartyLayerClient {
|
|
|
349
356
|
private activeSessionNeedsProbe;
|
|
350
357
|
readonly registryClient: RegistryClient;
|
|
351
358
|
private logger;
|
|
359
|
+
/** Configured log verbosity; filtering happens centrally in {@link log}. */
|
|
360
|
+
private readonly logLevel;
|
|
352
361
|
private crypto;
|
|
353
362
|
private storage;
|
|
354
363
|
private telemetry?;
|
|
@@ -583,6 +592,14 @@ declare class PartyLayerClient {
|
|
|
583
592
|
/**
|
|
584
593
|
* Emit event to handlers
|
|
585
594
|
*/
|
|
595
|
+
/**
|
|
596
|
+
* Central structured log. Filters by the configured level here, before the adapter
|
|
597
|
+
* is called, so adapters never filter themselves; skips entirely when no real
|
|
598
|
+
* logger was configured (the no-op default), so a silent client pays only a check.
|
|
599
|
+
* Every line carries a machine readable payload `{ event, correlationId?, ...fields }`.
|
|
600
|
+
* Privacy: callers pass only non identifying fields, the same rule as telemetry.
|
|
601
|
+
*/
|
|
602
|
+
private log;
|
|
586
603
|
private emit;
|
|
587
604
|
}
|
|
588
605
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -178,6 +178,13 @@ interface PartyLayerConfig {
|
|
|
178
178
|
telemetry?: TelemetryAdapter | TelemetryConfig;
|
|
179
179
|
/** Logger adapter (optional) */
|
|
180
180
|
logger?: LoggerAdapter;
|
|
181
|
+
/**
|
|
182
|
+
* Log verbosity. Filtering happens centrally in the client before the adapter is
|
|
183
|
+
* called, so adapters never filter themselves. `silent` suppresses everything.
|
|
184
|
+
* Defaults to `info` when a logger is supplied; with no logger the client is
|
|
185
|
+
* silent regardless.
|
|
186
|
+
*/
|
|
187
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
181
188
|
/** Application metadata */
|
|
182
189
|
app: {
|
|
183
190
|
/** Application name */
|
|
@@ -349,6 +356,8 @@ declare class PartyLayerClient {
|
|
|
349
356
|
private activeSessionNeedsProbe;
|
|
350
357
|
readonly registryClient: RegistryClient;
|
|
351
358
|
private logger;
|
|
359
|
+
/** Configured log verbosity; filtering happens centrally in {@link log}. */
|
|
360
|
+
private readonly logLevel;
|
|
352
361
|
private crypto;
|
|
353
362
|
private storage;
|
|
354
363
|
private telemetry?;
|
|
@@ -583,6 +592,14 @@ declare class PartyLayerClient {
|
|
|
583
592
|
/**
|
|
584
593
|
* Emit event to handlers
|
|
585
594
|
*/
|
|
595
|
+
/**
|
|
596
|
+
* Central structured log. Filters by the configured level here, before the adapter
|
|
597
|
+
* is called, so adapters never filter themselves; skips entirely when no real
|
|
598
|
+
* logger was configured (the no-op default), so a silent client pays only a check.
|
|
599
|
+
* Every line carries a machine readable payload `{ event, correlationId?, ...fields }`.
|
|
600
|
+
* Privacy: callers pass only non identifying fields, the same rule as telemetry.
|
|
601
|
+
*/
|
|
602
|
+
private log;
|
|
586
603
|
private emit;
|
|
587
604
|
}
|
|
588
605
|
/**
|
package/dist/index.js
CHANGED
|
@@ -385,25 +385,13 @@ var DEFAULT_REGISTRY_URL = "https://registry.partylayer.xyz";
|
|
|
385
385
|
|
|
386
386
|
// src/adapters.ts
|
|
387
387
|
var DefaultLogger = class {
|
|
388
|
-
debug(
|
|
389
|
-
if (typeof console !== "undefined" && console.debug) {
|
|
390
|
-
console.debug(`[PartyLayer] ${message}`, ...args);
|
|
391
|
-
}
|
|
388
|
+
debug(_message, ..._args) {
|
|
392
389
|
}
|
|
393
|
-
info(
|
|
394
|
-
if (typeof console !== "undefined" && console.info) {
|
|
395
|
-
console.info(`[PartyLayer] ${message}`, ...args);
|
|
396
|
-
}
|
|
390
|
+
info(_message, ..._args) {
|
|
397
391
|
}
|
|
398
|
-
warn(
|
|
399
|
-
if (typeof console !== "undefined" && console.warn) {
|
|
400
|
-
console.warn(`[PartyLayer] ${message}`, ...args);
|
|
401
|
-
}
|
|
392
|
+
warn(_message, ..._args) {
|
|
402
393
|
}
|
|
403
|
-
error(
|
|
404
|
-
if (typeof console !== "undefined" && console.error) {
|
|
405
|
-
console.error(`[PartyLayer] ${message}`, error, ...args);
|
|
406
|
-
}
|
|
394
|
+
error(_message, _error, ..._args) {
|
|
407
395
|
}
|
|
408
396
|
};
|
|
409
397
|
var DefaultCrypto = class {
|
|
@@ -731,6 +719,85 @@ function createTelemetryAdapter(config) {
|
|
|
731
719
|
}
|
|
732
720
|
return config;
|
|
733
721
|
}
|
|
722
|
+
|
|
723
|
+
// src/event-telemetry.ts
|
|
724
|
+
function errorProperties(error) {
|
|
725
|
+
const code = error.code;
|
|
726
|
+
return code ? { code } : {};
|
|
727
|
+
}
|
|
728
|
+
function eventTelemetryProperties(event) {
|
|
729
|
+
switch (event.type) {
|
|
730
|
+
case "registry:updated":
|
|
731
|
+
return { channel: event.channel, version: event.version };
|
|
732
|
+
case "registry:status":
|
|
733
|
+
return {
|
|
734
|
+
source: event.status.source,
|
|
735
|
+
channel: event.status.channel,
|
|
736
|
+
verified: event.status.verified,
|
|
737
|
+
stale: event.status.stale,
|
|
738
|
+
sequence: event.status.sequence
|
|
739
|
+
};
|
|
740
|
+
case "session:connected":
|
|
741
|
+
return { walletId: event.session.walletId, network: event.session.network };
|
|
742
|
+
case "session:disconnected":
|
|
743
|
+
return {};
|
|
744
|
+
case "session:expired":
|
|
745
|
+
return {};
|
|
746
|
+
case "session:networkMismatch":
|
|
747
|
+
return { expected: event.expected, actual: event.actual, enforced: event.enforced };
|
|
748
|
+
case "tx:status":
|
|
749
|
+
return { status: event.status };
|
|
750
|
+
case "error":
|
|
751
|
+
return errorProperties(event.error);
|
|
752
|
+
case "wallets:changed":
|
|
753
|
+
return { reason: event.reason };
|
|
754
|
+
default:
|
|
755
|
+
return {};
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// src/logging.ts
|
|
760
|
+
var LEVEL_PRIORITY = {
|
|
761
|
+
debug: 10,
|
|
762
|
+
info: 20,
|
|
763
|
+
warn: 30,
|
|
764
|
+
error: 40,
|
|
765
|
+
silent: 100
|
|
766
|
+
};
|
|
767
|
+
function shouldLog(level, threshold) {
|
|
768
|
+
if (threshold === "silent") return false;
|
|
769
|
+
return LEVEL_PRIORITY[level] >= LEVEL_PRIORITY[threshold];
|
|
770
|
+
}
|
|
771
|
+
function newCorrelationId() {
|
|
772
|
+
const scope = typeof globalThis !== "undefined" ? globalThis : {};
|
|
773
|
+
if (scope.crypto && typeof scope.crypto.getRandomValues === "function") {
|
|
774
|
+
const bytes = new Uint8Array(6);
|
|
775
|
+
scope.crypto.getRandomValues(bytes);
|
|
776
|
+
let hex = "";
|
|
777
|
+
for (const byte of bytes) hex += byte.toString(16).padStart(2, "0");
|
|
778
|
+
return hex;
|
|
779
|
+
}
|
|
780
|
+
return Math.random().toString(16).slice(2, 14).padStart(12, "0");
|
|
781
|
+
}
|
|
782
|
+
function eventLogLevel(type) {
|
|
783
|
+
switch (type) {
|
|
784
|
+
case "error":
|
|
785
|
+
return "error";
|
|
786
|
+
case "session:networkMismatch":
|
|
787
|
+
return "warn";
|
|
788
|
+
case "session:connected":
|
|
789
|
+
case "session:disconnected":
|
|
790
|
+
return "info";
|
|
791
|
+
case "registry:status":
|
|
792
|
+
case "registry:updated":
|
|
793
|
+
case "session:expired":
|
|
794
|
+
case "tx:status":
|
|
795
|
+
case "wallets:changed":
|
|
796
|
+
return "debug";
|
|
797
|
+
default:
|
|
798
|
+
return "info";
|
|
799
|
+
}
|
|
800
|
+
}
|
|
734
801
|
var SESSION_STORAGE_KEY = "active_session";
|
|
735
802
|
var WALLETS_CHANGED_DEBOUNCE_MS = 50;
|
|
736
803
|
function deriveAnnounceConfig(entry) {
|
|
@@ -774,6 +841,8 @@ var PartyLayerClient = class {
|
|
|
774
841
|
registryClient;
|
|
775
842
|
// Expose for React hooks
|
|
776
843
|
logger;
|
|
844
|
+
/** Configured log verbosity; filtering happens centrally in {@link log}. */
|
|
845
|
+
logLevel;
|
|
777
846
|
crypto;
|
|
778
847
|
storage;
|
|
779
848
|
telemetry;
|
|
@@ -798,6 +867,7 @@ var PartyLayerClient = class {
|
|
|
798
867
|
this.origin = "unknown";
|
|
799
868
|
}
|
|
800
869
|
this.logger = config.logger || new DefaultLogger();
|
|
870
|
+
this.logLevel = config.logLevel ?? "info";
|
|
801
871
|
this.crypto = config.crypto || new DefaultCrypto();
|
|
802
872
|
this.storage = config.storage || new DefaultStorage();
|
|
803
873
|
const telemetryAdapter = createTelemetryAdapter(config.telemetry);
|
|
@@ -815,7 +885,7 @@ var PartyLayerClient = class {
|
|
|
815
885
|
adapter = adapterOrClass;
|
|
816
886
|
}
|
|
817
887
|
this.adapters.set(adapter.walletId, adapter);
|
|
818
|
-
this.
|
|
888
|
+
this.log("debug", "adapter:registered", "Registered wallet adapter", {
|
|
819
889
|
walletId: adapter.walletId,
|
|
820
890
|
name: adapter.name,
|
|
821
891
|
capabilities: adapter.getCapabilities()
|
|
@@ -881,7 +951,7 @@ var PartyLayerClient = class {
|
|
|
881
951
|
this.updateRegistryStatus();
|
|
882
952
|
} catch (err) {
|
|
883
953
|
this.updateRegistryStatus();
|
|
884
|
-
this.
|
|
954
|
+
this.log("warn", "registry:fetch_failed", "Registry fetch failed, using registered adapters only", {
|
|
885
955
|
error: err instanceof Error ? err.message : String(err)
|
|
886
956
|
});
|
|
887
957
|
registryWallets = [];
|
|
@@ -1069,7 +1139,9 @@ var PartyLayerClient = class {
|
|
|
1069
1139
|
this.emit("session:expired", { type: "session:expired", sessionId: active.sessionId });
|
|
1070
1140
|
}
|
|
1071
1141
|
} catch (err) {
|
|
1072
|
-
this.
|
|
1142
|
+
this.log("warn", "session:reprobe_failed", "Restore re-probe failed; leaving session as-is", {
|
|
1143
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1144
|
+
});
|
|
1073
1145
|
}
|
|
1074
1146
|
}
|
|
1075
1147
|
}
|
|
@@ -1136,11 +1208,13 @@ var PartyLayerClient = class {
|
|
|
1136
1208
|
*/
|
|
1137
1209
|
async connect(options) {
|
|
1138
1210
|
this.telemetry?.increment?.(core.METRICS.WALLET_CONNECT_ATTEMPTS);
|
|
1211
|
+
const correlationId = newCorrelationId();
|
|
1212
|
+
this.log("debug", "connect:start", "connect", {}, correlationId);
|
|
1139
1213
|
try {
|
|
1140
|
-
const fast = this.tryFastConnect(options);
|
|
1214
|
+
const fast = this.tryFastConnect(options, correlationId);
|
|
1141
1215
|
if (fast) return await fast;
|
|
1142
1216
|
const plan = await this.resolveConnectPlan(options);
|
|
1143
|
-
return await this.completeConnect(plan, options);
|
|
1217
|
+
return await this.completeConnect(plan, options, correlationId);
|
|
1144
1218
|
} catch (err) {
|
|
1145
1219
|
const timeoutMs = options?.timeoutMs || 3e4;
|
|
1146
1220
|
const error = core.mapUnknownErrorToPartyLayerError(err, {
|
|
@@ -1148,7 +1222,7 @@ var PartyLayerClient = class {
|
|
|
1148
1222
|
walletId: options?.walletId ? String(options.walletId) : void 0,
|
|
1149
1223
|
timeoutMs
|
|
1150
1224
|
});
|
|
1151
|
-
this.emit("error", { type: "error", error });
|
|
1225
|
+
this.emit("error", { type: "error", error }, correlationId);
|
|
1152
1226
|
throw error;
|
|
1153
1227
|
}
|
|
1154
1228
|
}
|
|
@@ -1252,7 +1326,7 @@ var PartyLayerClient = class {
|
|
|
1252
1326
|
* build / persist / emit the session. Separated from plan resolution so the
|
|
1253
1327
|
* popup-safe fast-path can call it gesture-synchronously.
|
|
1254
1328
|
*/
|
|
1255
|
-
async completeConnect(plan, options) {
|
|
1329
|
+
async completeConnect(plan, options, correlationId = newCorrelationId()) {
|
|
1256
1330
|
const { selectedWallet, adapter, ctx } = plan;
|
|
1257
1331
|
const timeoutMs = options?.timeoutMs || 12e4;
|
|
1258
1332
|
const connectPromise = adapter.connect(ctx, {
|
|
@@ -1295,7 +1369,7 @@ var PartyLayerClient = class {
|
|
|
1295
1369
|
expected: mismatch.expected,
|
|
1296
1370
|
actual: mismatch.actual,
|
|
1297
1371
|
enforced: this.enforcement !== "off"
|
|
1298
|
-
});
|
|
1372
|
+
}, correlationId);
|
|
1299
1373
|
if (this.enforcement === "strict") {
|
|
1300
1374
|
throw new core.NetworkMismatchError(mismatch.expected, mismatch.actual);
|
|
1301
1375
|
}
|
|
@@ -1309,7 +1383,7 @@ var PartyLayerClient = class {
|
|
|
1309
1383
|
this.emit("session:connected", {
|
|
1310
1384
|
type: "session:connected",
|
|
1311
1385
|
session
|
|
1312
|
-
});
|
|
1386
|
+
}, correlationId);
|
|
1313
1387
|
return session;
|
|
1314
1388
|
}
|
|
1315
1389
|
/**
|
|
@@ -1349,14 +1423,14 @@ var PartyLayerClient = class {
|
|
|
1349
1423
|
* Returns the in-flight Session promise, or null to fall back to the normal
|
|
1350
1424
|
* path (e.g. cold cache, or a non-discovery wallet).
|
|
1351
1425
|
*/
|
|
1352
|
-
tryFastConnect(options) {
|
|
1426
|
+
tryFastConnect(options, correlationId) {
|
|
1353
1427
|
const walletId = options?.walletId;
|
|
1354
1428
|
if (!walletId) return null;
|
|
1355
1429
|
if (options?.requiredCapabilities || options?.allowWallets) return null;
|
|
1356
1430
|
const plan = this.warmPlans.get(walletId);
|
|
1357
1431
|
if (!plan) return null;
|
|
1358
1432
|
this.warmPlans.delete(walletId);
|
|
1359
|
-
return this.completeConnect(plan, options);
|
|
1433
|
+
return this.completeConnect(plan, options, correlationId);
|
|
1360
1434
|
}
|
|
1361
1435
|
/**
|
|
1362
1436
|
* Disconnect from wallet
|
|
@@ -1448,6 +1522,8 @@ var PartyLayerClient = class {
|
|
|
1448
1522
|
"signTransaction"
|
|
1449
1523
|
);
|
|
1450
1524
|
}
|
|
1525
|
+
const correlationId = newCorrelationId();
|
|
1526
|
+
this.log("debug", "signTransaction:start", "signTransaction", {}, correlationId);
|
|
1451
1527
|
try {
|
|
1452
1528
|
this.assertNetworkOk(session);
|
|
1453
1529
|
const ctx = this.createAdapterContext();
|
|
@@ -1458,14 +1534,14 @@ var PartyLayerClient = class {
|
|
|
1458
1534
|
txId: result.transactionHash,
|
|
1459
1535
|
status: "pending",
|
|
1460
1536
|
raw: result.signedTx
|
|
1461
|
-
});
|
|
1537
|
+
}, correlationId);
|
|
1462
1538
|
return result;
|
|
1463
1539
|
} catch (err) {
|
|
1464
1540
|
const error = core.mapUnknownErrorToPartyLayerError(err, {
|
|
1465
1541
|
phase: "signTransaction",
|
|
1466
1542
|
walletId: String(session.walletId)
|
|
1467
1543
|
});
|
|
1468
|
-
this.emit("error", { type: "error", error });
|
|
1544
|
+
this.emit("error", { type: "error", error }, correlationId);
|
|
1469
1545
|
throw error;
|
|
1470
1546
|
}
|
|
1471
1547
|
}
|
|
@@ -1484,6 +1560,8 @@ var PartyLayerClient = class {
|
|
|
1484
1560
|
"submitTransaction"
|
|
1485
1561
|
);
|
|
1486
1562
|
}
|
|
1563
|
+
const correlationId = newCorrelationId();
|
|
1564
|
+
this.log("debug", "submitTransaction:start", "submitTransaction", {}, correlationId);
|
|
1487
1565
|
try {
|
|
1488
1566
|
this.assertNetworkOk(session);
|
|
1489
1567
|
const ctx = this.createAdapterContext();
|
|
@@ -1494,14 +1572,14 @@ var PartyLayerClient = class {
|
|
|
1494
1572
|
txId: result.transactionHash,
|
|
1495
1573
|
status: "submitted",
|
|
1496
1574
|
raw: result
|
|
1497
|
-
});
|
|
1575
|
+
}, correlationId);
|
|
1498
1576
|
return result;
|
|
1499
1577
|
} catch (err) {
|
|
1500
1578
|
const error = core.mapUnknownErrorToPartyLayerError(err, {
|
|
1501
1579
|
phase: "submitTransaction",
|
|
1502
1580
|
walletId: String(session.walletId)
|
|
1503
1581
|
});
|
|
1504
|
-
this.emit("error", { type: "error", error });
|
|
1582
|
+
this.emit("error", { type: "error", error }, correlationId);
|
|
1505
1583
|
throw error;
|
|
1506
1584
|
}
|
|
1507
1585
|
}
|
|
@@ -1626,7 +1704,9 @@ var PartyLayerClient = class {
|
|
|
1626
1704
|
const encrypted = await this.crypto.encrypt(data, this.origin);
|
|
1627
1705
|
await this.storage.set(SESSION_STORAGE_KEY, encrypted);
|
|
1628
1706
|
} catch (err) {
|
|
1629
|
-
this.
|
|
1707
|
+
this.log("warn", "session:persist_failed", "Failed to persist session", {
|
|
1708
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1709
|
+
});
|
|
1630
1710
|
}
|
|
1631
1711
|
}
|
|
1632
1712
|
/**
|
|
@@ -1639,7 +1719,9 @@ var PartyLayerClient = class {
|
|
|
1639
1719
|
try {
|
|
1640
1720
|
await this.storage.remove(SESSION_STORAGE_KEY);
|
|
1641
1721
|
} catch (err) {
|
|
1642
|
-
this.
|
|
1722
|
+
this.log("warn", "session:remove_failed", "Failed to remove session", {
|
|
1723
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1724
|
+
});
|
|
1643
1725
|
}
|
|
1644
1726
|
}
|
|
1645
1727
|
/**
|
|
@@ -1647,6 +1729,8 @@ var PartyLayerClient = class {
|
|
|
1647
1729
|
*/
|
|
1648
1730
|
async restoreSession() {
|
|
1649
1731
|
this.telemetry?.increment?.(core.METRICS.RESTORE_ATTEMPTS);
|
|
1732
|
+
const correlationId = newCorrelationId();
|
|
1733
|
+
this.log("debug", "session:restore_start", "restoreSession", {}, correlationId);
|
|
1650
1734
|
try {
|
|
1651
1735
|
const encrypted = await this.storage.get(SESSION_STORAGE_KEY);
|
|
1652
1736
|
if (!encrypted) {
|
|
@@ -1669,17 +1753,17 @@ var PartyLayerClient = class {
|
|
|
1669
1753
|
expected: mismatch.expected,
|
|
1670
1754
|
actual: mismatch.actual,
|
|
1671
1755
|
enforced: this.enforcement !== "off"
|
|
1672
|
-
});
|
|
1756
|
+
}, correlationId);
|
|
1673
1757
|
if (this.enforcement !== "off") {
|
|
1674
|
-
this.
|
|
1758
|
+
this.log("warn", "session:restore_network_mismatch", "Refused session restore: network mismatch", {
|
|
1675
1759
|
expected: mismatch.expected,
|
|
1676
1760
|
actual: mismatch.actual
|
|
1677
|
-
});
|
|
1761
|
+
}, correlationId);
|
|
1678
1762
|
await this.removeSession(session.sessionId);
|
|
1679
1763
|
this.emit("session:expired", {
|
|
1680
1764
|
type: "session:expired",
|
|
1681
1765
|
sessionId: session.sessionId
|
|
1682
|
-
});
|
|
1766
|
+
}, correlationId);
|
|
1683
1767
|
return null;
|
|
1684
1768
|
}
|
|
1685
1769
|
session.networkMismatch = mismatch;
|
|
@@ -1700,14 +1784,14 @@ var PartyLayerClient = class {
|
|
|
1700
1784
|
this.emit("session:connected", {
|
|
1701
1785
|
type: "session:connected",
|
|
1702
1786
|
session: restored
|
|
1703
|
-
});
|
|
1787
|
+
}, correlationId);
|
|
1704
1788
|
return restored;
|
|
1705
1789
|
} else {
|
|
1706
1790
|
await this.removeSession(session.sessionId);
|
|
1707
1791
|
this.emit("session:expired", {
|
|
1708
1792
|
type: "session:expired",
|
|
1709
1793
|
sessionId: session.sessionId
|
|
1710
|
-
});
|
|
1794
|
+
}, correlationId);
|
|
1711
1795
|
return null;
|
|
1712
1796
|
}
|
|
1713
1797
|
}
|
|
@@ -1715,7 +1799,9 @@ var PartyLayerClient = class {
|
|
|
1715
1799
|
this.activeSessionNeedsProbe = true;
|
|
1716
1800
|
return session;
|
|
1717
1801
|
} catch (err) {
|
|
1718
|
-
this.
|
|
1802
|
+
this.log("warn", "session:restore_failed", "Failed to restore session", {
|
|
1803
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1804
|
+
}, correlationId);
|
|
1719
1805
|
return null;
|
|
1720
1806
|
}
|
|
1721
1807
|
}
|
|
@@ -1757,20 +1843,56 @@ var PartyLayerClient = class {
|
|
|
1757
1843
|
/**
|
|
1758
1844
|
* Emit event to handlers
|
|
1759
1845
|
*/
|
|
1760
|
-
|
|
1846
|
+
/**
|
|
1847
|
+
* Central structured log. Filters by the configured level here, before the adapter
|
|
1848
|
+
* is called, so adapters never filter themselves; skips entirely when no real
|
|
1849
|
+
* logger was configured (the no-op default), so a silent client pays only a check.
|
|
1850
|
+
* Every line carries a machine readable payload `{ event, correlationId?, ...fields }`.
|
|
1851
|
+
* Privacy: callers pass only non identifying fields, the same rule as telemetry.
|
|
1852
|
+
*/
|
|
1853
|
+
log(level, event, message, fields, correlationId) {
|
|
1854
|
+
if (this.logger instanceof DefaultLogger) return;
|
|
1855
|
+
if (!shouldLog(level, this.logLevel)) return;
|
|
1856
|
+
const payload = {
|
|
1857
|
+
event,
|
|
1858
|
+
...correlationId ? { correlationId } : {},
|
|
1859
|
+
...fields ?? {}
|
|
1860
|
+
};
|
|
1861
|
+
switch (level) {
|
|
1862
|
+
case "debug":
|
|
1863
|
+
this.logger.debug(message, payload);
|
|
1864
|
+
break;
|
|
1865
|
+
case "info":
|
|
1866
|
+
this.logger.info(message, payload);
|
|
1867
|
+
break;
|
|
1868
|
+
case "warn":
|
|
1869
|
+
this.logger.warn(message, payload);
|
|
1870
|
+
break;
|
|
1871
|
+
case "error":
|
|
1872
|
+
this.logger.error(message, payload);
|
|
1873
|
+
break;
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
emit(event, payload, correlationId) {
|
|
1761
1877
|
if (event === "error" && "error" in payload) {
|
|
1762
1878
|
const error = payload.error;
|
|
1763
1879
|
if (error.code) {
|
|
1764
1880
|
this.telemetry?.increment?.(core.errorMetricName(error.code));
|
|
1765
1881
|
}
|
|
1766
1882
|
}
|
|
1883
|
+
if (this.telemetry && !(this.telemetry instanceof DefaultTelemetry)) {
|
|
1884
|
+
this.telemetry.track(event, eventTelemetryProperties(payload));
|
|
1885
|
+
}
|
|
1886
|
+
this.log(eventLogLevel(event), event, event, eventTelemetryProperties(payload), correlationId);
|
|
1767
1887
|
const handlers = this.eventHandlers.get(event);
|
|
1768
1888
|
if (handlers) {
|
|
1769
1889
|
for (const handler of handlers) {
|
|
1770
1890
|
try {
|
|
1771
1891
|
handler(payload);
|
|
1772
1892
|
} catch (err) {
|
|
1773
|
-
this.
|
|
1893
|
+
this.log("error", "event:handler_error", "Error in event handler", {
|
|
1894
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1895
|
+
});
|
|
1774
1896
|
}
|
|
1775
1897
|
}
|
|
1776
1898
|
}
|