UNPKG

@embrace-io/web-sdk

Version:
145 lines 6.66 kB
import { ExtendedSpan } from "../../api-traces/api/TraceAPI/types.cjs"; import "../../index.cjs"; import { PropertyOptions, SessionPartStartedEvent } from "../../api-sessions/manager/types.cjs"; import { EmbraceUserSessionManagerArgs, EndSessionPartOptions, RolloverSessionPartOptions, StartSessionPartOptions, UserSessionAttributes, UserSessionManagerInternal } from "./types.cjs"; import { TracerProvider } from "@opentelemetry/api"; //#region src/managers/EmbraceUserSessionManager/EmbraceUserSessionManager.d.ts /** * Parts are engagement-gated (visible AND focused), so only one part can * be active at a time. Engagement exclusivity lets us treat storage as * a plain shared row read on engagement and written on changes. */ declare class EmbraceUserSessionManager implements UserSessionManagerInternal { private _state; private _previousUserSessionId; private _maxDurationTimeout; private _permanentProperties; private _hasStoredState; private _activeSessionPartId; private _currentSessionPartNumber; private _sessionPartSpan; private _activeSessionPartCounts; private _coldStart; private _nextSessionPartCounts; private _sdkStartupDuration; private readonly _sessionPartStartedListeners; private readonly _sessionPartEndedListeners; private _tracer; private readonly _diag; private readonly _perf; private readonly _storage; private readonly _visibilityDoc; private readonly _limitManager; private readonly _dynamicConfigManager; private readonly _target; private readonly _activityEvents; private readonly _onActivityThrottled; private _sessionPartInactivityTimer; constructor({ dynamicConfigManager, diag: diagParam, perf, visibilityDoc, storage, limitManager, target, activityThrottleMs, activityEvents }: EmbraceUserSessionManagerArgs); /** * Reads the user-session durations from remote config, clamps each to its * allowed range, and enforces inactivity <= max duration. Called once per * user-session creation; the resolved values are frozen into that session's * state. */ private _resolveUserSessionDurations; setTracerProvider(tracerProvider: TracerProvider): void; recordSDKStartupDuration(duration: number): void; getUserSessionId(): string | null; getPreviousUserSessionId(): string | null; getUserSessionStartTime(): number | null; getUserSessionAttributes(): UserSessionAttributes | null; endUserSession(): void; getSessionPartId(): string | null; getSessionPartSpan(): ExtendedSpan | null; startSessionPartInternal({ reason, timestamp }: StartSessionPartOptions): void; endSessionPartInternal({ reason, userSessionEndReason, timestamp }: EndSessionPartOptions): void; addBreadcrumb(name: string): void; addProperty(propertyKey: string, value: string, options?: PropertyOptions): void; removeProperty(propertyKey: string): void; /** * Bare-keyed view of properties for the active part. User-session-scoped * entries shadow permanent ones, matching the cross-scope flip rule * enforced in `addProperty`. Callers apply the wire-format prefix at * stamp time. */ getSessionPartProperties(): Record<string, string>; incrSessionPartCountForKey(key: string): void; incrNextSessionPartCountForKey(key: string): void; addSessionPartStartedListener(listener: (event: SessionPartStartedEvent) => void): () => void; addSessionPartEndedListener(listener: () => void): () => void; getSessionId(): string | null; getPreviousSessionId(): null; getSessionStartTime(): number | null; endSessionSpan(): void; startSessionSpan(): void; getSessionSpan(): ExtendedSpan | null; currentSessionAsReadableSpan(): null; addSessionStartedListener(_listener: () => void): () => void; addSessionEndedListener(_listener: () => void): () => void; /** * Returns the persisted user-session state, rotating to a fresh one if * the persisted row is missing or expired. Arms the max-duration timer * when needed. The caller is responsible for assigning the result to * `_state` and for persisting (the helper does not write to storage). */ private _loadOrCreateUserSessionState; /** * Bumps the part counter and arms the max-duration timer. Relies on * `_loadOrCreateUserSessionState` to provide a non-null, non-expired state, * so `getUserSessionAttributes()` is guaranteed non-null after this. */ private _beginUserSessionForPartStart; /** * Records the inactivity deadline on the user-session row so the next * part start can detect lazy expiry. The max-duration timer stays valid * because userSessionMaxEndTs doesn't change between parts. */ private _continueUserSessionAfterPartEnd; /** * Ends the active part as final and starts a fresh part for the next * user session. State clearing for the engaged path is handled by * endSessionPartInternal's isFinal branch. When no part is active * (tab disengaged), the same state-clearing is performed inline so * the next engagement creates a fresh user session rather than * resuming the just-ended one. */ private _rolloverUserSession; /** * Ends the active part and starts a new one within the same user session. * The user session is preserved while the part counters advance, so the * caller's `endReason`/`startReason` must both be non-final. Both spans share * one boundary timestamp so they tile without a gap; the caller may supply it * (for example the timestamp of the triggering event), defaulting to now. A * no-op when no part is active: there is nothing to roll over and the next * engagement starts one. */ rolloverSessionPartInternal({ endReason, startReason, timestamp }: RolloverSessionPartOptions): void; private _setupMaxDurationTimer; /** * @internal Would be private but exposed for tests to simulate a page reload */ _clearMaxDurationTimer(): void; /** * Detaches browser-activity listeners and clears the part-inactivity * timer. Intended for SDK teardown and tests; in production the manager * lives for the page's lifetime. */ _shutdown(): void; private readonly _onActivity; private readonly _onVisibilityChange; private readonly _onFocus; private readonly _onBlur; private _handleEngagementTransition; private readonly _onSessionPartInactivity; private _startSessionPartInactivityTimer; private _clearSessionPartInactivityTimer; private _addListener; private _fireListeners; private _storeState; private _removeFromPermanentProperties; private _removeFromUserSessionProperties; } //#endregion export { EmbraceUserSessionManager }; //# sourceMappingURL=EmbraceUserSessionManager.d.cts.map