@unblind/react 0.1.0-alpha.9 → 0.1.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/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { QueryClient, QueryClientConfig } from '@tanstack/react-query';
3
3
  import React$1, { ReactNode } from 'react';
4
4
  import { StringValue } from 'ms';
5
- import uPlot from 'uplot';
5
+ import uPlot$1 from 'uplot';
6
6
 
7
7
  type UnblindClientConfig = {
8
8
  /**
@@ -50,7 +50,7 @@ type UnblindClientProviderProps = {
50
50
  * return (
51
51
  * <>
52
52
  * <button onClick={() => refresh()}>Refresh</button>
53
- * <TimeseriesChart metrics={["cpu"]} />
53
+ * <Timeseries metrics={["cpu"]} />
54
54
  * </>
55
55
  * );
56
56
  * }
@@ -58,20 +58,14 @@ type UnblindClientProviderProps = {
58
58
  */
59
59
  declare function useRefresh(): () => Promise<void>;
60
60
 
61
- interface TooltipItem {
62
- metric: MetricMetadata;
63
- serie: uPlot.Series;
64
- color: string;
65
- value?: number;
66
- formattedValue?: string;
67
- attributes?: Record<string, string>;
68
- }
69
- type TooltipLayout = "auto" | "group-by-metric" | "flat";
70
- type TooltipFormat = "original" | "suffix" | "title";
71
61
  interface TooltipProps {
72
62
  timestamp: number;
73
- items: TooltipItem[];
63
+ tooltipSerieList: TooltipSerie[];
74
64
  timeZone?: string;
65
+ stacked?: boolean;
66
+ invertSort?: boolean;
67
+ visibilityLimit?: number;
68
+ disableSuggestedLabel?: boolean;
75
69
  }
76
70
 
77
71
  /**
@@ -83,29 +77,21 @@ type MetricType = "gauge" | "sum" | "histogram" | "summary" | "exphistogram";
83
77
  * Aggregation operators available for metric queries.
84
78
  */
85
79
  type AggregationOperator = "avg" | "sum" | "max" | "min" | "p90" | "p99" | "p50";
86
- /**
87
- * Attribute filter with a specific value.
88
- */
89
- interface AttributeWithValue {
90
- name: string;
91
- value: string;
92
- }
93
80
  /**
94
81
  * Metric metadata returned by the API.
95
82
  */
96
83
  interface MetricMetadata {
97
84
  name: string;
98
85
  description: string;
99
- displayName?: string;
86
+ suggestedLabel?: string;
100
87
  unit: {
101
88
  code?: string;
102
- name?: string;
103
- synonym?: string;
104
- category?: string;
105
89
  };
106
90
  type: MetricType;
107
- operator?: AggregationOperator;
108
91
  }
92
+ type LabeledMetricMetadata = MetricMetadata & {
93
+ label?: string;
94
+ };
109
95
  /**
110
96
  * List of metric metadata.
111
97
  */
@@ -117,7 +103,6 @@ interface Serie {
117
103
  metric: string;
118
104
  attributes?: Record<string, string>;
119
105
  values: Array<number>;
120
- queryName?: string;
121
106
  queryIndex: number;
122
107
  isEmpty?: boolean;
123
108
  }
@@ -125,7 +110,6 @@ interface Serie {
125
110
  * Query definition for timeseries requests.
126
111
  */
127
112
  interface TimeseriesQuery {
128
- queryName?: string;
129
113
  metrics: Array<string>;
130
114
  groupBy?: Array<string>;
131
115
  operator?: AggregationOperator;
@@ -143,19 +127,20 @@ type ChartType = "bar" | "line" | "area" | "step" | "spline";
143
127
  type TimeRange = StringValue;
144
128
  interface Log {
145
129
  timestamp: number;
146
- trace_id?: string;
147
- span_id?: string;
148
- severity_text: Severity;
130
+ traceId?: string;
131
+ spanId?: string;
132
+ logId?: string;
133
+ severity: Severity;
149
134
  attributes?: Record<string, string>;
150
- service_name?: string;
151
135
  body?: string;
136
+ serviceName?: string;
152
137
  }
153
138
  /**
154
139
  * Default paginated response structure
155
140
  */
156
141
  type PaginatedResponse<T> = {
157
142
  data: Array<T>;
158
- next_page?: string;
143
+ nextPage?: string;
159
144
  };
160
145
  /**
161
146
  * Different severity values based on OTEL
@@ -217,11 +202,6 @@ interface ChartVisualConfig {
217
202
  * Optional color configuration
218
203
  */
219
204
  colors?: Colors;
220
- /**
221
- * Optional order for rendering results.
222
- * Defaults to false
223
- */
224
- sortByValues?: boolean;
225
205
  /**
226
206
  * Optional to fill charts.
227
207
  *
@@ -232,13 +212,61 @@ interface ChartVisualConfig {
232
212
  * Optional tooltip configuration.
233
213
  */
234
214
  tooltip?: TooltipConfig;
215
+ /**
216
+ * Chart type. Defaults to "line".
217
+ */
218
+ type?: ChartType;
219
+ /**
220
+ * Optional threshold
221
+ */
222
+ thresholds?: Array<Threshold>;
223
+ /**
224
+ * Optional min value
225
+ */
226
+ min?: number;
227
+ /**
228
+ * Optional max value
229
+ */
230
+ max?: number;
231
+ /**
232
+ * Optional boolean to hide both axis
233
+ */
234
+ hideAxis?: boolean;
235
+ /**
236
+ * Optional boolean to hide cursor
237
+ */
238
+ hideCursor?: boolean;
239
+ /**
240
+ * Optional boolean to display relative time axis
241
+ *
242
+ * e.g. a day ago ------ a few seconds ago
243
+ */
244
+ relativeTimeAxis?: boolean;
245
+ /**
246
+ * Unit of measurement for the value.
247
+ *
248
+ * Supports standard unit identifiers:
249
+ * - Data: 'bytes', 'decbytes', 'bits', 'decbits'
250
+ * - Time: 'ms', 's', 'm', 'h', 'd'
251
+ * - Throughput: 'Bps', 'Mbps', 'Gbps'
252
+ * - Percentage: 'percent', 'percentunit'
253
+ * - And many more standard units
254
+ *
255
+ */
256
+ unit?: string;
257
+ /**
258
+ * Optional invert value order.
259
+ * Defaults to false
260
+ */
261
+ invertSort?: boolean;
262
+ /**
263
+ * Disables suggested label
264
+ */
265
+ disableSuggestedLabel?: boolean;
235
266
  }
236
267
  interface TooltipConfig {
237
- layout?: TooltipLayout;
238
- format?: TooltipFormat;
239
- hideAttributeKey?: boolean;
240
- hideAttributes?: boolean;
241
- hideMetric?: boolean;
268
+ hide?: boolean;
269
+ visibilityLimit?: number;
242
270
  }
243
271
  /**
244
272
  * Appearance configuration for Unblind components.
@@ -246,7 +274,7 @@ interface TooltipConfig {
246
274
  * Allows consumers to override internal UI components used for
247
275
  * loading, empty, and error states.
248
276
  *
249
- * Overrides can be provided globally via UnblindScope or
277
+ * Overrides can be provided globally via Scope or
250
278
  * locally per component.
251
279
  *
252
280
  * This API customizes presentation only; component state and data
@@ -259,9 +287,37 @@ type Appearance = {
259
287
  Empty?: React.ComponentType;
260
288
  Tooltip?: React.ComponentType<TooltipProps>;
261
289
  };
262
- } & ChartVisualConfig;
290
+ };
291
+ type ThresholdLevel = "info" | "warning" | "error" | "ok";
292
+ type ThresholdLineType = "line" | "dashed" | "bold";
293
+ type LineThreshold = {
294
+ value: number;
295
+ type?: ThresholdLineType;
296
+ level?: ThresholdLevel;
297
+ label?: string;
298
+ };
299
+ type RangeThreshold = {
300
+ from: number;
301
+ to?: number;
302
+ type?: ThresholdLineType;
303
+ level?: ThresholdLevel;
304
+ label?: string;
305
+ };
306
+ type Threshold = LineThreshold | RangeThreshold;
307
+ interface TooltipSerie {
308
+ metric: LabeledMetricMetadata;
309
+ serie: uPlot.Series;
310
+ color: string;
311
+ value?: number;
312
+ formattedValue?: string;
313
+ attributes?: Record<string, string>;
314
+ }
315
+ interface LabeledMetric {
316
+ name: string;
317
+ label: string;
318
+ }
263
319
 
264
- type UnblindScopeConfig = TimeseriesQueryConfig & {
320
+ type ScopeConfig = TimeseriesQueryConfig & ChartVisualConfig & {
265
321
  /**
266
322
  * Optional appearance configuration for all components
267
323
  * within this scope.
@@ -274,7 +330,7 @@ type UnblindScopeConfig = TimeseriesQueryConfig & {
274
330
  *
275
331
  * @example
276
332
  * ```tsx
277
- * <UnblindScope
333
+ * <Scope
278
334
  * appearance={{
279
335
  * components: {
280
336
  * Loading: CustomLoading,
@@ -283,16 +339,16 @@ type UnblindScopeConfig = TimeseriesQueryConfig & {
283
339
  * }}
284
340
  * >
285
341
  * <App />
286
- * </UnblindScope>
342
+ * </Scope>
287
343
  * ```
288
344
  */
289
345
  appearance?: Appearance;
290
346
  };
291
- type UnblindScopeProps = UnblindScopeConfig & {
347
+ type ScopeProps = ScopeConfig & {
292
348
  children?: React$1.ReactNode;
293
349
  };
294
350
  /**
295
- * UnblindScope provides scoped configuration for all Unblind components (charts, logs, etc).
351
+ * Scope provides scoped configuration for all Unblind components (charts, logs, etc).
296
352
  * This includes default time ranges, intervals, attributes, groupBy, operator, appearance, and colors.
297
353
  *
298
354
  * When nested, child scopes inherit defaults from parent scopes and can override specific values.
@@ -301,26 +357,26 @@ type UnblindScopeProps = UnblindScopeConfig & {
301
357
  *
302
358
  * @example
303
359
  * ```tsx
304
- * import { UnblindScope } from '@unblind/react';
360
+ * import { Scope } from '@unblind/react';
305
361
  *
306
362
  * function App() {
307
363
  * return (
308
- * <UnblindScope
364
+ * <Scope
309
365
  * appearance={{ components: { Loading: CustomLoading } }}
310
366
  * timeRange="24h"
311
367
  * >
312
368
  * // Components here use 24h and CustomLoading
313
369
  *
314
- * <UnblindScope timeRange="1h">
370
+ * <Scope timeRange="1h">
315
371
  * // Components here use 1h but still inherit CustomLoading
316
- * </UnblindScope>
317
- * </UnblindScope>
372
+ * </Scope>
373
+ * </Scope>
318
374
  * );
319
375
  * }
320
376
  * ```
321
377
  */
322
- declare function UnblindScope({ children, timeRange, startTime, endTime, interval, attributes, groupBy, operator, appearance, }: UnblindScopeProps): react_jsx_runtime.JSX.Element;
323
- type UseScopeReturn = TimeseriesQueryConfig & {
378
+ declare function Scope({ children, timeRange, startTime, endTime, interval, attributes, groupBy, operator, appearance, tooltip, colors, fill, hideAxis, hideCursor, relativeTimeAxis, invertSort, disableSuggestedLabel, }: ScopeProps): react_jsx_runtime.JSX.Element;
379
+ type UseScopeReturn = TimeseriesQueryConfig & ChartVisualConfig & {
324
380
  timeRange: TimeRange;
325
381
  appearance: {
326
382
  components: {
@@ -329,14 +385,10 @@ type UseScopeReturn = TimeseriesQueryConfig & {
329
385
  Empty: React$1.ComponentType;
330
386
  Tooltip?: React$1.ComponentType<TooltipProps>;
331
387
  };
332
- colors: Colors;
333
- sortByValues?: boolean;
334
- fill?: boolean;
335
- tooltip?: TooltipConfig;
336
388
  };
337
389
  };
338
390
  /**
339
- * Hook to access the scoped configuration from UnblindScope.
391
+ * Hook to access the scoped configuration from Scope.
340
392
  * Returns all configuration including time range, attributes,
341
393
  * groupBy, operator, colors, and UI components.
342
394
  *
@@ -350,13 +402,13 @@ type UseScopeReturn = TimeseriesQueryConfig & {
350
402
  */
351
403
  declare function useScope(): UseScopeReturn;
352
404
 
353
- type UnblindProviderProps = UnblindClientProviderProps & UnblindScopeProps & {
405
+ type UnblindProviderProps = UnblindClientProviderProps & ScopeProps & {
354
406
  children?: React.ReactNode;
355
407
  };
356
408
  /**
357
409
  * UnblindProvider is required for all Unblind hooks to work.
358
410
  * It sets up both the QueryClientProvider (for React Query) and the Unblind configuration context.
359
- * This is a convenience wrapper around UnblindClientProvider and UnblindScope.
411
+ * This is a convenience wrapper around `UnblindClientProvider` and `Scope`.
360
412
  *
361
413
  * @example
362
414
  * ```tsx
@@ -371,7 +423,7 @@ type UnblindProviderProps = UnblindClientProviderProps & UnblindScopeProps & {
371
423
  * }
372
424
  * ```
373
425
  */
374
- declare function UnblindProvider({ children, queryClient, apiBaseUrl, fetchImpl, timeRange, startTime, endTime, interval, attributes, groupBy, operator, appearance, }: UnblindProviderProps): react_jsx_runtime.JSX.Element;
426
+ declare function UnblindProvider({ children, queryClient, apiBaseUrl, fetchImpl, timeRange, startTime, endTime, interval, attributes, groupBy, operator, appearance, tooltip, colors, fill, hideAxis, hideCursor, relativeTimeAxis, invertSort, disableSuggestedLabel, }: UnblindProviderProps): react_jsx_runtime.JSX.Element;
375
427
 
376
428
  interface UseMetricsReturn {
377
429
  metrics: MetricMetadataList | undefined;
@@ -392,12 +444,13 @@ interface UseTimeseriesParams extends Pick<TimeseriesQueryConfig, "timeRange" |
392
444
  */
393
445
  queries: Array<TimeseriesQuery>;
394
446
  }
447
+ interface UseTimeseriesData {
448
+ series: Serie[];
449
+ times: number[];
450
+ metadata: Record<string, MetricMetadata>;
451
+ }
395
452
  interface UseTimeseriesReturn {
396
- data: {
397
- series: Serie[];
398
- times: number[];
399
- metadata: Record<string, MetricMetadata>;
400
- };
453
+ data: UseTimeseriesData;
401
454
  isLoading: boolean;
402
455
  isFetching: boolean;
403
456
  hasError: boolean;
@@ -409,7 +462,7 @@ interface UseTimeseriesReturn {
409
462
  * @param params - Configuration object with queries, and either timeRange or startTime/endTime, plus optional interval.
410
463
  * @returns Object containing timeseries data, loading states, and error state.
411
464
  */
412
- declare function useTimeseries({ queries, timeRange, startTime, endTime, interval, }: UseTimeseriesParams): UseTimeseriesReturn;
465
+ declare function useTimeseries(params: UseTimeseriesParams): UseTimeseriesReturn;
413
466
 
414
467
  interface Usage {
415
468
  period: {
@@ -437,13 +490,18 @@ interface UseUsageReturn {
437
490
  * @param params - Configuration object with optional timeRange.
438
491
  * @returns Object containing usage data, loading state, and error state.
439
492
  */
440
- declare function useUsage({ timeRange, startTime, endTime, }: UseUsageParams): UseUsageReturn;
493
+ declare function useUsage(params: UseUsageParams): UseUsageReturn;
441
494
 
442
495
  type UseLogsParams = {
443
496
  /**
444
497
  * Array of filters to apply to the logs query.
445
498
  */
446
- filters: Array<AttributeWithValue>;
499
+ attributes?: Record<string, Array<string>>;
500
+ body?: Array<string>;
501
+ severity?: Array<string>;
502
+ traceId?: string;
503
+ spanId?: string;
504
+ logId?: string;
447
505
  } & TimeConfig;
448
506
  interface UseLogsReturn {
449
507
  logs: Array<Log>;
@@ -460,33 +518,30 @@ interface UseLogsReturn {
460
518
  * @param params - Configuration object with timeRange and filters.
461
519
  * @returns Object containing logs data, loading states, and pagination controls.
462
520
  */
463
- declare function useLogs({ timeRange, filters, startTime, endTime, }: UseLogsParams): UseLogsReturn;
464
-
465
- declare function useTheme(): boolean;
521
+ declare function useLogs(props: UseLogsParams): UseLogsReturn;
466
522
 
467
- type TimeseriesChartProps = Exclude<TimeseriesQueryConfig, "startTime" | "endTime" | "timeRange"> & {
523
+ type TimeseriesProps = Exclude<TimeseriesQueryConfig, "startTime" | "endTime" | "timeRange"> & ChartVisualConfig & {
468
524
  /**
469
525
  * Metric name(s) to display in the chart.
470
526
  *
471
- * Optional: a single string name.
472
- */
473
- metrics: Array<string> | string;
474
- /**
475
- * Chart type. Defaults to "line".
476
- */
477
- type?: ChartType;
478
- /**
479
- * Unit of measurement for the value.
527
+ * @example Single metric
528
+ * ```jsx
529
+ * <Timeseries metrics="nodejs.eventloop.p50" />
530
+ * ```
480
531
  *
481
- * Supports standard unit identifiers:
482
- * - Data: 'bytes', 'decbytes', 'bits', 'decbits'
483
- * - Time: 'ms', 's', 'm', 'h', 'd'
484
- * - Throughput: 'Bps', 'Mbps', 'Gbps'
485
- * - Percentage: 'percent', 'percentunit'
486
- * - And many more standard units
532
+ * @example
533
+ * Multiple metrics
534
+ * ```jsx
535
+ * <Timeseries metrics={["nodejs.eventloop.p50", "..."]} />
536
+ * ```
487
537
  *
538
+ * @example
539
+ * Labeled metrics
540
+ * ```jsx
541
+ * <Timeseries metrics={{ name: "nodejs.eventloop.p50", label: "P50" ]} />
542
+ * ```
488
543
  */
489
- unit?: string;
544
+ metrics: Array<LabeledMetric> | Array<string> | string;
490
545
  /**
491
546
  * Optional className for the chart container.
492
547
  */
@@ -495,40 +550,45 @@ type TimeseriesChartProps = Exclude<TimeseriesQueryConfig, "startTime" | "endTim
495
550
  * Optional appearance configuration for this chart
496
551
  */
497
552
  appearance?: Appearance;
553
+ /**
554
+ * Hook to get request data
555
+ */
556
+ onResponse?: (response: UseTimeseriesReturn) => void;
498
557
  };
499
558
  /**
500
- * TimeseriesChart component that displays time series data for the given metrics.
501
- * It uses values from the UnblindProvider for timeRange, attributes, groupBy, and operator
502
- * if not explicitly provided as props.
559
+ * Displays a time series chart.
560
+ * Uses values from <UnblindProvider> or <Scope>
561
+ * when they are not explicitly provided as props.
503
562
  *
504
- * @example Using [UnblindProvider]
563
+ * @example
505
564
  * ```tsx
506
- * <UnblindProvider timeRange="1h">
507
- * <TimeseriesChart metrics={["host.cpu"]} />
508
- * <TimeseriesChart metrics={["host.memory"]} />
509
- * </UnblindProvider>
565
+ * <Timeseries
566
+ * metrics="host.cpu"
567
+ * attributes={{ "host.region": ["us-east-2"] }}
568
+ * groupBy={["host.name"]}
569
+ * />
510
570
  * ```
511
571
  *
512
- * @example Using <UnblindScope>
572
+ * @example Using `<Scope>`
513
573
  * ```tsx
514
- * <UnblindScope timeRange="1h">
515
- * <TimeseriesChart metrics={["host.cpu"]} />
516
- * <TimeseriesChart metrics={["host.memory"]} />
517
- * </UnblindScope>
574
+ * <Scope timeRange="1h">
575
+ * <Timeseries metrics="host.cpu" />
576
+ * <Timeseries metrics="host.memory" />
577
+ * </Scope>
518
578
  * ```
519
579
  */
520
- declare function TimeseriesChart({ metrics, operator: propOperator, attributes: propAttributes, groupBy: propGroupBy, interval: propInterval, type, className, appearance: propAppearance, unit: propUnit, }: TimeseriesChartProps): react_jsx_runtime.JSX.Element;
580
+ declare function Timeseries({ metrics, operator: propOperator, attributes: propAttributes, groupBy: propGroupBy, interval: propInterval, type, className, appearance: propAppearance, tooltip: propTooltip, onResponse, ...chartStyleProps }: TimeseriesProps): react_jsx_runtime.JSX.Element;
521
581
 
522
582
  interface ChartProps extends ChartVisualConfig {
523
583
  times: Array<number>;
524
584
  series: Serie[];
525
- metadata: Record<string, MetricMetadata>;
585
+ metadata: Record<string, LabeledMetricMetadata>;
526
586
  type: ChartType;
587
+ invertSort?: boolean;
527
588
  className?: string;
528
589
  timeZone?: string;
529
- options?: uPlot.Options;
530
- unit?: string;
531
- tooltipAppearance?: React.ComponentType<TooltipProps>;
590
+ options?: uPlot$1.Options;
591
+ tooltipComponent?: React.ComponentType<TooltipProps>;
532
592
  }
533
593
  /**
534
594
  * Renders a chart for time series data
@@ -539,4 +599,4 @@ declare function Empty(): react_jsx_runtime.JSX.Element;
539
599
  declare function Error(): react_jsx_runtime.JSX.Element;
540
600
  declare function Loading(): react_jsx_runtime.JSX.Element;
541
601
 
542
- export { type AggregationOperator, type Appearance, type AttributeWithValue, Chart, type ChartProps, type ChartType, type ChartVisualConfig, type Colors, Empty, Error, type Interval, Loading, type Log, type MetricMetadata, type MetricMetadataList, type MetricType, type PaginatedResponse, type Serie, type Severity, type TimeConfig, type TimeRange, TimeseriesChart, type TimeseriesChartProps, type TimeseriesQuery, type TimeseriesQueryConfig, type TooltipProps, type UnblindClientConfig, UnblindProvider, type UnblindProviderProps, UnblindScope, type UnblindScopeConfig, type UnblindScopeProps, type Usage, type UseLogsParams, type UseLogsReturn, type UseMetricsReturn, type UseScopeReturn, type UseTimeseriesParams, type UseTimeseriesReturn, type UseUsageParams, type UseUsageReturn, useLogs, useMetrics, useRefresh, useScope, useTheme, useTimeseries, useUsage };
602
+ export { type AggregationOperator, type Appearance, Chart, type ChartProps, type ChartType, type ChartVisualConfig, type Colors, Empty, Error, type Interval, Loading, type Log, type MetricMetadata, type MetricMetadataList, type MetricType, type PaginatedResponse, Scope, type ScopeConfig, type ScopeProps, type Serie, type Severity, type TimeConfig, type TimeRange, Timeseries, type TimeseriesProps, type TimeseriesQuery, type TimeseriesQueryConfig, type TooltipProps, type UnblindClientConfig, UnblindProvider, type UnblindProviderProps, type Usage, type UseLogsParams, type UseLogsReturn, type UseMetricsReturn, type UseScopeReturn, type UseTimeseriesParams, type UseTimeseriesReturn, type UseUsageParams, type UseUsageReturn, useLogs, useMetrics, useRefresh, useScope, useTimeseries, useUsage };