@partylayer/sdk 0.14.1 → 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/README.md +2 -2
- package/dist/index.d.mts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +169 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +169 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
## Overview
|
|
16
16
|
|
|
17
|
-
`@partylayer/sdk` provides a unified interface for connecting your decentralized application (dApp) to multiple Canton Network wallets. It abstracts wallet-specific implementations behind a simple, type-safe API
|
|
17
|
+
`@partylayer/sdk` provides a unified interface for connecting your decentralized application (dApp) to multiple Canton Network wallets. It abstracts wallet-specific implementations behind a simple, type-safe API, one integration for every Canton wallet.
|
|
18
18
|
|
|
19
19
|
### Features
|
|
20
20
|
|
|
@@ -130,7 +130,7 @@ await client.disconnect();
|
|
|
130
130
|
| WalletConnect | devnet, testnet, mainnet | signMessage, submitTransaction | Yes | `@partylayer/adapter-walletconnect` |
|
|
131
131
|
<!-- WALLETS:END -->
|
|
132
132
|
|
|
133
|
-
> **Try it live:** [PartyLayer Studio](https://studio.partylayer.xyz)
|
|
133
|
+
> **Try it live:** [PartyLayer Studio](https://studio.partylayer.xyz), runnable, editable scenarios · [Pattern Cookbook](https://partylayer.xyz/docs/cookbook), copy-paste recipes.
|
|
134
134
|
|
|
135
135
|
---
|
|
136
136
|
|
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, {
|
|
@@ -1280,7 +1354,11 @@ var PartyLayerClient = class {
|
|
|
1280
1354
|
expiresAt: result.session.expiresAt,
|
|
1281
1355
|
origin: this.origin,
|
|
1282
1356
|
capabilitiesSnapshot: result.capabilities,
|
|
1283
|
-
metadata: result.session.metadata
|
|
1357
|
+
metadata: result.session.metadata,
|
|
1358
|
+
// Fund-safety passthrough: the wallet's payout-preapproval signal, if the
|
|
1359
|
+
// adapter surfaced it at connect. Optional; absent when not reported.
|
|
1360
|
+
hasPreapproval: result.session.hasPreapproval,
|
|
1361
|
+
utilityPreapprovalAdmins: result.session.utilityPreapprovalAdmins
|
|
1284
1362
|
};
|
|
1285
1363
|
const mismatch = this.networkMismatch(session);
|
|
1286
1364
|
if (mismatch) {
|
|
@@ -1291,7 +1369,7 @@ var PartyLayerClient = class {
|
|
|
1291
1369
|
expected: mismatch.expected,
|
|
1292
1370
|
actual: mismatch.actual,
|
|
1293
1371
|
enforced: this.enforcement !== "off"
|
|
1294
|
-
});
|
|
1372
|
+
}, correlationId);
|
|
1295
1373
|
if (this.enforcement === "strict") {
|
|
1296
1374
|
throw new core.NetworkMismatchError(mismatch.expected, mismatch.actual);
|
|
1297
1375
|
}
|
|
@@ -1305,7 +1383,7 @@ var PartyLayerClient = class {
|
|
|
1305
1383
|
this.emit("session:connected", {
|
|
1306
1384
|
type: "session:connected",
|
|
1307
1385
|
session
|
|
1308
|
-
});
|
|
1386
|
+
}, correlationId);
|
|
1309
1387
|
return session;
|
|
1310
1388
|
}
|
|
1311
1389
|
/**
|
|
@@ -1345,14 +1423,14 @@ var PartyLayerClient = class {
|
|
|
1345
1423
|
* Returns the in-flight Session promise, or null to fall back to the normal
|
|
1346
1424
|
* path (e.g. cold cache, or a non-discovery wallet).
|
|
1347
1425
|
*/
|
|
1348
|
-
tryFastConnect(options) {
|
|
1426
|
+
tryFastConnect(options, correlationId) {
|
|
1349
1427
|
const walletId = options?.walletId;
|
|
1350
1428
|
if (!walletId) return null;
|
|
1351
1429
|
if (options?.requiredCapabilities || options?.allowWallets) return null;
|
|
1352
1430
|
const plan = this.warmPlans.get(walletId);
|
|
1353
1431
|
if (!plan) return null;
|
|
1354
1432
|
this.warmPlans.delete(walletId);
|
|
1355
|
-
return this.completeConnect(plan, options);
|
|
1433
|
+
return this.completeConnect(plan, options, correlationId);
|
|
1356
1434
|
}
|
|
1357
1435
|
/**
|
|
1358
1436
|
* Disconnect from wallet
|
|
@@ -1444,6 +1522,8 @@ var PartyLayerClient = class {
|
|
|
1444
1522
|
"signTransaction"
|
|
1445
1523
|
);
|
|
1446
1524
|
}
|
|
1525
|
+
const correlationId = newCorrelationId();
|
|
1526
|
+
this.log("debug", "signTransaction:start", "signTransaction", {}, correlationId);
|
|
1447
1527
|
try {
|
|
1448
1528
|
this.assertNetworkOk(session);
|
|
1449
1529
|
const ctx = this.createAdapterContext();
|
|
@@ -1454,14 +1534,14 @@ var PartyLayerClient = class {
|
|
|
1454
1534
|
txId: result.transactionHash,
|
|
1455
1535
|
status: "pending",
|
|
1456
1536
|
raw: result.signedTx
|
|
1457
|
-
});
|
|
1537
|
+
}, correlationId);
|
|
1458
1538
|
return result;
|
|
1459
1539
|
} catch (err) {
|
|
1460
1540
|
const error = core.mapUnknownErrorToPartyLayerError(err, {
|
|
1461
1541
|
phase: "signTransaction",
|
|
1462
1542
|
walletId: String(session.walletId)
|
|
1463
1543
|
});
|
|
1464
|
-
this.emit("error", { type: "error", error });
|
|
1544
|
+
this.emit("error", { type: "error", error }, correlationId);
|
|
1465
1545
|
throw error;
|
|
1466
1546
|
}
|
|
1467
1547
|
}
|
|
@@ -1480,6 +1560,8 @@ var PartyLayerClient = class {
|
|
|
1480
1560
|
"submitTransaction"
|
|
1481
1561
|
);
|
|
1482
1562
|
}
|
|
1563
|
+
const correlationId = newCorrelationId();
|
|
1564
|
+
this.log("debug", "submitTransaction:start", "submitTransaction", {}, correlationId);
|
|
1483
1565
|
try {
|
|
1484
1566
|
this.assertNetworkOk(session);
|
|
1485
1567
|
const ctx = this.createAdapterContext();
|
|
@@ -1490,14 +1572,14 @@ var PartyLayerClient = class {
|
|
|
1490
1572
|
txId: result.transactionHash,
|
|
1491
1573
|
status: "submitted",
|
|
1492
1574
|
raw: result
|
|
1493
|
-
});
|
|
1575
|
+
}, correlationId);
|
|
1494
1576
|
return result;
|
|
1495
1577
|
} catch (err) {
|
|
1496
1578
|
const error = core.mapUnknownErrorToPartyLayerError(err, {
|
|
1497
1579
|
phase: "submitTransaction",
|
|
1498
1580
|
walletId: String(session.walletId)
|
|
1499
1581
|
});
|
|
1500
|
-
this.emit("error", { type: "error", error });
|
|
1582
|
+
this.emit("error", { type: "error", error }, correlationId);
|
|
1501
1583
|
throw error;
|
|
1502
1584
|
}
|
|
1503
1585
|
}
|
|
@@ -1622,7 +1704,9 @@ var PartyLayerClient = class {
|
|
|
1622
1704
|
const encrypted = await this.crypto.encrypt(data, this.origin);
|
|
1623
1705
|
await this.storage.set(SESSION_STORAGE_KEY, encrypted);
|
|
1624
1706
|
} catch (err) {
|
|
1625
|
-
this.
|
|
1707
|
+
this.log("warn", "session:persist_failed", "Failed to persist session", {
|
|
1708
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1709
|
+
});
|
|
1626
1710
|
}
|
|
1627
1711
|
}
|
|
1628
1712
|
/**
|
|
@@ -1635,7 +1719,9 @@ var PartyLayerClient = class {
|
|
|
1635
1719
|
try {
|
|
1636
1720
|
await this.storage.remove(SESSION_STORAGE_KEY);
|
|
1637
1721
|
} catch (err) {
|
|
1638
|
-
this.
|
|
1722
|
+
this.log("warn", "session:remove_failed", "Failed to remove session", {
|
|
1723
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1724
|
+
});
|
|
1639
1725
|
}
|
|
1640
1726
|
}
|
|
1641
1727
|
/**
|
|
@@ -1643,6 +1729,8 @@ var PartyLayerClient = class {
|
|
|
1643
1729
|
*/
|
|
1644
1730
|
async restoreSession() {
|
|
1645
1731
|
this.telemetry?.increment?.(core.METRICS.RESTORE_ATTEMPTS);
|
|
1732
|
+
const correlationId = newCorrelationId();
|
|
1733
|
+
this.log("debug", "session:restore_start", "restoreSession", {}, correlationId);
|
|
1646
1734
|
try {
|
|
1647
1735
|
const encrypted = await this.storage.get(SESSION_STORAGE_KEY);
|
|
1648
1736
|
if (!encrypted) {
|
|
@@ -1665,17 +1753,17 @@ var PartyLayerClient = class {
|
|
|
1665
1753
|
expected: mismatch.expected,
|
|
1666
1754
|
actual: mismatch.actual,
|
|
1667
1755
|
enforced: this.enforcement !== "off"
|
|
1668
|
-
});
|
|
1756
|
+
}, correlationId);
|
|
1669
1757
|
if (this.enforcement !== "off") {
|
|
1670
|
-
this.
|
|
1758
|
+
this.log("warn", "session:restore_network_mismatch", "Refused session restore: network mismatch", {
|
|
1671
1759
|
expected: mismatch.expected,
|
|
1672
1760
|
actual: mismatch.actual
|
|
1673
|
-
});
|
|
1761
|
+
}, correlationId);
|
|
1674
1762
|
await this.removeSession(session.sessionId);
|
|
1675
1763
|
this.emit("session:expired", {
|
|
1676
1764
|
type: "session:expired",
|
|
1677
1765
|
sessionId: session.sessionId
|
|
1678
|
-
});
|
|
1766
|
+
}, correlationId);
|
|
1679
1767
|
return null;
|
|
1680
1768
|
}
|
|
1681
1769
|
session.networkMismatch = mismatch;
|
|
@@ -1696,14 +1784,14 @@ var PartyLayerClient = class {
|
|
|
1696
1784
|
this.emit("session:connected", {
|
|
1697
1785
|
type: "session:connected",
|
|
1698
1786
|
session: restored
|
|
1699
|
-
});
|
|
1787
|
+
}, correlationId);
|
|
1700
1788
|
return restored;
|
|
1701
1789
|
} else {
|
|
1702
1790
|
await this.removeSession(session.sessionId);
|
|
1703
1791
|
this.emit("session:expired", {
|
|
1704
1792
|
type: "session:expired",
|
|
1705
1793
|
sessionId: session.sessionId
|
|
1706
|
-
});
|
|
1794
|
+
}, correlationId);
|
|
1707
1795
|
return null;
|
|
1708
1796
|
}
|
|
1709
1797
|
}
|
|
@@ -1711,7 +1799,9 @@ var PartyLayerClient = class {
|
|
|
1711
1799
|
this.activeSessionNeedsProbe = true;
|
|
1712
1800
|
return session;
|
|
1713
1801
|
} catch (err) {
|
|
1714
|
-
this.
|
|
1802
|
+
this.log("warn", "session:restore_failed", "Failed to restore session", {
|
|
1803
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1804
|
+
}, correlationId);
|
|
1715
1805
|
return null;
|
|
1716
1806
|
}
|
|
1717
1807
|
}
|
|
@@ -1753,20 +1843,56 @@ var PartyLayerClient = class {
|
|
|
1753
1843
|
/**
|
|
1754
1844
|
* Emit event to handlers
|
|
1755
1845
|
*/
|
|
1756
|
-
|
|
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) {
|
|
1757
1877
|
if (event === "error" && "error" in payload) {
|
|
1758
1878
|
const error = payload.error;
|
|
1759
1879
|
if (error.code) {
|
|
1760
1880
|
this.telemetry?.increment?.(core.errorMetricName(error.code));
|
|
1761
1881
|
}
|
|
1762
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);
|
|
1763
1887
|
const handlers = this.eventHandlers.get(event);
|
|
1764
1888
|
if (handlers) {
|
|
1765
1889
|
for (const handler of handlers) {
|
|
1766
1890
|
try {
|
|
1767
1891
|
handler(payload);
|
|
1768
1892
|
} catch (err) {
|
|
1769
|
-
this.
|
|
1893
|
+
this.log("error", "event:handler_error", "Error in event handler", {
|
|
1894
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1895
|
+
});
|
|
1770
1896
|
}
|
|
1771
1897
|
}
|
|
1772
1898
|
}
|