@junctionjs/debug 0.1.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 +49 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.js +1200 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# @junctionjs/debug
|
|
2
|
+
|
|
3
|
+
In-page debug panel for Junction. Real-time visibility into event flow, consent state, and destination status.
|
|
4
|
+
|
|
5
|
+
Zero dependencies. Vanilla DOM in a shadow root. Toggles with a keyboard shortcut.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Events tab** — real-time event stream with syntax-highlighted payload expansion, text filtering, color-coded badges
|
|
10
|
+
- **Consent tab** — visual consent state per category with click-to-toggle for testing
|
|
11
|
+
- **Destinations tab** — registered destinations with traffic-light status and per-destination send/error counts
|
|
12
|
+
- **Context tab** — live snapshot of page info, device, UTM params, session, and user identity
|
|
13
|
+
- Status bar with aggregate counters (valid, invalid, sent)
|
|
14
|
+
- Ring buffer retains the last 500 events (configurable)
|
|
15
|
+
- Dark theme, shadow DOM isolated, collapses to a small fab button
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @junctionjs/debug
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { createDebugPanel } from "@junctionjs/debug";
|
|
27
|
+
|
|
28
|
+
// Attach to your collector (e.g., window.jct)
|
|
29
|
+
const panel = createDebugPanel(window.jct, {
|
|
30
|
+
shortcut: "ctrl+shift+j", // keyboard toggle
|
|
31
|
+
position: "bottom-right",
|
|
32
|
+
startOpen: false,
|
|
33
|
+
maxEvents: 500,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Programmatic control
|
|
37
|
+
panel.open();
|
|
38
|
+
panel.close();
|
|
39
|
+
panel.toggle();
|
|
40
|
+
panel.destroy();
|
|
41
|
+
|
|
42
|
+
// Access the event store directly
|
|
43
|
+
const entries = panel.store.getEntries();
|
|
44
|
+
const counters = panel.store.getCounters();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { CollectorEvent, Collector } from '@junctionjs/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @junctionjs/debug - Event Store
|
|
5
|
+
*
|
|
6
|
+
* Ring buffer that captures all collector events for the debug panel.
|
|
7
|
+
* Subscribes to the collector's event system and maintains an in-memory
|
|
8
|
+
* log with aggregate counters.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface DebugEntry {
|
|
12
|
+
/** Auto-incrementing ID */
|
|
13
|
+
id: number;
|
|
14
|
+
/** ISO timestamp from the collector event */
|
|
15
|
+
timestamp: string;
|
|
16
|
+
/** Collector event type */
|
|
17
|
+
type: CollectorEvent;
|
|
18
|
+
/** Raw payload from the event */
|
|
19
|
+
payload: unknown;
|
|
20
|
+
}
|
|
21
|
+
interface DebugCounters {
|
|
22
|
+
total: number;
|
|
23
|
+
valid: number;
|
|
24
|
+
invalid: number;
|
|
25
|
+
sent: Record<string, number>;
|
|
26
|
+
errors: Record<string, number>;
|
|
27
|
+
consentChanges: number;
|
|
28
|
+
queueFlushes: number;
|
|
29
|
+
}
|
|
30
|
+
interface DebugStore {
|
|
31
|
+
/** Get all stored entries (newest last) */
|
|
32
|
+
getEntries: () => DebugEntry[];
|
|
33
|
+
/** Get entries filtered by type */
|
|
34
|
+
getByType: (type: CollectorEvent) => DebugEntry[];
|
|
35
|
+
/** Get aggregate counters */
|
|
36
|
+
getCounters: () => DebugCounters;
|
|
37
|
+
/** Clear all entries and reset counters */
|
|
38
|
+
clear: () => void;
|
|
39
|
+
/** Subscribe to updates (called on every new entry) */
|
|
40
|
+
onUpdate: (callback: () => void) => () => void;
|
|
41
|
+
/** Unsubscribe from all collector events and clean up */
|
|
42
|
+
destroy: () => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @junctionjs/debug - Panel
|
|
47
|
+
*
|
|
48
|
+
* DOM construction for the debug overlay. All rendering uses vanilla DOM
|
|
49
|
+
* inside a shadow root for complete style isolation.
|
|
50
|
+
*
|
|
51
|
+
* 4 tabs: Events | Consent | Destinations | Context
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
type PanelPosition = "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @junctionjs/debug
|
|
58
|
+
*
|
|
59
|
+
* In-page debug overlay for Junction. Shows real-time event flow,
|
|
60
|
+
* consent state, destination status, and context snapshot.
|
|
61
|
+
*
|
|
62
|
+
* Zero dependencies. Vanilla DOM in a shadow root. ~5KB gzipped.
|
|
63
|
+
*
|
|
64
|
+
* Usage:
|
|
65
|
+
* import { createDebugPanel } from "@junctionjs/debug";
|
|
66
|
+
*
|
|
67
|
+
* const panel = createDebugPanel(window.jct, {
|
|
68
|
+
* shortcut: "ctrl+shift+j",
|
|
69
|
+
* startOpen: false,
|
|
70
|
+
* position: "bottom-right",
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* // Or for Astro integration:
|
|
74
|
+
* // The panel auto-injects when debug: true in your junction config.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
interface DebugPanelOptions {
|
|
78
|
+
/**
|
|
79
|
+
* Keyboard shortcut to toggle the panel (default: "ctrl+shift+j").
|
|
80
|
+
* Format: modifier keys joined with "+" followed by a key.
|
|
81
|
+
* Examples: "ctrl+shift+j", "meta+shift+d", "ctrl+shift+."
|
|
82
|
+
*/
|
|
83
|
+
shortcut?: string;
|
|
84
|
+
/** Maximum events to retain in the ring buffer (default: 500) */
|
|
85
|
+
maxEvents?: number;
|
|
86
|
+
/** Start with the panel open (default: false) */
|
|
87
|
+
startOpen?: boolean;
|
|
88
|
+
/** Panel position on screen (default: "bottom-right") */
|
|
89
|
+
position?: PanelPosition;
|
|
90
|
+
}
|
|
91
|
+
interface DebugPanelInstance {
|
|
92
|
+
/** Open the debug panel */
|
|
93
|
+
open: () => void;
|
|
94
|
+
/** Close the debug panel */
|
|
95
|
+
close: () => void;
|
|
96
|
+
/** Toggle open/close */
|
|
97
|
+
toggle: () => void;
|
|
98
|
+
/** Remove the panel from the DOM and unsubscribe from all events */
|
|
99
|
+
destroy: () => void;
|
|
100
|
+
/** Access the underlying event store (for programmatic use) */
|
|
101
|
+
store: DebugStore;
|
|
102
|
+
}
|
|
103
|
+
declare function createDebugPanel(collector: Collector, options?: DebugPanelOptions): DebugPanelInstance;
|
|
104
|
+
|
|
105
|
+
export { type DebugCounters, type DebugEntry, type DebugPanelInstance, type DebugPanelOptions, type DebugStore, type PanelPosition, createDebugPanel };
|