@traffical/core 0.1.2
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/dedup/decision-dedup.d.ts +74 -0
- package/dist/dedup/decision-dedup.d.ts.map +1 -0
- package/dist/dedup/decision-dedup.js +132 -0
- package/dist/dedup/decision-dedup.js.map +1 -0
- package/dist/dedup/index.d.ts +5 -0
- package/dist/dedup/index.d.ts.map +1 -0
- package/dist/dedup/index.js +5 -0
- package/dist/dedup/index.js.map +1 -0
- package/dist/edge/client.d.ts +109 -0
- package/dist/edge/client.d.ts.map +1 -0
- package/dist/edge/client.js +154 -0
- package/dist/edge/client.js.map +1 -0
- package/dist/edge/index.d.ts +7 -0
- package/dist/edge/index.d.ts.map +1 -0
- package/dist/edge/index.js +7 -0
- package/dist/edge/index.js.map +1 -0
- package/dist/hashing/bucket.d.ts +56 -0
- package/dist/hashing/bucket.d.ts.map +1 -0
- package/dist/hashing/bucket.js +89 -0
- package/dist/hashing/bucket.js.map +1 -0
- package/dist/hashing/fnv1a.d.ts +17 -0
- package/dist/hashing/fnv1a.d.ts.map +1 -0
- package/dist/hashing/fnv1a.js +27 -0
- package/dist/hashing/fnv1a.js.map +1 -0
- package/dist/hashing/index.d.ts +8 -0
- package/dist/hashing/index.d.ts.map +1 -0
- package/dist/hashing/index.js +8 -0
- package/dist/hashing/index.js.map +1 -0
- package/dist/ids/index.d.ts +83 -0
- package/dist/ids/index.d.ts.map +1 -0
- package/dist/ids/index.js +165 -0
- package/dist/ids/index.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/resolution/conditions.d.ts +81 -0
- package/dist/resolution/conditions.d.ts.map +1 -0
- package/dist/resolution/conditions.js +197 -0
- package/dist/resolution/conditions.js.map +1 -0
- package/dist/resolution/engine.d.ts +54 -0
- package/dist/resolution/engine.d.ts.map +1 -0
- package/dist/resolution/engine.js +382 -0
- package/dist/resolution/engine.js.map +1 -0
- package/dist/resolution/index.d.ts +8 -0
- package/dist/resolution/index.d.ts.map +1 -0
- package/dist/resolution/index.js +10 -0
- package/dist/resolution/index.js.map +1 -0
- package/dist/types/index.d.ts +440 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +51 -0
- package/src/dedup/decision-dedup.ts +175 -0
- package/src/dedup/index.ts +6 -0
- package/src/edge/client.ts +256 -0
- package/src/edge/index.ts +16 -0
- package/src/hashing/bucket.ts +115 -0
- package/src/hashing/fnv1a.test.ts +87 -0
- package/src/hashing/fnv1a.ts +31 -0
- package/src/hashing/index.ts +15 -0
- package/src/ids/index.ts +221 -0
- package/src/index.ts +136 -0
- package/src/resolution/conditions.ts +253 -0
- package/src/resolution/engine.test.ts +242 -0
- package/src/resolution/engine.ts +480 -0
- package/src/resolution/index.ts +32 -0
- package/src/types/index.ts +508 -0
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Traffical SDK Core Types
|
|
3
|
+
*
|
|
4
|
+
* These types define the contract between the SDK and the Control Plane.
|
|
5
|
+
* They are designed to be self-contained and independent of the control-plane package.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// =============================================================================
|
|
9
|
+
// Base Types
|
|
10
|
+
// =============================================================================
|
|
11
|
+
|
|
12
|
+
/** ISO 8601 timestamp string */
|
|
13
|
+
export type Timestamp = string;
|
|
14
|
+
|
|
15
|
+
/** Unique identifier */
|
|
16
|
+
export type Id = string;
|
|
17
|
+
|
|
18
|
+
/** Parameter value types supported by the system */
|
|
19
|
+
export type ParameterType = "string" | "number" | "boolean" | "json";
|
|
20
|
+
|
|
21
|
+
/** Runtime value for a parameter */
|
|
22
|
+
export type ParameterValue = string | number | boolean | Record<string, unknown>;
|
|
23
|
+
|
|
24
|
+
/** Context for evaluation - arbitrary key-value pairs */
|
|
25
|
+
export type Context = Record<string, unknown>;
|
|
26
|
+
|
|
27
|
+
// =============================================================================
|
|
28
|
+
// Config Bundle Types
|
|
29
|
+
// =============================================================================
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* ConfigBundle - the complete configuration for a project/environment.
|
|
33
|
+
* This is what the SDK fetches and caches.
|
|
34
|
+
*/
|
|
35
|
+
export interface ConfigBundle {
|
|
36
|
+
/** ISO timestamp for cache invalidation / ETag generation */
|
|
37
|
+
version: Timestamp;
|
|
38
|
+
/** Organization ID */
|
|
39
|
+
orgId: Id;
|
|
40
|
+
/** Project ID */
|
|
41
|
+
projectId: Id;
|
|
42
|
+
/** Environment (e.g., "production", "staging") */
|
|
43
|
+
env: string;
|
|
44
|
+
/** Hashing configuration for deterministic bucket assignment */
|
|
45
|
+
hashing: BundleHashingConfig;
|
|
46
|
+
/** All parameters for this project/env with defaults and layer membership */
|
|
47
|
+
parameters: BundleParameter[];
|
|
48
|
+
/** All layers with their policies */
|
|
49
|
+
layers: BundleLayer[];
|
|
50
|
+
/** DOM bindings for automatic value application (optional for backwards compatibility) */
|
|
51
|
+
domBindings?: BundleDOMBinding[];
|
|
52
|
+
/**
|
|
53
|
+
* Per-entity optimization state for per-entity adaptive policies.
|
|
54
|
+
* Only included for policies with resolutionMode: "bundle".
|
|
55
|
+
*/
|
|
56
|
+
entityState?: Record<Id, BundleEntityPolicyState>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Hashing configuration in the bundle.
|
|
61
|
+
*/
|
|
62
|
+
export interface BundleHashingConfig {
|
|
63
|
+
/** The context field name to use as the unit key */
|
|
64
|
+
unitKey: string;
|
|
65
|
+
/** Total number of buckets for allocation */
|
|
66
|
+
bucketCount: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Parameter definition in the bundle.
|
|
71
|
+
*/
|
|
72
|
+
export interface BundleParameter {
|
|
73
|
+
/** Parameter key (e.g., "ui.primaryColor", "pricing.discount") */
|
|
74
|
+
key: string;
|
|
75
|
+
/** Value type */
|
|
76
|
+
type: ParameterType;
|
|
77
|
+
/** Default value when no policy overrides apply */
|
|
78
|
+
default: ParameterValue;
|
|
79
|
+
/** The layer this parameter belongs to */
|
|
80
|
+
layerId: Id;
|
|
81
|
+
/** Namespace for organizational purposes */
|
|
82
|
+
namespace: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* DOM binding definition in the bundle.
|
|
87
|
+
* Links a parameter to a DOM element for automatic value application.
|
|
88
|
+
*/
|
|
89
|
+
export interface BundleDOMBinding {
|
|
90
|
+
/** Parameter key (denormalized for SDK lookup) */
|
|
91
|
+
parameterKey: string;
|
|
92
|
+
/** CSS selector for the target element */
|
|
93
|
+
selector: string;
|
|
94
|
+
/** Which property to modify: 'innerHTML', 'textContent', 'src', 'href', etc. */
|
|
95
|
+
property: string;
|
|
96
|
+
/** URL pattern (regex) where this binding applies */
|
|
97
|
+
urlPattern: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Layer definition in the bundle.
|
|
102
|
+
*/
|
|
103
|
+
export interface BundleLayer {
|
|
104
|
+
/** Layer ID */
|
|
105
|
+
id: Id;
|
|
106
|
+
/** Policies within this layer (evaluated in order) */
|
|
107
|
+
policies: BundlePolicy[];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Policy state determines whether it's active.
|
|
112
|
+
*/
|
|
113
|
+
export type PolicyState = "draft" | "running" | "paused" | "completed";
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Policy kind determines how allocations are managed.
|
|
117
|
+
* - "static": Fixed allocations (A/B testing) - bucket ranges never change
|
|
118
|
+
* - "adaptive": Dynamic allocations based on rewards (bandit-style learning)
|
|
119
|
+
*/
|
|
120
|
+
export type PolicyKind = "static" | "adaptive";
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Context logging configuration in the bundle.
|
|
124
|
+
*
|
|
125
|
+
* Defines which context fields should be logged in exposure events
|
|
126
|
+
* for contextual bandit training.
|
|
127
|
+
*/
|
|
128
|
+
export interface BundleContextLogging {
|
|
129
|
+
/**
|
|
130
|
+
* Context fields to include in exposure events (allowlist).
|
|
131
|
+
* Only these fields will be logged for training.
|
|
132
|
+
*/
|
|
133
|
+
allowedFields: string[];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Configuration for per-entity adaptive policies.
|
|
138
|
+
*
|
|
139
|
+
* When present on an adaptive policy, optimization happens at a granular level
|
|
140
|
+
* (per product, per user, or any combination of context keys) instead of globally.
|
|
141
|
+
*/
|
|
142
|
+
export interface EntityConfig {
|
|
143
|
+
/**
|
|
144
|
+
* Context keys that identify the entity.
|
|
145
|
+
* The entity ID is built by joining these key values with "_".
|
|
146
|
+
*/
|
|
147
|
+
entityKeys: string[];
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* How to resolve entity state.
|
|
151
|
+
* - "bundle": State shipped in config bundle, SDK resolves locally
|
|
152
|
+
* - "edge": SDK calls edge API for fresh state
|
|
153
|
+
*/
|
|
154
|
+
resolutionMode: "bundle" | "edge";
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* For edge mode: timeout in milliseconds before falling back to bundle.
|
|
158
|
+
*/
|
|
159
|
+
edgeTimeoutMs?: number;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* When set, allocations are dynamically derived from a context key
|
|
163
|
+
* instead of being fixed in the policy definition.
|
|
164
|
+
*/
|
|
165
|
+
dynamicAllocations?: {
|
|
166
|
+
/** Context key containing the count of options */
|
|
167
|
+
countKey: string;
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Entity weights for per-entity resolution.
|
|
173
|
+
*/
|
|
174
|
+
export interface EntityWeights {
|
|
175
|
+
/** Entity ID */
|
|
176
|
+
entityId: string;
|
|
177
|
+
/** Selection weights per allocation (sum to 1.0) */
|
|
178
|
+
weights: number[];
|
|
179
|
+
/** When these weights were computed */
|
|
180
|
+
computedAt: Timestamp;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Per-entity state for a single policy in the bundle.
|
|
185
|
+
*/
|
|
186
|
+
export interface BundleEntityPolicyState {
|
|
187
|
+
/** Global prior weights (used for cold start) */
|
|
188
|
+
_global: EntityWeights;
|
|
189
|
+
/** Per-entity learned weights */
|
|
190
|
+
entities: Record<string, EntityWeights>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Policy definition in the bundle.
|
|
195
|
+
*/
|
|
196
|
+
export interface BundlePolicy {
|
|
197
|
+
/** Policy ID for tracking and analytics */
|
|
198
|
+
id: Id;
|
|
199
|
+
/** Current state */
|
|
200
|
+
state: PolicyState;
|
|
201
|
+
/** Policy kind: "static" for fixed allocations, "adaptive" for learning-based */
|
|
202
|
+
kind: PolicyKind;
|
|
203
|
+
/** Allocations: bucket ranges mapped to parameter overrides */
|
|
204
|
+
allocations: BundleAllocation[];
|
|
205
|
+
/** Conditions: context predicates that must all match for eligibility */
|
|
206
|
+
conditions: BundleCondition[];
|
|
207
|
+
/**
|
|
208
|
+
* For adaptive policies: version of the optimization state.
|
|
209
|
+
* Updated when the optimization engine changes allocations.
|
|
210
|
+
*/
|
|
211
|
+
stateVersion?: Timestamp;
|
|
212
|
+
/**
|
|
213
|
+
* For adaptive policies: context fields to log in exposure events.
|
|
214
|
+
* Only fields in the allowlist are included to protect PII.
|
|
215
|
+
*/
|
|
216
|
+
contextLogging?: BundleContextLogging;
|
|
217
|
+
/**
|
|
218
|
+
* For per-entity adaptive policies: entity configuration.
|
|
219
|
+
* When present, optimization happens at a granular level per entity.
|
|
220
|
+
*/
|
|
221
|
+
entityConfig?: EntityConfig;
|
|
222
|
+
/**
|
|
223
|
+
* Optional bucket eligibility range for non-overlapping experiments.
|
|
224
|
+
* When set, this policy only applies to users whose bucket falls within [start, end].
|
|
225
|
+
* If not set, the policy applies to all buckets (default behavior).
|
|
226
|
+
*/
|
|
227
|
+
eligibleBucketRange?: { start: number; end: number };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Allocation in the bundle.
|
|
232
|
+
*/
|
|
233
|
+
export interface BundleAllocation {
|
|
234
|
+
/** Unique allocation ID */
|
|
235
|
+
id: Id;
|
|
236
|
+
/** Variant name for tracking (e.g., "control", "treatment_a") */
|
|
237
|
+
name: string;
|
|
238
|
+
/** Bucket range [start, end] inclusive */
|
|
239
|
+
bucketRange: [number, number];
|
|
240
|
+
/** Parameter overrides for units in this bucket range */
|
|
241
|
+
overrides: Record<string, ParameterValue>;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Condition operators for context matching.
|
|
246
|
+
*/
|
|
247
|
+
export type ConditionOperator =
|
|
248
|
+
| "eq"
|
|
249
|
+
| "neq"
|
|
250
|
+
| "in"
|
|
251
|
+
| "nin"
|
|
252
|
+
| "gt"
|
|
253
|
+
| "gte"
|
|
254
|
+
| "lt"
|
|
255
|
+
| "lte"
|
|
256
|
+
| "contains"
|
|
257
|
+
| "startsWith"
|
|
258
|
+
| "endsWith"
|
|
259
|
+
| "regex"
|
|
260
|
+
| "exists"
|
|
261
|
+
| "notExists";
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Condition in the bundle.
|
|
265
|
+
*/
|
|
266
|
+
export interface BundleCondition {
|
|
267
|
+
/** Context field to evaluate */
|
|
268
|
+
field: string;
|
|
269
|
+
/** Comparison operator */
|
|
270
|
+
op: ConditionOperator;
|
|
271
|
+
/** Single value for binary operators */
|
|
272
|
+
value?: unknown;
|
|
273
|
+
/** Multiple values for "in"/"nin" operators */
|
|
274
|
+
values?: unknown[];
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// =============================================================================
|
|
278
|
+
// SDK-Specific Types
|
|
279
|
+
// =============================================================================
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Parameter defaults - simple key-value pairs for fallback values.
|
|
283
|
+
* TypeScript will infer the types from the values provided.
|
|
284
|
+
*/
|
|
285
|
+
export type ParameterDefaults<T extends Record<string, ParameterValue> = Record<string, ParameterValue>> = T;
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Layer resolution info for tracking.
|
|
289
|
+
*/
|
|
290
|
+
export interface LayerResolution {
|
|
291
|
+
layerId: Id;
|
|
292
|
+
/** The bucket computed for this layer */
|
|
293
|
+
bucket: number;
|
|
294
|
+
/** The policy that was applied (if any) */
|
|
295
|
+
policyId?: Id;
|
|
296
|
+
/** The allocation ID that was selected (if any) */
|
|
297
|
+
allocationId?: Id;
|
|
298
|
+
/** The allocation/variant name that was selected (if any) */
|
|
299
|
+
allocationName?: string;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Decision result with metadata for tracking.
|
|
304
|
+
*/
|
|
305
|
+
export interface DecisionResult {
|
|
306
|
+
/** Unique ID for this decision */
|
|
307
|
+
decisionId: Id;
|
|
308
|
+
/** Resolved parameter assignments */
|
|
309
|
+
assignments: Record<string, ParameterValue>;
|
|
310
|
+
/** Metadata about the resolution */
|
|
311
|
+
metadata: DecisionMetadata;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Metadata about a decision.
|
|
316
|
+
*/
|
|
317
|
+
export interface DecisionMetadata {
|
|
318
|
+
/** Timestamp of the decision */
|
|
319
|
+
timestamp: Timestamp;
|
|
320
|
+
/** The unit key value used for bucket computation */
|
|
321
|
+
unitKeyValue: string;
|
|
322
|
+
/** Per-layer resolution info */
|
|
323
|
+
layers: LayerResolution[];
|
|
324
|
+
/**
|
|
325
|
+
* Filtered context for exposure logging.
|
|
326
|
+
* Contains only fields allowed by matched policies' contextLogging config.
|
|
327
|
+
* Used for contextual bandit training without exposing PII.
|
|
328
|
+
*/
|
|
329
|
+
filteredContext?: Context;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// =============================================================================
|
|
333
|
+
// Event Types (for SDK tracking)
|
|
334
|
+
// =============================================================================
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Base fields for events sent to the control plane.
|
|
338
|
+
*/
|
|
339
|
+
export interface BaseEventFields {
|
|
340
|
+
/** Optional client-generated event ID */
|
|
341
|
+
id?: Id;
|
|
342
|
+
/** Organization ID */
|
|
343
|
+
orgId: Id;
|
|
344
|
+
/** Project ID */
|
|
345
|
+
projectId: Id;
|
|
346
|
+
/** Environment */
|
|
347
|
+
env: string;
|
|
348
|
+
/** Unit key value */
|
|
349
|
+
unitKey: string;
|
|
350
|
+
/** Event timestamp */
|
|
351
|
+
timestamp: Timestamp;
|
|
352
|
+
/** Optional context snapshot */
|
|
353
|
+
context?: Context;
|
|
354
|
+
/**
|
|
355
|
+
* SDK that generated this event.
|
|
356
|
+
* Examples: "js-client", "node", "react"
|
|
357
|
+
*/
|
|
358
|
+
sdkName?: string;
|
|
359
|
+
/**
|
|
360
|
+
* Version of the SDK that generated this event.
|
|
361
|
+
* Example: "0.1.0"
|
|
362
|
+
*/
|
|
363
|
+
sdkVersion?: string;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Exposure event for tracking parameter exposures.
|
|
368
|
+
*/
|
|
369
|
+
export interface ExposureEvent extends BaseEventFields {
|
|
370
|
+
type: "exposure";
|
|
371
|
+
/** Reference to the decision that was exposed */
|
|
372
|
+
decisionId: Id;
|
|
373
|
+
/** The parameter assignments that were exposed */
|
|
374
|
+
assignments: Record<string, ParameterValue>;
|
|
375
|
+
/** Per-layer resolution metadata */
|
|
376
|
+
layers: LayerResolution[];
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Attribution for a track event to a specific policy/allocation.
|
|
381
|
+
*/
|
|
382
|
+
export interface TrackAttribution {
|
|
383
|
+
layerId: Id;
|
|
384
|
+
policyId: Id;
|
|
385
|
+
allocationName: string;
|
|
386
|
+
/** Attribution weight (0.0-1.0). Defaults to equal split if not provided. */
|
|
387
|
+
weight?: number;
|
|
388
|
+
/** Optional: which attribution model assigned this weight */
|
|
389
|
+
model?: 'first_touch' | 'last_touch' | 'linear' | 'time_decay' | 'position_based';
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Track event - records user behavior/conversion.
|
|
394
|
+
*
|
|
395
|
+
* Replaces the old ActionEvent and RewardEvent types.
|
|
396
|
+
* Used for conversion tracking, engagement metrics, and optimization.
|
|
397
|
+
*/
|
|
398
|
+
export interface TrackEvent extends BaseEventFields {
|
|
399
|
+
type: "track";
|
|
400
|
+
/** Event name (e.g., 'purchase', 'add_to_cart', 'page_view') */
|
|
401
|
+
event: string;
|
|
402
|
+
/** Reference to the decision event for attribution */
|
|
403
|
+
decisionId?: Id;
|
|
404
|
+
/** Primary numeric value for optimization (e.g., revenue amount) */
|
|
405
|
+
value?: number;
|
|
406
|
+
/** Optional secondary values for multi-objective optimization */
|
|
407
|
+
values?: Record<string, number>;
|
|
408
|
+
/** Event properties/metadata (e.g., orderId, itemSku) */
|
|
409
|
+
properties?: Record<string, unknown>;
|
|
410
|
+
/**
|
|
411
|
+
* Attribution chain - which policies/allocations influenced this.
|
|
412
|
+
* SDK auto-populates this from cached decision when decisionId is provided.
|
|
413
|
+
*/
|
|
414
|
+
attribution?: TrackAttribution[];
|
|
415
|
+
/** For delayed events: the original event timestamp */
|
|
416
|
+
eventTimestamp?: Timestamp;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* DecisionEvent - records that a decision was made (assignment computed).
|
|
421
|
+
*
|
|
422
|
+
* Used for:
|
|
423
|
+
* - Intent-to-treat analysis: tracking all assignments, not just exposures
|
|
424
|
+
* - Debugging: understanding why specific values were computed
|
|
425
|
+
* - Audit trail: tracking all decisions made by the SDK
|
|
426
|
+
*
|
|
427
|
+
* Unlike ExposureEvent which is tracked when the user sees the variant,
|
|
428
|
+
* DecisionEvent is tracked immediately when decide() is called.
|
|
429
|
+
*/
|
|
430
|
+
export interface DecisionEvent extends BaseEventFields {
|
|
431
|
+
type: "decision";
|
|
432
|
+
/** Parameters that were requested (keys from defaults) */
|
|
433
|
+
requestedParameters?: string[];
|
|
434
|
+
/** The resolved assignments */
|
|
435
|
+
assignments: Record<string, ParameterValue>;
|
|
436
|
+
/** Resolution metadata */
|
|
437
|
+
layers: LayerResolution[];
|
|
438
|
+
/** Processing time in milliseconds */
|
|
439
|
+
latencyMs?: number;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Union of all trackable events.
|
|
444
|
+
*/
|
|
445
|
+
export type TrackableEvent = ExposureEvent | TrackEvent | DecisionEvent;
|
|
446
|
+
|
|
447
|
+
// =============================================================================
|
|
448
|
+
// Client Configuration Types
|
|
449
|
+
// =============================================================================
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Options for creating a Traffical client.
|
|
453
|
+
*/
|
|
454
|
+
export interface TrafficalClientOptions {
|
|
455
|
+
/** Organization ID */
|
|
456
|
+
orgId: Id;
|
|
457
|
+
/** Project ID */
|
|
458
|
+
projectId: Id;
|
|
459
|
+
/** Environment (e.g., "production", "staging") */
|
|
460
|
+
env: string;
|
|
461
|
+
/** API key for authentication */
|
|
462
|
+
apiKey: string;
|
|
463
|
+
/** Base URL for the control plane API (optional, defaults to Traffical cloud) */
|
|
464
|
+
baseUrl?: string;
|
|
465
|
+
/** Local config bundle for offline fallback */
|
|
466
|
+
localConfig?: ConfigBundle;
|
|
467
|
+
/** Refresh interval in milliseconds (default: 60000) */
|
|
468
|
+
refreshIntervalMs?: number;
|
|
469
|
+
/** Strict mode: throw on unknown or deprecated parameters */
|
|
470
|
+
strictMode?: boolean;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Options for parameter resolution.
|
|
475
|
+
*/
|
|
476
|
+
export interface GetParamsOptions<T extends Record<string, ParameterValue> = Record<string, ParameterValue>> {
|
|
477
|
+
/** Context for evaluation */
|
|
478
|
+
context: Context;
|
|
479
|
+
/** Default values for parameters - used as fallback when bundle unavailable */
|
|
480
|
+
defaults: T;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Options for making a decision.
|
|
485
|
+
*/
|
|
486
|
+
export interface DecideOptions<T extends Record<string, ParameterValue> = Record<string, ParameterValue>> {
|
|
487
|
+
/** Context for evaluation */
|
|
488
|
+
context: Context;
|
|
489
|
+
/** Default values for parameters - used as fallback when bundle unavailable */
|
|
490
|
+
defaults: T;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Options for tracking an event.
|
|
495
|
+
*/
|
|
496
|
+
export interface TrackOptions {
|
|
497
|
+
/** Event name (e.g., 'purchase', 'add_to_cart') */
|
|
498
|
+
event: string;
|
|
499
|
+
/** Primary value for optimization (optional) */
|
|
500
|
+
value?: number;
|
|
501
|
+
/** Additional event properties */
|
|
502
|
+
properties?: Record<string, unknown>;
|
|
503
|
+
/** Reference to the decision (optional, SDK can auto-populate) */
|
|
504
|
+
decisionId?: Id;
|
|
505
|
+
/** Secondary values for multi-objective optimization */
|
|
506
|
+
values?: Record<string, number>;
|
|
507
|
+
}
|
|
508
|
+
|