@meshconnect/uwc-core 1.0.1-snapshot.c7e65ce → 1.0.2

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.
Files changed (76) hide show
  1. package/README.md +66 -211
  2. package/dist/events.d.ts +2 -69
  3. package/dist/events.d.ts.map +1 -1
  4. package/dist/events.js +1 -40
  5. package/dist/events.js.map +1 -1
  6. package/dist/index.d.ts +0 -2
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +0 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/managers/event-manager.d.ts.map +1 -1
  11. package/dist/managers/event-manager.js +1 -5
  12. package/dist/managers/event-manager.js.map +1 -1
  13. package/dist/services/connection-service.d.ts +1 -2
  14. package/dist/services/connection-service.d.ts.map +1 -1
  15. package/dist/services/connection-service.js +15 -35
  16. package/dist/services/connection-service.js.map +1 -1
  17. package/dist/services/network-switch-service.d.ts +1 -2
  18. package/dist/services/network-switch-service.d.ts.map +1 -1
  19. package/dist/services/network-switch-service.js +15 -33
  20. package/dist/services/network-switch-service.js.map +1 -1
  21. package/dist/universal-wallet-connector.d.ts +2 -51
  22. package/dist/universal-wallet-connector.d.ts.map +1 -1
  23. package/dist/universal-wallet-connector.js +61 -163
  24. package/dist/universal-wallet-connector.js.map +1 -1
  25. package/package.json +5 -5
  26. package/src/events.ts +1 -114
  27. package/src/index.ts +0 -6
  28. package/src/managers/event-manager.test.ts +0 -25
  29. package/src/managers/event-manager.ts +1 -5
  30. package/src/services/connection-service.test.ts +1 -66
  31. package/src/services/connection-service.ts +32 -54
  32. package/src/services/network-switch-service.test.ts +1 -51
  33. package/src/services/network-switch-service.ts +23 -43
  34. package/src/universal-wallet-connector.ts +71 -244
  35. package/dist/logger/create-logger.d.ts +0 -32
  36. package/dist/logger/create-logger.d.ts.map +0 -1
  37. package/dist/logger/create-logger.js +0 -69
  38. package/dist/logger/create-logger.js.map +0 -1
  39. package/dist/observability/connect-observer.d.ts +0 -22
  40. package/dist/observability/connect-observer.d.ts.map +0 -1
  41. package/dist/observability/connect-observer.js +0 -60
  42. package/dist/observability/connect-observer.js.map +0 -1
  43. package/dist/observability/instrument-handoff.d.ts +0 -39
  44. package/dist/observability/instrument-handoff.d.ts.map +0 -1
  45. package/dist/observability/instrument-handoff.js +0 -86
  46. package/dist/observability/instrument-handoff.js.map +0 -1
  47. package/dist/observability/scrub.d.ts +0 -30
  48. package/dist/observability/scrub.d.ts.map +0 -1
  49. package/dist/observability/scrub.js +0 -135
  50. package/dist/observability/scrub.js.map +0 -1
  51. package/dist/observability/telemetry.d.ts +0 -77
  52. package/dist/observability/telemetry.d.ts.map +0 -1
  53. package/dist/observability/telemetry.js +0 -138
  54. package/dist/observability/telemetry.js.map +0 -1
  55. package/dist/utils/id.d.ts +0 -2
  56. package/dist/utils/id.d.ts.map +0 -1
  57. package/dist/utils/id.js +0 -41
  58. package/dist/utils/id.js.map +0 -1
  59. package/dist/utils/to-wallet-error.d.ts +0 -16
  60. package/dist/utils/to-wallet-error.d.ts.map +0 -1
  61. package/dist/utils/to-wallet-error.js +0 -33
  62. package/dist/utils/to-wallet-error.js.map +0 -1
  63. package/src/logger/create-logger.test.ts +0 -111
  64. package/src/logger/create-logger.ts +0 -101
  65. package/src/observability/connect-observer.test.ts +0 -100
  66. package/src/observability/connect-observer.ts +0 -71
  67. package/src/observability/instrument-handoff.test.ts +0 -150
  68. package/src/observability/instrument-handoff.ts +0 -122
  69. package/src/observability/scrub.test.ts +0 -109
  70. package/src/observability/scrub.ts +0 -142
  71. package/src/observability/telemetry.test.ts +0 -134
  72. package/src/observability/telemetry.ts +0 -211
  73. package/src/universal-wallet-connector.observability.test.ts +0 -265
  74. package/src/utils/id.test.ts +0 -15
  75. package/src/utils/id.ts +0 -48
  76. package/src/utils/to-wallet-error.ts +0 -36
@@ -18,10 +18,9 @@ import type {
18
18
  EVMCapabilities,
19
19
  SignatureType,
20
20
  EIP712TypedData,
21
- LogLevel,
22
- Logger,
23
- Session
21
+ WalletError
24
22
  } from '@meshconnect/uwc-types'
23
+ import { WalletConnectorError } from '@meshconnect/uwc-types'
25
24
  import { InjectedConnector } from '@meshconnect/uwc-injected-connector'
26
25
  import { WalletConnectConnector } from '@meshconnect/uwc-wallet-connect-connector'
27
26
  import { TonConnectConnector } from '@meshconnect/uwc-ton-connector'
@@ -34,20 +33,8 @@ import { SignatureService } from './services/signature-service'
34
33
  import { TransactionService } from './services/transaction-service'
35
34
  import { WalletCapabilitiesService } from './services/wallet-capabilities-service'
36
35
  import { createNetworkRpcMap } from './utils/network-rpc-utils'
37
- import { generateId } from './utils/id'
38
- import { toWalletError, isAbortError } from './utils/to-wallet-error'
39
- import { createLogger, type ManagedLogger } from './logger/create-logger'
40
- import { connectObserver } from './observability/connect-observer'
41
- import type { UWCObserver } from './observability/telemetry'
42
- import {
43
- instrumentHandoff,
44
- type HandoffContext
45
- } from './observability/instrument-handoff'
46
36
  import type { UWCEventName, UWCEventListener, UWCOperation } from './events'
47
37
 
48
- /** Default observational wallet-response deadline (ms). Matches TON's 60s. */
49
- const DEFAULT_WALLET_RESPONSE_TIMEOUT_MS = 60_000
50
-
51
38
  /**
52
39
  * Configuration object form of the UniversalWalletConnector constructor.
53
40
  * Prefer this over the positional constructor in new code.
@@ -62,35 +49,6 @@ export interface UWCConfig {
62
49
  walletConnectConfig?: WalletConnectConfig
63
50
  tonConnectConfig?: TonConnectConfig
64
51
  tronConnectorConfig?: TronConnectorConfig
65
- // ---- Observability (all optional; defaults preserve current behaviour) -----
66
- /**
67
- * Vendor-agnostic telemetry sink. When omitted, UWC emits NOTHING externally —
68
- * zero egress is the security-first default for a sign-only wallet layer. The
69
- * consumer implements the sink and wires it to their backend (Datadog/…).
70
- */
71
- observer?: UWCObserver
72
- /**
73
- * Redirect UWC's internal logging into your own logger. Receives raw
74
- * `(message, ...args)` at/above `logLevel`. When omitted, a console-backed
75
- * logger is used.
76
- */
77
- logger?: Logger
78
- /** Console threshold for the default logger. Default `'warn'`. */
79
- logLevel?: LogLevel
80
- /**
81
- * Correlation id stamped on every telemetry record (`sdkSessionId`). Supply
82
- * your own (e.g. the consumer's `link_sess_id`) so UWC events join your existing
83
- * telemetry in Datadog/RUM without a separate mapping. Pass a getter if the id
84
- * isn't known at construction or can change. Defaults to a generated per-instance
85
- * id. Resolved per-event; a throwing/empty getter falls back to the default.
86
- */
87
- correlationId?: string | (() => string)
88
- /**
89
- * Observational wallet-response deadline (ms) for the `walletTimedOut` marker.
90
- * `0` disables it. TON is always exempt (it bounds its own response). Default
91
- * 60_000.
92
- */
93
- walletResponseTimeoutMs?: number
94
52
  }
95
53
 
96
54
  /** Common options for user-initiated async operations. */
@@ -117,12 +75,6 @@ export class UniversalWalletConnector {
117
75
  private usingIntegratedBrowser: boolean
118
76
  private detectionComplete = false
119
77
  private networkRpcMap: NetworkRpcMap
120
- private logger: ManagedLogger
121
- /** Per-instance correlation id stamped on every telemetry record. */
122
- private readonly sdkSessionId: string = generateId()
123
- private walletResponseTimeoutMs: number
124
- /** Tears down the observer subscriptions; set only when an observer is wired. */
125
- private observerTeardown: (() => void) | undefined
126
78
 
127
79
  /**
128
80
  * Recommended entry point: returns the shared instance, creating it on the
@@ -200,49 +152,14 @@ export class UniversalWalletConnector {
200
152
  tronConnectorConfig: configuredTronConnectorConfig
201
153
  } = config
202
154
 
203
- // Observability seam — wire the event bus, logger, and (optional) observer
204
- // FIRST so even construction-time logs/events are captured. `sdkSessionId` is
205
- // already assigned as a field initializer.
206
- this.eventManager = new EventManager()
207
- this.walletResponseTimeoutMs =
208
- config.walletResponseTimeoutMs ?? DEFAULT_WALLET_RESPONSE_TIMEOUT_MS
209
- this.logger = createLogger({
210
- level: config.logLevel ?? 'warn',
211
- sink: config.logger,
212
- // Pre-gate tap → typed `log` event → observer.onLog. Fires for all levels
213
- // regardless of the console threshold.
214
- onLog: (level, message, args) =>
215
- this.eventManager.emit('log', { level, message, args })
216
- })
217
- if (config.observer) {
218
- // Resolve the correlation id per-event. A consumer can align it to their
219
- // own session key (e.g. link_sess_id); the generated `sdkSessionId` is the
220
- // always-available fallback if none is supplied or a getter misbehaves.
221
- const cid = config.correlationId
222
- const getCorrelationId: () => string =
223
- typeof cid === 'function'
224
- ? () => {
225
- try {
226
- return cid() || this.sdkSessionId
227
- } catch {
228
- return this.sdkSessionId
229
- }
230
- }
231
- : () => cid ?? this.sdkSessionId
232
- this.observerTeardown = connectObserver(
233
- this.eventManager,
234
- config.observer,
235
- getCorrelationId
236
- )
237
- }
238
-
239
155
  // Track instance creation and warn on duplicates
240
156
  UniversalWalletConnector.instanceCount++
241
157
  if (
242
158
  UniversalWalletConnector.instanceCount > 1 &&
243
159
  !UniversalWalletConnector.hasWarnedAboutMultipleInstances
244
160
  ) {
245
- this.logger.error(
161
+ // eslint-disable-next-line no-console
162
+ console.error(
246
163
  `⚠️ WARNING: Multiple instances of UniversalWalletConnector detected (${UniversalWalletConnector.instanceCount} instances). ` +
247
164
  'This can lead to state inconsistencies and unexpected behavior. ' +
248
165
  'Please ensure you create only one instance and reuse it throughout your application. ' +
@@ -303,22 +220,21 @@ export class UniversalWalletConnector {
303
220
  }
304
221
 
305
222
  this.sessionManager = new SessionManager()
223
+ this.eventManager = new EventManager()
306
224
  this.connectionService = new ConnectionService(
307
225
  networks,
308
226
  this.wallets,
309
227
  this.sessionManager,
310
228
  this.connectors,
311
229
  configuredUsingIntegratedBrowser,
312
- this.eventManager,
313
- this.walletResponseTimeoutMs
230
+ this.eventManager
314
231
  )
315
232
  this.networkSwitchService = new NetworkSwitchService(
316
233
  networks,
317
234
  this.sessionManager,
318
235
  this.connectors,
319
236
  configuredUsingIntegratedBrowser,
320
- this.eventManager,
321
- this.walletResponseTimeoutMs
237
+ this.eventManager
322
238
  )
323
239
  this.signatureService = new SignatureService(
324
240
  this.sessionManager,
@@ -602,9 +518,6 @@ export class UniversalWalletConnector {
602
518
  options?: OperationOptions
603
519
  ): Promise<void> {
604
520
  try {
605
- // Hand-off instrumentation lives in ConnectionService.connect (emitted
606
- // after validation, at the real wallet boundary) — not here, so pre-wallet
607
- // validation failures don't pollute the funnel.
608
521
  await this.connectionService.connect(
609
522
  connectionMode,
610
523
  walletId,
@@ -635,8 +548,6 @@ export class UniversalWalletConnector {
635
548
  options?: OperationOptions
636
549
  ): Promise<void> {
637
550
  try {
638
- // Hand-off instrumentation lives in NetworkSwitchService.switchNetwork
639
- // (emitted after validation, at the real wallet boundary).
640
551
  await this.networkSwitchService.switchNetwork(networkId, options)
641
552
  } catch (error) {
642
553
  this.emitError(error, 'switchNetwork')
@@ -669,36 +580,27 @@ export class UniversalWalletConnector {
669
580
  }
670
581
 
671
582
  try {
672
- return await this.instrument(
673
- this.sessionHandoffContext('signMessage', session),
674
- async () => {
675
- // Get the provider from the active wallet based on connection mode
676
- let provider
677
- if (session.connectionMode === 'injected') {
678
- provider = this.usingIntegratedBrowser
679
- ? session.activeWallet!.integratedBrowserInjectedProvider
680
- : session.activeWallet!.extensionInjectedProvider
681
- } else if (session.connectionMode === 'walletConnect') {
682
- provider = session.activeWallet!.walletConnectProvider
683
- } else if (session.connectionMode === 'tonConnect') {
684
- return await this.signatureService.signMessage(
685
- message,
686
- undefined,
687
- options
688
- )
689
- }
583
+ // Get the provider from the active wallet based on connection mode
584
+ let provider
585
+ if (session.connectionMode === 'injected') {
586
+ provider = this.usingIntegratedBrowser
587
+ ? session.activeWallet.integratedBrowserInjectedProvider
588
+ : session.activeWallet.extensionInjectedProvider
589
+ } else if (session.connectionMode === 'walletConnect') {
590
+ provider = session.activeWallet.walletConnectProvider
591
+ } else if (session.connectionMode === 'tonConnect') {
592
+ return await this.signatureService.signMessage(
593
+ message,
594
+ undefined,
595
+ options
596
+ )
597
+ }
690
598
 
691
- if (!provider) {
692
- throw new Error('No provider available for the active wallet')
693
- }
599
+ if (!provider) {
600
+ throw new Error('No provider available for the active wallet')
601
+ }
694
602
 
695
- return await this.signatureService.signMessage(
696
- message,
697
- provider,
698
- options
699
- )
700
- }
701
- )
603
+ return await this.signatureService.signMessage(message, provider, options)
702
604
  } catch (error) {
703
605
  this.emitError(error, 'signMessage')
704
606
  throw error
@@ -728,30 +630,20 @@ export class UniversalWalletConnector {
728
630
  throw new Error('signTypedData is not supported for TON wallets')
729
631
  }
730
632
 
731
- try {
732
- return await this.instrument(
733
- this.sessionHandoffContext('signTypedData', session),
734
- async () => {
735
- // Resolve the injected provider from the active wallet. WalletConnect
736
- // resolves its own provider inside the connector, so it stays undefined.
737
- let provider
738
- if (session.connectionMode === 'injected') {
739
- provider = this.usingIntegratedBrowser
740
- ? session.activeWallet!.integratedBrowserInjectedProvider
741
- : session.activeWallet!.extensionInjectedProvider
742
-
743
- if (!provider) {
744
- throw new Error('No provider available for the active wallet')
745
- }
746
- }
633
+ // Resolve the injected provider from the active wallet. WalletConnect
634
+ // resolves its own provider inside the connector, so it stays undefined here.
635
+ let provider
636
+ if (session.connectionMode === 'injected') {
637
+ provider = this.usingIntegratedBrowser
638
+ ? session.activeWallet.integratedBrowserInjectedProvider
639
+ : session.activeWallet.extensionInjectedProvider
747
640
 
748
- return await this.signatureService.signTypedData(typedData, provider)
749
- }
750
- )
751
- } catch (error) {
752
- this.emitError(error, 'signTypedData')
753
- throw error
641
+ if (!provider) {
642
+ throw new Error('No provider available for the active wallet')
643
+ }
754
644
  }
645
+
646
+ return await this.signatureService.signTypedData(typedData, provider)
755
647
  }
756
648
 
757
649
  /**
@@ -775,35 +667,30 @@ export class UniversalWalletConnector {
775
667
  }
776
668
 
777
669
  try {
778
- return await this.instrument(
779
- this.sessionHandoffContext('sendTransaction', session),
780
- async () => {
781
- // Get the provider from the active wallet based on connection mode
782
- let provider
783
- if (session.connectionMode === 'injected') {
784
- provider = this.usingIntegratedBrowser
785
- ? session.activeWallet!.integratedBrowserInjectedProvider
786
- : session.activeWallet!.extensionInjectedProvider
787
- } else if (session.connectionMode === 'walletConnect') {
788
- provider = session.activeWallet!.walletConnectProvider
789
- } else if (session.connectionMode === 'tonConnect') {
790
- return await this.transactionService.sendTransaction(
791
- request,
792
- undefined,
793
- options
794
- )
795
- }
670
+ // Get the provider from the active wallet based on connection mode
671
+ let provider
672
+ if (session.connectionMode === 'injected') {
673
+ provider = this.usingIntegratedBrowser
674
+ ? session.activeWallet.integratedBrowserInjectedProvider
675
+ : session.activeWallet.extensionInjectedProvider
676
+ } else if (session.connectionMode === 'walletConnect') {
677
+ provider = session.activeWallet.walletConnectProvider
678
+ } else if (session.connectionMode === 'tonConnect') {
679
+ return await this.transactionService.sendTransaction(
680
+ request,
681
+ undefined,
682
+ options
683
+ )
684
+ }
796
685
 
797
- if (!provider) {
798
- throw new Error('No provider available for the active wallet')
799
- }
686
+ if (!provider) {
687
+ throw new Error('No provider available for the active wallet')
688
+ }
800
689
 
801
- return await this.transactionService.sendTransaction(
802
- request,
803
- provider,
804
- options
805
- )
806
- }
690
+ return await this.transactionService.sendTransaction(
691
+ request,
692
+ provider,
693
+ options
807
694
  )
808
695
  } catch (error) {
809
696
  this.emitError(error, 'sendTransaction')
@@ -835,15 +722,7 @@ export class UniversalWalletConnector {
835
722
  )
836
723
  }
837
724
 
838
- try {
839
- return await this.instrument(
840
- this.sessionHandoffContext('signSolanaTransaction', session),
841
- () => connector.signSolanaTransactionBytes!(serializedTx)
842
- )
843
- } catch (error) {
844
- this.emitError(error, 'signSolanaTransaction')
845
- throw error
846
- }
725
+ return await connector.signSolanaTransactionBytes(serializedTx)
847
726
  }
848
727
 
849
728
  /**
@@ -930,74 +809,22 @@ export class UniversalWalletConnector {
930
809
  return session.activeWalletCapabilities
931
810
  }
932
811
 
933
- /**
934
- * Set the console log threshold at runtime (e.g. from a support toggle). The
935
- * global `window.UWC_DEBUG` override still takes precedence for ad-hoc triage.
936
- */
937
- setLogLevel(level: LogLevel): void {
938
- this.logger.setLevel(level)
939
- }
940
-
941
- /**
942
- * Release observer subscriptions and clear all event listeners. Call on full
943
- * teardown / logout to avoid leaking listeners across connector lifecycles.
944
- */
945
- dispose(): void {
946
- this.observerTeardown?.()
947
- this.observerTeardown = undefined
948
- this.eventManager.clearAllListeners()
949
- // Full teardown: if this was the shared singleton, clear the static refs too
950
- // so a later getInstance()/new starts clean — otherwise getInstance() would
951
- // hand back this now-listener-less instance, and the instance-count warning
952
- // would mis-fire on the next construction.
953
- if (UniversalWalletConnector.instance === this) {
954
- UniversalWalletConnector.resetInstance()
955
- }
956
- }
957
-
958
812
  // ---- private helpers ----
959
813
 
960
- /** Instrument a wallet-boundary op (emits awaitingWallet + a terminal). */
961
- private instrument<T>(
962
- context: HandoffContext,
963
- fn: () => Promise<T>
964
- ): Promise<T> {
965
- return instrumentHandoff(
966
- {
967
- eventManager: this.eventManager,
968
- timeoutMs: this.walletResponseTimeoutMs
969
- },
970
- context,
971
- fn
972
- )
973
- }
974
-
975
- /** Build handoff routing facets from the active session (no address). */
976
- private sessionHandoffContext(
977
- operation: UWCOperation,
978
- session: Session
979
- ): HandoffContext {
980
- return {
981
- operation,
982
- connectionMode: session.connectionMode ?? 'injected',
983
- walletId: session.activeWallet?.id,
984
- namespace: session.activeNetwork?.namespace,
985
- chainId: session.activeNetwork?.id ?? undefined
986
- }
987
- }
988
-
989
814
  private emitError(error: unknown, operation: UWCOperation): void {
990
815
  // Intentional cancellations (AbortSignal.throwIfAborted, fetch abort,
991
816
  // DOMException) should NOT surface as wallet errors — the caller already
992
- // knows it asked to abort. Uses the same name-based check as
993
- // `instrumentHandoff` so a DOMException abort (not an `Error` subclass in
994
- // every runtime) is skipped consistently on both paths.
995
- if (isAbortError(error)) {
817
+ // knows it asked to abort. Skip emission so error telemetry stays clean.
818
+ if (error instanceof Error && error.name === 'AbortError') {
996
819
  return
997
820
  }
998
- this.eventManager.emit('error', {
999
- error: toWalletError(error),
1000
- operation
1001
- })
821
+ const walletError: WalletError =
822
+ error instanceof WalletConnectorError
823
+ ? { type: error.type, message: error.message }
824
+ : {
825
+ type: 'unknown',
826
+ message: error instanceof Error ? error.message : String(error)
827
+ }
828
+ this.eventManager.emit('error', { error: walletError, operation })
1002
829
  }
1003
830
  }
@@ -1,32 +0,0 @@
1
- import type { LogLevel, Logger } from '@meshconnect/uwc-types';
2
- /** The logger returned by `createLogger`, with runtime-tunable level controls. */
3
- export interface ManagedLogger extends Logger {
4
- /** Lower/raise the console threshold at runtime (e.g. from a support toggle). */
5
- setLevel(level: LogLevel): void;
6
- /** The currently configured threshold (ignores the global override). */
7
- getLevel(): LogLevel;
8
- }
9
- export interface CreateLoggerOptions {
10
- /** Console threshold. Default `'warn'` — UWC stays quiet unless asked. */
11
- level?: LogLevel | undefined;
12
- /**
13
- * Pre-gate tap: invoked for EVERY log line regardless of the console threshold.
14
- * The observer bridge subscribes here so `debug`/`info` reach remote telemetry
15
- * even when the console is silent. Throws are swallowed — a bad sink must not
16
- * break a log call.
17
- */
18
- onLog?: ((level: LogLevel, message: string, args: unknown[]) => void) | undefined;
19
- /**
20
- * Output sink for gated lines. When provided (e.g. a consumer's own logger), it
21
- * receives the RAW `(message, ...args)` so it can apply its own formatting. When
22
- * omitted, the default `console` sink is used with an ISO/level prefix.
23
- */
24
- sink?: Logger | undefined;
25
- }
26
- /**
27
- * Console-backed, level-gated logger. ~zero-dep. Two seams:
28
- * - `onLog` fires pre-gate (all levels) → drives the observer.
29
- * - the console sink fires only at/above the threshold.
30
- */
31
- export declare function createLogger(options?: CreateLoggerOptions): ManagedLogger;
32
- //# sourceMappingURL=create-logger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-logger.d.ts","sourceRoot":"","sources":["../../src/logger/create-logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAS9D,kFAAkF;AAClF,MAAM,WAAW,aAAc,SAAQ,MAAM;IAC3C,iFAAiF;IACjF,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;IAC/B,wEAAwE;IACxE,QAAQ,IAAI,QAAQ,CAAA;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,0EAA0E;IAC1E,KAAK,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC5B;;;;;OAKG;IACH,KAAK,CAAC,EACF,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC,GAC7D,SAAS,CAAA;IACb;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B;AA2BD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,aAAa,CAiC7E"}
@@ -1,69 +0,0 @@
1
- const LEVEL_WEIGHT = {
2
- debug: 0,
3
- info: 1,
4
- warn: 2,
5
- error: 3
6
- };
7
- /**
8
- * Resolve the effective console threshold, honouring a runtime global override so
9
- * an issue can be triaged in a wallet's in-app browser WITHOUT a redeploy:
10
- *
11
- * window.UWC_DEBUG = true // surface everything (debug)
12
- * window.UWC_DEBUG = 'info' // surface info and above
13
- *
14
- * The override only ever LOWERS the threshold (shows more) — it can't hide logs a
15
- * consumer explicitly opted into. Re-read on every call so toggling it mid-session
16
- * takes effect immediately. SSR/Node-safe via the `globalThis` guard.
17
- */
18
- function resolveWeight(configured) {
19
- if (typeof globalThis !== 'undefined') {
20
- const override = globalThis.UWC_DEBUG;
21
- if (override === true)
22
- return LEVEL_WEIGHT.debug;
23
- if (typeof override === 'string' && override in LEVEL_WEIGHT) {
24
- return Math.min(LEVEL_WEIGHT[override], LEVEL_WEIGHT[configured]);
25
- }
26
- }
27
- return LEVEL_WEIGHT[configured];
28
- }
29
- /**
30
- * Console-backed, level-gated logger. ~zero-dep. Two seams:
31
- * - `onLog` fires pre-gate (all levels) → drives the observer.
32
- * - the console sink fires only at/above the threshold.
33
- */
34
- export function createLogger(options = {}) {
35
- let configured = options.level ?? 'warn';
36
- const customSink = options.sink;
37
- const emit = (level, message, args) => {
38
- // Pre-gate tap first — observability must not depend on the console threshold.
39
- if (options.onLog) {
40
- try {
41
- options.onLog(level, message, args);
42
- }
43
- catch {
44
- // A failing sink must never break the caller's log statement.
45
- }
46
- }
47
- if (LEVEL_WEIGHT[level] < resolveWeight(configured))
48
- return;
49
- if (customSink) {
50
- customSink[level](message, ...args);
51
- }
52
- else {
53
- const line = `[${new Date().toISOString()}] ${level.toUpperCase()}: ${message}`;
54
- // eslint-disable-next-line no-console -- this IS the default console sink
55
- console[level](line, ...args);
56
- }
57
- };
58
- return {
59
- debug: (message, ...args) => emit('debug', message, args),
60
- info: (message, ...args) => emit('info', message, args),
61
- warn: (message, ...args) => emit('warn', message, args),
62
- error: (message, ...args) => emit('error', message, args),
63
- setLevel: level => {
64
- configured = level;
65
- },
66
- getLevel: () => configured
67
- };
68
- }
69
- //# sourceMappingURL=create-logger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-logger.js","sourceRoot":"","sources":["../../src/logger/create-logger.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAA6B;IAC7C,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACT,CAAA;AA8BD;;;;;;;;;;GAUG;AACH,SAAS,aAAa,CAAC,UAAoB;IACzC,IAAI,OAAO,UAAU,KAAK,WAAW,EAAE,CAAC;QACtC,MAAM,QAAQ,GAAI,UAAsC,CAAC,SAAS,CAAA;QAClE,IAAI,QAAQ,KAAK,IAAI;YAAE,OAAO,YAAY,CAAC,KAAK,CAAA;QAChD,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,IAAI,YAAY,EAAE,CAAC;YAC7D,OAAO,IAAI,CAAC,GAAG,CACb,YAAY,CAAC,QAAoB,CAAC,EAClC,YAAY,CAAC,UAAU,CAAC,CACzB,CAAA;QACH,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAC,UAAU,CAAC,CAAA;AACjC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,UAA+B,EAAE;IAC5D,IAAI,UAAU,GAAa,OAAO,CAAC,KAAK,IAAI,MAAM,CAAA;IAClD,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAA;IAE/B,MAAM,IAAI,GAAG,CAAC,KAAe,EAAE,OAAe,EAAE,IAAe,EAAQ,EAAE;QACvE,+EAA+E;QAC/E,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;YAClB,IAAI,CAAC;gBACH,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;YACrC,CAAC;YAAC,MAAM,CAAC;gBACP,8DAA8D;YAChE,CAAC;QACH,CAAC;QACD,IAAI,YAAY,CAAC,KAAK,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC;YAAE,OAAM;QAC3D,IAAI,UAAU,EAAE,CAAC;YACf,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAA;QACrC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,WAAW,EAAE,KAAK,OAAO,EAAE,CAAA;YAC/E,0EAA0E;YAC1E,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAA;QAC/B,CAAC;IACH,CAAC,CAAA;IAED,OAAO;QACL,KAAK,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;QACzD,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;QACvD,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;QACvD,KAAK,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;QACzD,QAAQ,EAAE,KAAK,CAAC,EAAE;YAChB,UAAU,GAAG,KAAK,CAAA;QACpB,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE,CAAC,UAAU;KAC3B,CAAA;AACH,CAAC"}
@@ -1,22 +0,0 @@
1
- import type { EventManager } from '../managers/event-manager';
2
- import { type UWCObserver } from './telemetry';
3
- /**
4
- * Bridge the internal event bus to a consumer-supplied `UWCObserver`.
5
- *
6
- * Subscribes to every `UWCEventMap` event, normalizes each to a PII-safe
7
- * `UWCTelemetryEvent`, and forwards it to `observer.onEvent`. The `log` event is
8
- * routed to `observer.onLog` instead (with scrubbed args) — it's the logging
9
- * channel, not a telemetry record. `change` is skipped: it's the legacy
10
- * re-render cascade and carries no payload.
11
- *
12
- * Returns a teardown function that removes every subscription. The caller MUST
13
- * invoke it on connector teardown — leaving these attached is the same listener-
14
- * leak class as the historical `BridgeParent.destroy()` zombie bug.
15
- *
16
- * @param getCorrelationId - resolves the correlation id stamped on every event,
17
- * called per-event so a consumer-supplied id that arrives/changes after
18
- * construction is honoured. Must not throw (the caller pre-wraps it).
19
- * @param now - clock injectable for deterministic tests; defaults to `Date.now`.
20
- */
21
- export declare function connectObserver(eventManager: EventManager, observer: UWCObserver, getCorrelationId: () => string, now?: () => number): () => void;
22
- //# sourceMappingURL=connect-observer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connect-observer.d.ts","sourceRoot":"","sources":["../../src/observability/connect-observer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAG7D,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAG9D;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,WAAW,EACrB,gBAAgB,EAAE,MAAM,MAAM,EAC9B,GAAG,GAAE,MAAM,MAAiB,GAC3B,MAAM,IAAI,CAyCZ"}
@@ -1,60 +0,0 @@
1
- import { UWC_EVENT_NAMES } from '../events';
2
- import { normalizeEvent } from './telemetry';
3
- import { scrubArgs } from './scrub';
4
- /**
5
- * Bridge the internal event bus to a consumer-supplied `UWCObserver`.
6
- *
7
- * Subscribes to every `UWCEventMap` event, normalizes each to a PII-safe
8
- * `UWCTelemetryEvent`, and forwards it to `observer.onEvent`. The `log` event is
9
- * routed to `observer.onLog` instead (with scrubbed args) — it's the logging
10
- * channel, not a telemetry record. `change` is skipped: it's the legacy
11
- * re-render cascade and carries no payload.
12
- *
13
- * Returns a teardown function that removes every subscription. The caller MUST
14
- * invoke it on connector teardown — leaving these attached is the same listener-
15
- * leak class as the historical `BridgeParent.destroy()` zombie bug.
16
- *
17
- * @param getCorrelationId - resolves the correlation id stamped on every event,
18
- * called per-event so a consumer-supplied id that arrives/changes after
19
- * construction is honoured. Must not throw (the caller pre-wraps it).
20
- * @param now - clock injectable for deterministic tests; defaults to `Date.now`.
21
- */
22
- export function connectObserver(eventManager, observer, getCorrelationId, now = Date.now) {
23
- const unsubscribers = [];
24
- for (const name of UWC_EVENT_NAMES) {
25
- if (name === 'change')
26
- continue;
27
- if (name === 'log') {
28
- unsubscribers.push(eventManager.on('log', data => {
29
- if (!observer.onLog)
30
- return;
31
- const { level, message, args } = data;
32
- try {
33
- observer.onLog(level, message, scrubArgs(args));
34
- }
35
- catch {
36
- // A throwing observer must not break the dispatch chain.
37
- }
38
- }));
39
- continue;
40
- }
41
- unsubscribers.push(eventManager.on(name, data => {
42
- if (!observer.onEvent)
43
- return;
44
- try {
45
- // Normalize OUTSIDE the EventManager's own try/catch (which guards the
46
- // listener, not the work the listener does), then hand off.
47
- observer.onEvent(normalizeEvent(name, data, getCorrelationId(), now()));
48
- }
49
- catch {
50
- // Same: never let a bad observer break other listeners.
51
- }
52
- }));
53
- }
54
- return () => {
55
- for (const unsubscribe of unsubscribers)
56
- unsubscribe();
57
- unsubscribers.length = 0;
58
- };
59
- }
60
- //# sourceMappingURL=connect-observer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connect-observer.js","sourceRoot":"","sources":["../../src/observability/connect-observer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAE3C,OAAO,EAAE,cAAc,EAAoB,MAAM,aAAa,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAEnC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAC7B,YAA0B,EAC1B,QAAqB,EACrB,gBAA8B,EAC9B,MAAoB,IAAI,CAAC,GAAG;IAE5B,MAAM,aAAa,GAAsB,EAAE,CAAA;IAE3C,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;QACnC,IAAI,IAAI,KAAK,QAAQ;YAAE,SAAQ;QAE/B,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;YACnB,aAAa,CAAC,IAAI,CAChB,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE;gBAC5B,IAAI,CAAC,QAAQ,CAAC,KAAK;oBAAE,OAAM;gBAC3B,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,IAA0B,CAAA;gBAC3D,IAAI,CAAC;oBACH,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;gBACjD,CAAC;gBAAC,MAAM,CAAC;oBACP,yDAAyD;gBAC3D,CAAC;YACH,CAAC,CAAC,CACH,CAAA;YACD,SAAQ;QACV,CAAC;QAED,aAAa,CAAC,IAAI,CAChB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;YAC3B,IAAI,CAAC,QAAQ,CAAC,OAAO;gBAAE,OAAM;YAC7B,IAAI,CAAC;gBACH,uEAAuE;gBACvE,4DAA4D;gBAC5D,QAAQ,CAAC,OAAO,CACd,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,gBAAgB,EAAE,EAAE,GAAG,EAAE,CAAC,CACtD,CAAA;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,wDAAwD;YAC1D,CAAC;QACH,CAAC,CAAC,CACH,CAAA;IACH,CAAC;IAED,OAAO,GAAG,EAAE;QACV,KAAK,MAAM,WAAW,IAAI,aAAa;YAAE,WAAW,EAAE,CAAA;QACtD,aAAa,CAAC,MAAM,GAAG,CAAC,CAAA;IAC1B,CAAC,CAAA;AACH,CAAC"}