@emit-vision/sdk-js 0.2.0 → 0.3.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/dist/index.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- export type EmitVisionUser = {
1
+ type EmitVisionUser = {
2
2
  id?: string;
3
3
  email?: string;
4
4
  username?: string;
5
5
  };
6
- export type EmitVisionTraits = Omit<EmitVisionUser, "id">;
7
- export type DeploymentContext = {
6
+ type EmitVisionTraits = Omit<EmitVisionUser, "id">;
7
+ type DeploymentContext = {
8
8
  deploymentId?: string;
9
9
  buildId?: string;
10
10
  };
11
- export type FeatureFlagsContext = Record<string, string | number | boolean | null>;
12
- export type FlagEvaluationOptions = {
11
+ type FeatureFlagsContext = Record<string, string | number | boolean | null>;
12
+ type FlagEvaluationOptions = {
13
13
  /** Opaque key used to bucket the caller. Must be provided explicitly — the SDK never reads email or username automatically. */
14
14
  evaluationKey: string;
15
15
  /** Overrides the environment set at init time for this evaluation request. */
@@ -19,13 +19,19 @@ export type FlagEvaluationOptions = {
19
19
  /** Limit evaluation to specific flag keys. Omit to evaluate all active flags. */
20
20
  flagKeys?: string[];
21
21
  };
22
- export type AutoCaptureOptions = {
22
+ type AutoCaptureOptions = {
23
23
  errors?: boolean;
24
24
  unhandledRejections?: boolean;
25
25
  /** Automatically fire a `$flag_exposure` event for each flag after evaluation. Default: true. */
26
26
  flagExposures?: boolean;
27
+ /**
28
+ * Automatically fire a `$page_view` event on init and on browser navigation
29
+ * (popstate + history.pushState/replaceState). Default: false.
30
+ * The event includes `{ page: window.location.pathname }` in properties.
31
+ */
32
+ pageViews?: boolean;
27
33
  };
28
- export type CaptureOptions = {
34
+ type CaptureOptions = {
29
35
  eventId?: string;
30
36
  timestamp?: string;
31
37
  environment?: string;
@@ -37,7 +43,7 @@ export type CaptureOptions = {
37
43
  featureFlags?: FeatureFlagsContext;
38
44
  tags?: Record<string, string>;
39
45
  };
40
- export type EmitVisionOptions = {
46
+ type EmitVisionOptions = {
41
47
  apiKey?: string;
42
48
  dsn?: string;
43
49
  endpoint?: string;
@@ -63,9 +69,11 @@ export type EmitVisionOptions = {
63
69
  /** Disable the SDK after this many consecutive flush failures: the queue is dropped, future captures become no-ops, and a single warning is logged. Default: 20. Set to 0 to disable the cap and retry forever. */
64
70
  maxConsecutiveFlushFailures?: number;
65
71
  };
72
+
66
73
  type RequiredEmitVisionOptions = Required<Pick<EmitVisionOptions, "apiKey" | "endpoint" | "flushIntervalMs" | "batchSize" | "fetchImpl" | "flushOnCapture" | "flagEvalTtlMs" | "retryBackoffInitialMs" | "retryBackoffMaxMs" | "maxConsecutiveFlushFailures">> & Pick<EmitVisionOptions, "environment" | "release" | "sessionId" | "label" | "deployment" | "featureFlags" | "debug"> & {
67
74
  autoCapture: Required<AutoCaptureOptions> & {
68
75
  flagExposures: boolean;
76
+ pageViews: boolean;
69
77
  };
70
78
  };
71
79
  declare class EmitVisionClient {
@@ -79,7 +87,7 @@ declare class EmitVisionClient {
79
87
  private timer;
80
88
  private flushScheduled;
81
89
  private readonly fetchImpl;
82
- private readonly flagCache;
90
+ private readonly flagEval;
83
91
  private readonly retry;
84
92
  constructor(options: RequiredEmitVisionOptions);
85
93
  captureEvent(name: string, properties?: Record<string, unknown>, options?: CaptureOptions): void;
@@ -88,51 +96,45 @@ declare class EmitVisionClient {
88
96
  setContext(context: Record<string, unknown>): void;
89
97
  setDeploymentContext(context: DeploymentContext): void;
90
98
  setFeatureFlags(featureFlags: FeatureFlagsContext): void;
91
- /**
92
- * Fetch and evaluate all active flags for the given evaluation key.
93
- * Results are cached for `ttlMs` (defaults to `flagEvalTtlMs` from init options).
94
- * On network failure returns an empty object and does not throw.
95
- * Evaluated variants are automatically merged into the SDK's feature-flag context.
96
- */
97
99
  evaluateFlags(opts: FlagEvaluationOptions): Promise<FeatureFlagsContext>;
98
- /**
99
- * Return a single flag's value, evaluated for the given key.
100
- * Returns `fallback` on network failure or when the flag is not found — never throws.
101
- */
102
100
  getFlag<T extends string | number | boolean | null>(flagKey: string, fallback: T, opts: FlagEvaluationOptions): Promise<T>;
103
- /**
104
- * Bypass the cache and re-fetch evaluations for the given key.
105
- * Useful after a flag change in the dashboard that should apply immediately.
106
- */
107
101
  refreshFlags(opts: FlagEvaluationOptions): Promise<FeatureFlagsContext>;
102
+ capturePageView(path?: string): void;
108
103
  captureExposure(flagKey: string, variantKey: string, variantValue?: string | number | boolean | null, reason?: string, environment?: string): void;
109
- private fetchAndCacheFlags;
110
104
  setTags(tags: Record<string, string>): void;
111
105
  flush(): Promise<void>;
106
+ private flushChunk;
112
107
  private handleFlushFailure;
113
108
  private stopBackgroundWork;
114
109
  close(): void;
110
+ private enqueueMetaEvent;
115
111
  private enqueue;
116
112
  private scheduleFlush;
117
113
  private withDefaults;
118
114
  private mergeDeployment;
119
115
  private mergeFeatureFlags;
120
116
  private readonly handleWindowError;
117
+ private readonly handlePopState;
118
+ private patchHistoryMethod;
119
+ private restoreHistoryMethod;
121
120
  private readonly handleUnhandledRejection;
122
121
  private debug;
123
122
  }
124
- export declare function init(options: EmitVisionOptions): EmitVisionClient;
125
- export declare function captureEvent(name: string, properties?: Record<string, unknown>, options?: CaptureOptions): void;
126
- export declare function captureError(error: unknown, options?: CaptureOptions): void;
127
- export declare function identify(user: EmitVisionUser): void;
128
- export declare function identify(userId: string, traits?: EmitVisionTraits): void;
129
- export declare function setContext(context: Record<string, unknown>): void;
130
- export declare function setDeploymentContext(context: DeploymentContext): void;
131
- export declare function setFeatureFlags(featureFlags: FeatureFlagsContext): void;
132
- export declare function setTags(tags: Record<string, string>): void;
133
- export declare function flush(): Promise<void>;
134
- export declare function evaluateFlags(options: FlagEvaluationOptions): Promise<FeatureFlagsContext>;
135
- export declare function getFlag<T extends string | number | boolean | null>(flagKey: string, fallback: T, options: FlagEvaluationOptions): Promise<T>;
136
- export declare function refreshFlags(options: FlagEvaluationOptions): Promise<FeatureFlagsContext>;
137
- export declare function captureExposure(flagKey: string, variantKey: string, variantValue?: string | number | boolean | null, reason?: string, environment?: string): void;
138
- export {};
123
+
124
+ declare function init(options: EmitVisionOptions): EmitVisionClient;
125
+ declare function captureEvent(name: string, properties?: Record<string, unknown>, options?: CaptureOptions): void;
126
+ declare function captureError(error: unknown, options?: CaptureOptions): void;
127
+ declare function capturePageView(path?: string): void;
128
+ declare function identify(user: EmitVisionUser): void;
129
+ declare function identify(userId: string, traits?: EmitVisionTraits): void;
130
+ declare function setContext(context: Record<string, unknown>): void;
131
+ declare function setDeploymentContext(context: DeploymentContext): void;
132
+ declare function setFeatureFlags(featureFlags: FeatureFlagsContext): void;
133
+ declare function setTags(tags: Record<string, string>): void;
134
+ declare function flush(): Promise<void>;
135
+ declare function evaluateFlags(options: FlagEvaluationOptions): Promise<FeatureFlagsContext>;
136
+ declare function getFlag<T extends string | number | boolean | null>(flagKey: string, fallback: T, options: FlagEvaluationOptions): Promise<T>;
137
+ declare function refreshFlags(options: FlagEvaluationOptions): Promise<FeatureFlagsContext>;
138
+ declare function captureExposure(flagKey: string, variantKey: string, variantValue?: string | number | boolean | null, reason?: string, environment?: string): void;
139
+
140
+ export { type AutoCaptureOptions, type CaptureOptions, type DeploymentContext, type EmitVisionOptions, type EmitVisionTraits, type EmitVisionUser, type FeatureFlagsContext, type FlagEvaluationOptions, captureError, captureEvent, captureExposure, capturePageView, evaluateFlags, flush, getFlag, identify, init, refreshFlags, setContext, setDeploymentContext, setFeatureFlags, setTags };