@emit-vision/sdk-js 0.2.0 → 0.4.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 +38 -53
- package/dist/index.js +800 -479
- package/package.json +4 -3
- package/dist/retry.d.ts +0 -25
- package/dist/retry.js +0 -56
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
type EmitVisionUser = {
|
|
2
2
|
id?: string;
|
|
3
3
|
email?: string;
|
|
4
4
|
username?: string;
|
|
5
5
|
};
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
type EmitVisionTraits = Omit<EmitVisionUser, "id">;
|
|
7
|
+
type DeploymentContext = {
|
|
8
8
|
deploymentId?: string;
|
|
9
9
|
buildId?: string;
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
46
|
+
type EmitVisionOptions = {
|
|
41
47
|
apiKey?: string;
|
|
42
48
|
dsn?: string;
|
|
43
49
|
endpoint?: string;
|
|
@@ -66,21 +72,20 @@ export type EmitVisionOptions = {
|
|
|
66
72
|
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
73
|
autoCapture: Required<AutoCaptureOptions> & {
|
|
68
74
|
flagExposures: boolean;
|
|
75
|
+
pageViews: boolean;
|
|
69
76
|
};
|
|
70
77
|
};
|
|
78
|
+
|
|
71
79
|
declare class EmitVisionClient {
|
|
72
80
|
private readonly options;
|
|
73
|
-
private queue;
|
|
74
81
|
private user;
|
|
75
82
|
private context;
|
|
76
83
|
private deployment;
|
|
77
84
|
private featureFlags;
|
|
78
85
|
private tags;
|
|
79
|
-
private
|
|
80
|
-
private
|
|
81
|
-
private readonly
|
|
82
|
-
private readonly flagCache;
|
|
83
|
-
private readonly retry;
|
|
86
|
+
private readonly flagEval;
|
|
87
|
+
private readonly autoCapture;
|
|
88
|
+
private readonly flusher;
|
|
84
89
|
constructor(options: RequiredEmitVisionOptions);
|
|
85
90
|
captureEvent(name: string, properties?: Record<string, unknown>, options?: CaptureOptions): void;
|
|
86
91
|
captureError(error: unknown, options?: CaptureOptions): void;
|
|
@@ -88,51 +93,31 @@ declare class EmitVisionClient {
|
|
|
88
93
|
setContext(context: Record<string, unknown>): void;
|
|
89
94
|
setDeploymentContext(context: DeploymentContext): void;
|
|
90
95
|
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
96
|
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
97
|
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
98
|
refreshFlags(opts: FlagEvaluationOptions): Promise<FeatureFlagsContext>;
|
|
99
|
+
capturePageView(path?: string): void;
|
|
108
100
|
captureExposure(flagKey: string, variantKey: string, variantValue?: string | number | boolean | null, reason?: string, environment?: string): void;
|
|
109
|
-
private fetchAndCacheFlags;
|
|
110
101
|
setTags(tags: Record<string, string>): void;
|
|
111
102
|
flush(): Promise<void>;
|
|
112
|
-
private handleFlushFailure;
|
|
113
|
-
private stopBackgroundWork;
|
|
114
103
|
close(): void;
|
|
115
|
-
private enqueue;
|
|
116
|
-
private scheduleFlush;
|
|
117
104
|
private withDefaults;
|
|
118
|
-
private mergeDeployment;
|
|
119
|
-
private mergeFeatureFlags;
|
|
120
|
-
private readonly handleWindowError;
|
|
121
|
-
private readonly handleUnhandledRejection;
|
|
122
|
-
private debug;
|
|
123
105
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
106
|
+
|
|
107
|
+
declare function init(options: EmitVisionOptions): EmitVisionClient;
|
|
108
|
+
declare function captureEvent(name: string, properties?: Record<string, unknown>, options?: CaptureOptions): void;
|
|
109
|
+
declare function captureError(error: unknown, options?: CaptureOptions): void;
|
|
110
|
+
declare function capturePageView(path?: string): void;
|
|
111
|
+
declare function identify(user: EmitVisionUser): void;
|
|
112
|
+
declare function identify(userId: string, traits?: EmitVisionTraits): void;
|
|
113
|
+
declare function setContext(context: Record<string, unknown>): void;
|
|
114
|
+
declare function setDeploymentContext(context: DeploymentContext): void;
|
|
115
|
+
declare function setFeatureFlags(featureFlags: FeatureFlagsContext): void;
|
|
116
|
+
declare function setTags(tags: Record<string, string>): void;
|
|
117
|
+
declare function flush(): Promise<void>;
|
|
118
|
+
declare function evaluateFlags(options: FlagEvaluationOptions): Promise<FeatureFlagsContext>;
|
|
119
|
+
declare function getFlag<T extends string | number | boolean | null>(flagKey: string, fallback: T, options: FlagEvaluationOptions): Promise<T>;
|
|
120
|
+
declare function refreshFlags(options: FlagEvaluationOptions): Promise<FeatureFlagsContext>;
|
|
121
|
+
declare function captureExposure(flagKey: string, variantKey: string, variantValue?: string | number | boolean | null, reason?: string, environment?: string): void;
|
|
122
|
+
|
|
123
|
+
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 };
|