@launchdarkly/toolbar 0.15.0-beta.1 → 0.16.0-beta.1
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 +31 -5
- package/dist/hooks/EventStore.d.ts +6 -0
- package/dist/js/index.js +10 -3
- package/dist/js/plugins/index.js +10 -3
- package/dist/plugins/EventInterceptionPlugin.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,10 +27,11 @@ pnpm add @launchdarkly/toolbar@next
|
|
|
27
27
|
```tsx
|
|
28
28
|
import { useEffect, useState } from 'react';
|
|
29
29
|
import { asyncWithLDProvider } from 'launchdarkly-react-client-sdk';
|
|
30
|
-
import { LaunchDarklyToolbar, FlagOverridePlugin } from '@launchdarkly/toolbar';
|
|
30
|
+
import { LaunchDarklyToolbar, FlagOverridePlugin, EventInterceptionPlugin } from '@launchdarkly/toolbar';
|
|
31
31
|
|
|
32
|
-
// Create the plugin
|
|
32
|
+
// Create the plugin instances
|
|
33
33
|
const flagOverridePlugin = new FlagOverridePlugin();
|
|
34
|
+
const eventInterceptionPlugin = new EventInterceptionPlugin();
|
|
34
35
|
|
|
35
36
|
function App() {
|
|
36
37
|
const [LDProvider, setLDProvider] = useState(null);
|
|
@@ -41,8 +42,8 @@ function App() {
|
|
|
41
42
|
clientSideID: 'your-client-side-id',
|
|
42
43
|
context: { key: 'user-key', name: 'User Name' },
|
|
43
44
|
options: {
|
|
44
|
-
// Pass the
|
|
45
|
-
plugins: [flagOverridePlugin],
|
|
45
|
+
// Pass the plugins to the SDK
|
|
46
|
+
plugins: [flagOverridePlugin, eventInterceptionPlugin],
|
|
46
47
|
},
|
|
47
48
|
});
|
|
48
49
|
setLDProvider(() => Provider);
|
|
@@ -59,7 +60,7 @@ function App() {
|
|
|
59
60
|
<LDProvider>
|
|
60
61
|
<div>
|
|
61
62
|
<h1>My App</h1>
|
|
62
|
-
{/* Pass the same plugin
|
|
63
|
+
{/* Pass the same plugin instances to the toolbar */}
|
|
63
64
|
<LaunchDarklyToolbar
|
|
64
65
|
flagOverridePlugin={flagOverridePlugin}
|
|
65
66
|
eventInterceptionPlugin={eventInterceptionPlugin}
|
|
@@ -169,6 +170,31 @@ function App() {
|
|
|
169
170
|
}
|
|
170
171
|
```
|
|
171
172
|
|
|
173
|
+
#### Event Interception Plugin
|
|
174
|
+
|
|
175
|
+
To track and display LaunchDarkly events (flag evaluations, custom events, etc.), add the `EventInterceptionPlugin`:
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
import { EventInterceptionPlugin } from '@launchdarkly/toolbar';
|
|
179
|
+
|
|
180
|
+
// Create plugin with optional configuration
|
|
181
|
+
const eventInterceptionPlugin = new EventInterceptionPlugin({
|
|
182
|
+
eventCapacity: 250, // Maximum events to store (default: 100)
|
|
183
|
+
enableLogging: true, // Console logging for debugging (default: false)
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// Add to both SDK and toolbar
|
|
187
|
+
const Provider = await asyncWithLDProvider({
|
|
188
|
+
// ... other config
|
|
189
|
+
options: {
|
|
190
|
+
plugins: [flagOverridePlugin, eventInterceptionPlugin],
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// Pass to toolbar
|
|
195
|
+
<LaunchDarklyToolbar flagOverridePlugin={flagOverridePlugin} eventInterceptionPlugin={eventInterceptionPlugin} />;
|
|
196
|
+
```
|
|
197
|
+
|
|
172
198
|
### Dev Server Mode
|
|
173
199
|
|
|
174
200
|
For teams using the LaunchDarkly CLI dev server, start it with CORS enabled:
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { ProcessedEvent } from '../types/events';
|
|
2
|
+
export interface EventStoreConfig {
|
|
3
|
+
/** Maximum number of events to store */
|
|
4
|
+
maxEvents?: number;
|
|
5
|
+
}
|
|
2
6
|
export declare class EventStore {
|
|
3
7
|
private events;
|
|
4
8
|
private listeners;
|
|
9
|
+
private maxEvents;
|
|
10
|
+
constructor(config?: EventStoreConfig);
|
|
5
11
|
addEvent(event: ProcessedEvent): void;
|
|
6
12
|
getEvents(): ProcessedEvent[];
|
|
7
13
|
subscribe(listener: () => void): () => void;
|
package/dist/js/index.js
CHANGED
|
@@ -5722,14 +5722,18 @@ class FlagOverridePlugin {
|
|
|
5722
5722
|
}
|
|
5723
5723
|
}
|
|
5724
5724
|
}
|
|
5725
|
-
const
|
|
5725
|
+
const DEFAULT_MAX_EVENTS = 100;
|
|
5726
5726
|
class EventStore {
|
|
5727
5727
|
events = [];
|
|
5728
5728
|
listeners = new Set();
|
|
5729
|
+
maxEvents;
|
|
5730
|
+
constructor(config = {}){
|
|
5731
|
+
this.maxEvents = config.maxEvents ?? DEFAULT_MAX_EVENTS;
|
|
5732
|
+
}
|
|
5729
5733
|
addEvent(event) {
|
|
5730
5734
|
try {
|
|
5731
5735
|
this.events.push(event);
|
|
5732
|
-
if (this.events.length >
|
|
5736
|
+
if (this.events.length > this.maxEvents) this.events.splice(0, this.events.length - this.maxEvents);
|
|
5733
5737
|
this.notifyListeners();
|
|
5734
5738
|
} catch (error) {
|
|
5735
5739
|
console.warn('Event store error:', error);
|
|
@@ -5963,9 +5967,12 @@ class EventInterceptionPlugin {
|
|
|
5963
5967
|
constructor(config = {}){
|
|
5964
5968
|
this.config = {
|
|
5965
5969
|
enableLogging: false,
|
|
5970
|
+
eventCapacity: 100,
|
|
5966
5971
|
...config
|
|
5967
5972
|
};
|
|
5968
|
-
this.eventStore = new EventStore(
|
|
5973
|
+
this.eventStore = new EventStore({
|
|
5974
|
+
maxEvents: this.config.eventCapacity
|
|
5975
|
+
});
|
|
5969
5976
|
const onNewEvent = (event)=>{
|
|
5970
5977
|
if (this.config.enableLogging) console.log('🎯 Event intercepted:', {
|
|
5971
5978
|
kind: event.kind,
|
package/dist/js/plugins/index.js
CHANGED
|
@@ -130,14 +130,18 @@ class FlagOverridePlugin {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
const
|
|
133
|
+
const DEFAULT_MAX_EVENTS = 100;
|
|
134
134
|
class EventStore {
|
|
135
135
|
events = [];
|
|
136
136
|
listeners = new Set();
|
|
137
|
+
maxEvents;
|
|
138
|
+
constructor(config = {}){
|
|
139
|
+
this.maxEvents = config.maxEvents ?? DEFAULT_MAX_EVENTS;
|
|
140
|
+
}
|
|
137
141
|
addEvent(event) {
|
|
138
142
|
try {
|
|
139
143
|
this.events.push(event);
|
|
140
|
-
if (this.events.length >
|
|
144
|
+
if (this.events.length > this.maxEvents) this.events.splice(0, this.events.length - this.maxEvents);
|
|
141
145
|
this.notifyListeners();
|
|
142
146
|
} catch (error) {
|
|
143
147
|
console.warn('Event store error:', error);
|
|
@@ -371,9 +375,12 @@ class EventInterceptionPlugin {
|
|
|
371
375
|
constructor(config = {}){
|
|
372
376
|
this.config = {
|
|
373
377
|
enableLogging: false,
|
|
378
|
+
eventCapacity: 100,
|
|
374
379
|
...config
|
|
375
380
|
};
|
|
376
|
-
this.eventStore = new EventStore(
|
|
381
|
+
this.eventStore = new EventStore({
|
|
382
|
+
maxEvents: this.config.eventCapacity
|
|
383
|
+
});
|
|
377
384
|
const onNewEvent = (event)=>{
|
|
378
385
|
if (this.config.enableLogging) console.log('🎯 Event intercepted:', {
|
|
379
386
|
kind: event.kind,
|
|
@@ -9,6 +9,8 @@ export interface EventInterceptionPluginConfig {
|
|
|
9
9
|
filter?: EventFilter;
|
|
10
10
|
/** Enable console logging for debugging */
|
|
11
11
|
enableLogging?: boolean;
|
|
12
|
+
/** Maximum number of events to store. The default value is 100. */
|
|
13
|
+
eventCapacity?: number;
|
|
12
14
|
}
|
|
13
15
|
/**
|
|
14
16
|
* Plugin dedicated to intercepting and processing LaunchDarkly events
|
package/package.json
CHANGED