@refraction-ui/react 0.7.0 → 0.9.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.
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @refraction-ui/analytics-sink-posthog/replay
3
+ *
4
+ * OPTIONAL, lazy session-replay (rrweb, via `posthog-js`).
5
+ *
6
+ * Hard guarantees this module exists to enforce:
7
+ *
8
+ * 1. **Off by default.** Nothing in the main `@refraction-ui/analytics-sink-posthog`
9
+ * entry imports this file, so it (and `posthog-js`, and rrweb) are fully
10
+ * tree-shaken out of any bundle that does not explicitly import it.
11
+ * 2. **Never on the event path.** Replay is not an `AnalyticsSink`. It does
12
+ * not see, transform, or block canonical envelopes. `track`/`identify`/…
13
+ * keep flowing through the sink even if replay never starts or fails.
14
+ * 3. **Privacy/consent gated.** `startSessionReplay` refuses to start unless
15
+ * a consent predicate returns true, and re-checks it; `stop()` tears the
16
+ * recorder down. Masking defaults are maximally private.
17
+ * 4. **Lazy.** `posthog-js` is `import()`-ed only when `startSessionReplay`
18
+ * is actually called.
19
+ *
20
+ * This is a thin controller around `posthog-js`'s built-in rrweb session
21
+ * recording — we do not bundle rrweb ourselves.
22
+ */
23
+ /** Minimal structural view of the `posthog-js` replay surface. */
24
+ interface PostHogReplay {
25
+ init(apiKey: string, options: Record<string, unknown>): void;
26
+ startSessionRecording(): void;
27
+ stopSessionRecording(): void;
28
+ sessionRecordingStarted?(): boolean;
29
+ }
30
+ interface SessionReplayOptions {
31
+ /** PostHog project API key. */
32
+ apiKey: string;
33
+ /** PostHog API host. Default `https://us.i.posthog.com`. */
34
+ host?: string;
35
+ /**
36
+ * Consent predicate. Replay starts ONLY when this returns `true`, and is
37
+ * re-checked by `enforceConsent()`. There is no default-allow: if omitted,
38
+ * replay is treated as NOT consented and will not start.
39
+ */
40
+ hasConsent?: () => boolean;
41
+ /**
42
+ * rrweb masking. Defaults are maximally private: all text + all inputs
43
+ * masked. Override deliberately and document the privacy review.
44
+ */
45
+ maskAllText?: boolean;
46
+ maskAllInputs?: boolean;
47
+ /** Extra `posthog-js` session_recording options (advanced). */
48
+ recordingOptions?: Record<string, unknown>;
49
+ /**
50
+ * Injected loader (testing / custom bundling). Defaults to a lazy
51
+ * `import('posthog-js')`.
52
+ */
53
+ loadPostHog?: () => Promise<{
54
+ default: PostHogReplay;
55
+ } | PostHogReplay>;
56
+ }
57
+ /** Handle returned by {@link startSessionReplay}. */
58
+ interface SessionReplayHandle {
59
+ /** True if the rrweb recorder is currently running. */
60
+ readonly recording: boolean;
61
+ /**
62
+ * Re-evaluate the consent predicate. If consent was revoked, recording is
63
+ * stopped. Call this from your consent-change handler.
64
+ */
65
+ enforceConsent(): void;
66
+ /** Stop recording and release the recorder. Idempotent. */
67
+ stop(): void;
68
+ }
69
+ /**
70
+ * Start PostHog/rrweb session replay. Resolves to a handle, or to a
71
+ * non-recording handle if consent is not granted (it never throws on the
72
+ * consent path — replay simply does not start).
73
+ *
74
+ * `posthog-js` is dynamically imported here and nowhere else.
75
+ */
76
+ declare function startSessionReplay(options: SessionReplayOptions): Promise<SessionReplayHandle>;
77
+
78
+ export { type SessionReplayHandle, type SessionReplayOptions, startSessionReplay };
@@ -1,6 +1,10 @@
1
1
  import * as React from 'react';
2
2
  import { Analytics, AnalyticsContext, AnalyticsProperties, CallOptions } from '../analytics/index.cjs';
3
3
  export { Analytics, AnalyticsConfig, AnalyticsContext, AnalyticsEvent, AnalyticsEventType, AnalyticsProperties, AnalyticsSink, CallOptions, createAnalytics } from '../analytics/index.cjs';
4
+ export { ConsentState, GA4ClientSdkOptions, GA4ConsentBridge, GA4HttpOptions, GA4SinkOptions, GtagFn, createGA4ClientSdkSink, createGA4HttpSink, createGA4Sink } from '../analytics-sink-ga4/index.cjs';
5
+ export { AppInsightsLike, AppInsightsSinkMode, AppInsightsSinkOptions, ClientSdkOptions, HttpOptions, createAppInsightsSink } from '../analytics-sink-app-insights/index.cjs';
6
+ export { PostHogClientSdkSinkOptions, PostHogHttpSinkOptions, PostHogSinkMode, PostHogSinkOptions, createPostHogClientSdkSink, createPostHogHttpSink, createPostHogSink } from '../analytics-sink-posthog/index.cjs';
7
+ export { SessionReplayHandle, SessionReplayOptions, startSessionReplay } from '../analytics-sink-posthog/replay.cjs';
4
8
 
5
9
  interface AnalyticsProviderProps {
6
10
  children: React.ReactNode;
@@ -1,6 +1,10 @@
1
1
  import * as React from 'react';
2
2
  import { Analytics, AnalyticsContext, AnalyticsProperties, CallOptions } from '../analytics/index.js';
3
3
  export { Analytics, AnalyticsConfig, AnalyticsContext, AnalyticsEvent, AnalyticsEventType, AnalyticsProperties, AnalyticsSink, CallOptions, createAnalytics } from '../analytics/index.js';
4
+ export { ConsentState, GA4ClientSdkOptions, GA4ConsentBridge, GA4HttpOptions, GA4SinkOptions, GtagFn, createGA4ClientSdkSink, createGA4HttpSink, createGA4Sink } from '../analytics-sink-ga4/index.js';
5
+ export { AppInsightsLike, AppInsightsSinkMode, AppInsightsSinkOptions, ClientSdkOptions, HttpOptions, createAppInsightsSink } from '../analytics-sink-app-insights/index.js';
6
+ export { PostHogClientSdkSinkOptions, PostHogHttpSinkOptions, PostHogSinkMode, PostHogSinkOptions, createPostHogClientSdkSink, createPostHogHttpSink, createPostHogSink } from '../analytics-sink-posthog/index.js';
7
+ export { SessionReplayHandle, SessionReplayOptions, startSessionReplay } from '../analytics-sink-posthog/replay.js';
4
8
 
5
9
  interface AnalyticsProviderProps {
6
10
  children: React.ReactNode;
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { Telemetry, TelemetryConfig, LogContext, Logger, Span } from '../logger/index.cjs';
3
- export { LogContext, LogLevel, LogRecord, Logger, Span, SpanRecord, Telemetry, TelemetryConfig, TelemetryEnv, TelemetrySink } from '../logger/index.cjs';
3
+ export { LogContext, LogLevel, LogRecord, Logger, Span, SpanRecord, Telemetry, TelemetryConfig, TelemetryEnv, TelemetrySink, createConsoleSink, createFaroSink, createTelemetry } from '../logger/index.cjs';
4
4
 
5
5
  interface TelemetryContextValue {
6
6
  /** The root telemetry instance (a logger bound to the empty root context). */
@@ -21,7 +21,11 @@ interface TelemetryProviderProps extends TelemetryConfig {
21
21
  declare function TelemetryProvider({ children, ...config }: TelemetryProviderProps): React.FunctionComponentElement<React.ProviderProps<TelemetryContextValue | null>>;
22
22
  /**
23
23
  * useTelemetry — access the root telemetry instance.
24
- * Must be used within <TelemetryProvider>.
24
+ *
25
+ * If called outside a <TelemetryProvider> it does NOT throw: it returns a
26
+ * shared no-op telemetry (a dev-only warn-once hint is emitted so the missing
27
+ * provider is discoverable). This lets components instrumented with
28
+ * useLogger/useSpan/useTelemetry render safely without a provider.
25
29
  */
26
30
  declare function useTelemetry(): Telemetry;
27
31
  /**
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { Telemetry, TelemetryConfig, LogContext, Logger, Span } from '../logger/index.js';
3
- export { LogContext, LogLevel, LogRecord, Logger, Span, SpanRecord, Telemetry, TelemetryConfig, TelemetryEnv, TelemetrySink } from '../logger/index.js';
3
+ export { LogContext, LogLevel, LogRecord, Logger, Span, SpanRecord, Telemetry, TelemetryConfig, TelemetryEnv, TelemetrySink, createConsoleSink, createFaroSink, createTelemetry } from '../logger/index.js';
4
4
 
5
5
  interface TelemetryContextValue {
6
6
  /** The root telemetry instance (a logger bound to the empty root context). */
@@ -21,7 +21,11 @@ interface TelemetryProviderProps extends TelemetryConfig {
21
21
  declare function TelemetryProvider({ children, ...config }: TelemetryProviderProps): React.FunctionComponentElement<React.ProviderProps<TelemetryContextValue | null>>;
22
22
  /**
23
23
  * useTelemetry — access the root telemetry instance.
24
- * Must be used within <TelemetryProvider>.
24
+ *
25
+ * If called outside a <TelemetryProvider> it does NOT throw: it returns a
26
+ * shared no-op telemetry (a dev-only warn-once hint is emitted so the missing
27
+ * provider is discoverable). This lets components instrumented with
28
+ * useLogger/useSpan/useTelemetry render safely without a provider.
25
29
  */
26
30
  declare function useTelemetry(): Telemetry;
27
31
  /**