@splithub/core 0.1.1 → 0.1.3

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.cts CHANGED
@@ -4,7 +4,7 @@
4
4
  * cloud all read the same object.
5
5
  */
6
6
  type ExperimentStatus = 'draft' | 'running' | 'paused' | 'finished';
7
- type ExperimentKind = 'component' | 'value' | 'redirect';
7
+ type ExperimentKind = 'component' | 'value' | 'redirect' | 'mvt';
8
8
  /** Weight shorthand (`{ control: 50, bold: 50 }`) or a full variant object. */
9
9
  type ComponentVariantInput = number | {
10
10
  weight: number;
@@ -108,7 +108,18 @@ interface RedirectExperimentInput extends ExperimentBase {
108
108
  match: string;
109
109
  variants: Record<string, RedirectVariantInput>;
110
110
  }
111
- type ExperimentInput = ComponentExperimentInput | ValueExperimentInput | RedirectExperimentInput;
111
+ /**
112
+ * Multivariate: several factors change at once and every combination is a
113
+ * variant. `{ headline: { old: 'Old', new: 'New' }, button: { red: '#f00', green: '#0f0' } }`
114
+ * gives four variants; the first level of every factor is the control. Besides
115
+ * the verdict over combinations, each factor is read on its own (main effects).
116
+ * Keep it small: at most 4 factors, 4 levels each, 16 combinations.
117
+ */
118
+ interface MvtExperimentInput extends ExperimentBase {
119
+ kind: 'mvt';
120
+ factors: Record<string, Record<string, unknown>>;
121
+ }
122
+ type ExperimentInput = ComponentExperimentInput | ValueExperimentInput | RedirectExperimentInput | MvtExperimentInput;
112
123
  type GoalInput = {
113
124
  type: 'event';
114
125
  revenue?: boolean;
@@ -142,6 +153,12 @@ interface SplitHubConfigInput {
142
153
  experiments: Record<string, ExperimentInput>;
143
154
  /** Cookie / localStorage key for the visitor id. Defaults to `sh_vid`. */
144
155
  visitorKey?: string;
156
+ /**
157
+ * Treat `status: 'draft'` experiments as running while the app runs in
158
+ * development (`NODE_ENV === 'development'`: `next dev`, `vite`). Lets you
159
+ * see a test before you start it. Production builds ignore drafts as usual.
160
+ */
161
+ runDraftsInDev?: boolean;
145
162
  }
146
163
  interface Variant {
147
164
  key: string;
@@ -149,6 +166,13 @@ interface Variant {
149
166
  weight: number;
150
167
  value?: unknown;
151
168
  to?: string;
169
+ /** Multivariate: which level of each factor this combination uses. */
170
+ levels?: Record<string, string>;
171
+ }
172
+ /** Multivariate factor: its levels in declared order (the first is the control level). */
173
+ interface Factor {
174
+ key: string;
175
+ levels: string[];
152
176
  }
153
177
  interface Experiment {
154
178
  key: string;
@@ -172,6 +196,8 @@ interface Experiment {
172
196
  origin?: 'config' | 'dashboard';
173
197
  /** Targeting / branching graph; null or absent = plain weights. */
174
198
  flow?: Flow | null;
199
+ /** Multivariate: the factors whose combinations the variants are. */
200
+ factors?: Factor[];
175
201
  }
176
202
  interface Goal {
177
203
  key: string;
@@ -186,6 +212,7 @@ interface SplitHubConfig {
186
212
  project: string;
187
213
  storage: StorageInput;
188
214
  visitorKey: string;
215
+ runDraftsInDev: boolean;
189
216
  goals: Goal[];
190
217
  experiments: Experiment[];
191
218
  /** Branded marker so plain objects are rejected by the SDK. */
@@ -222,13 +249,25 @@ interface Assignment {
222
249
  experiment: string;
223
250
  /** Null when the visitor is outside the traffic share or the experiment is not running. */
224
251
  variant: Variant | null;
225
- /** Why the variant was (not) assigned. Useful for `splithub doctor`. */
226
- reason: 'assigned' | 'not_running' | 'outside_traffic' | 'unknown_experiment' | 'override' | 'targeting';
252
+ /** Why the variant was (not) assigned. Useful for `splithub doctor`. `dev`: a draft served because of `runDraftsInDev`. */
253
+ reason: 'assigned' | 'dev' | 'not_running' | 'outside_traffic' | 'unknown_experiment' | 'override' | 'targeting';
227
254
  }
228
255
 
229
256
  declare class ConfigError extends Error {
230
257
  constructor(message: string);
231
258
  }
259
+ declare const MVT_MAX_FACTORS = 4;
260
+ declare const MVT_MAX_LEVELS = 4;
261
+ declare const MVT_MAX_COMBINATIONS = 16;
262
+ /**
263
+ * Every combination of the factors' levels as a variant, in order (first levels
264
+ * first, so the all-control combination is the control), equal weights. The
265
+ * variant's `value` is `{ factor: levelValue }`, what `useValue()` returns.
266
+ */
267
+ declare function mvtVariants(expKey: string, factors: Record<string, Record<string, unknown>>): {
268
+ variants: Variant[];
269
+ factors: Factor[];
270
+ };
232
271
  /**
233
272
  * Validate and normalize a config. Call it once in `splithub.config.ts`:
234
273
  *
@@ -240,6 +279,16 @@ declare function defineConfig(input: SplitHubConfigInput): SplitHubConfig;
240
279
  declare function isSplitHubConfig(value: unknown): value is SplitHubConfig;
241
280
  declare function getExperiment(config: SplitHubConfig, key: string): Experiment | undefined;
242
281
 
282
+ /**
283
+ * True in `next dev` / `vite` and on the server of a dev build. Bundlers
284
+ * replace `process.env.NODE_ENV` with a literal, so the expression is kept
285
+ * verbatim; where nothing replaces it and no `process` exists, it is false.
286
+ */
287
+ declare function isDevEnvironment(): boolean;
288
+ /** A draft shown in development because the config says `runDraftsInDev: true`. */
289
+ declare function isDevDraft(config: Pick<SplitHubConfig, 'runDraftsInDev'>, experiment: Pick<Experiment, 'status'>): boolean;
290
+ /** Running now, or a draft served in development. What the middleware and the drop-in script check before assigning. */
291
+ declare function isActive(config: Pick<SplitHubConfig, 'runDraftsInDev'>, experiment: Pick<Experiment, 'status' | 'schedule'>, now?: number): boolean;
243
292
  /**
244
293
  * Deterministic bucketing. Same visitor + same experiment + same seed always
245
294
  * yields the same variant, on any runtime, with no network call.
@@ -470,4 +519,4 @@ declare function debugLog(kind: DebugKind, message: string, data?: Record<string
470
519
  /** Subscribe to debug entries (the devtools panel). Returns an unsubscribe function. */
471
520
  declare function onDebug(listener: (e: DebugEntry) => void): () => void;
472
521
 
473
- export { type AssignOptions, type Assignment, CLOUD_ENDPOINT, type ClientOptions, type ComponentExperimentInput, type ComponentVariantInput, ConfigError, type DebugEntry, type DebugKind, EMPTY_OVERRIDES, type EventBatch, EventQueue, type EventQueueOptions, type Experiment, type ExperimentBase, type ExperimentInput, type ExperimentKind, type ExperimentOverride, type ExperimentStatus, type ExposureEvent, type Flow, type FlowNode, type FlowOutcome, type Goal, type GoalEvent, type GoalInput, KEYED_FIELDS, REMOTE_TTL_MS, type RedirectExperimentInput, type RedirectVariantInput, type RemoteOverrides, SDK_VERSION, type SplitHubClient, type SplitHubConfig, type SplitHubConfigInput, type SplitHubEvent, type StorageInput, TARGET_FIELDS, TARGET_OPS, type TargetCondition, type TargetField, type TargetOp, type TargetingContext, type Transport, type TransportOptions, type ValueExperimentInput, type ValueVariantInput, type Variant, applyRemoteOverrides, assign, browserContext, contextValue, controlVariant, createClient, createFetchTransport, debugLog, debugMode, defineConfig, evaluateCondition, fetchRemoteOverrides, getExperiment, getOrCreateSessionId, getOrCreateVisitorId, hasVisitorId, hashToUnit, inSchedule, isBrowser, isDebug, isRemoteOverrides, isSplitHubConfig, matchConditions, murmur3, newId, newSessionId, newVisitorId, onDebug, parseCookies, parseForceParam, parseUserAgent, pickVariant, readRemoteCache, resolveOverridesUrl, runFlow, validateFlow, writeRemoteCache };
522
+ export { type AssignOptions, type Assignment, CLOUD_ENDPOINT, type ClientOptions, type ComponentExperimentInput, type ComponentVariantInput, ConfigError, type DebugEntry, type DebugKind, EMPTY_OVERRIDES, type EventBatch, EventQueue, type EventQueueOptions, type Experiment, type ExperimentBase, type ExperimentInput, type ExperimentKind, type ExperimentOverride, type ExperimentStatus, type ExposureEvent, type Factor, type Flow, type FlowNode, type FlowOutcome, type Goal, type GoalEvent, type GoalInput, KEYED_FIELDS, MVT_MAX_COMBINATIONS, MVT_MAX_FACTORS, MVT_MAX_LEVELS, type MvtExperimentInput, REMOTE_TTL_MS, type RedirectExperimentInput, type RedirectVariantInput, type RemoteOverrides, SDK_VERSION, type SplitHubClient, type SplitHubConfig, type SplitHubConfigInput, type SplitHubEvent, type StorageInput, TARGET_FIELDS, TARGET_OPS, type TargetCondition, type TargetField, type TargetOp, type TargetingContext, type Transport, type TransportOptions, type ValueExperimentInput, type ValueVariantInput, type Variant, applyRemoteOverrides, assign, browserContext, contextValue, controlVariant, createClient, createFetchTransport, debugLog, debugMode, defineConfig, evaluateCondition, fetchRemoteOverrides, getExperiment, getOrCreateSessionId, getOrCreateVisitorId, hasVisitorId, hashToUnit, inSchedule, isActive, isBrowser, isDebug, isDevDraft, isDevEnvironment, isRemoteOverrides, isSplitHubConfig, matchConditions, murmur3, mvtVariants, newId, newSessionId, newVisitorId, onDebug, parseCookies, parseForceParam, parseUserAgent, pickVariant, readRemoteCache, resolveOverridesUrl, runFlow, validateFlow, writeRemoteCache };
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * cloud all read the same object.
5
5
  */
6
6
  type ExperimentStatus = 'draft' | 'running' | 'paused' | 'finished';
7
- type ExperimentKind = 'component' | 'value' | 'redirect';
7
+ type ExperimentKind = 'component' | 'value' | 'redirect' | 'mvt';
8
8
  /** Weight shorthand (`{ control: 50, bold: 50 }`) or a full variant object. */
9
9
  type ComponentVariantInput = number | {
10
10
  weight: number;
@@ -108,7 +108,18 @@ interface RedirectExperimentInput extends ExperimentBase {
108
108
  match: string;
109
109
  variants: Record<string, RedirectVariantInput>;
110
110
  }
111
- type ExperimentInput = ComponentExperimentInput | ValueExperimentInput | RedirectExperimentInput;
111
+ /**
112
+ * Multivariate: several factors change at once and every combination is a
113
+ * variant. `{ headline: { old: 'Old', new: 'New' }, button: { red: '#f00', green: '#0f0' } }`
114
+ * gives four variants; the first level of every factor is the control. Besides
115
+ * the verdict over combinations, each factor is read on its own (main effects).
116
+ * Keep it small: at most 4 factors, 4 levels each, 16 combinations.
117
+ */
118
+ interface MvtExperimentInput extends ExperimentBase {
119
+ kind: 'mvt';
120
+ factors: Record<string, Record<string, unknown>>;
121
+ }
122
+ type ExperimentInput = ComponentExperimentInput | ValueExperimentInput | RedirectExperimentInput | MvtExperimentInput;
112
123
  type GoalInput = {
113
124
  type: 'event';
114
125
  revenue?: boolean;
@@ -142,6 +153,12 @@ interface SplitHubConfigInput {
142
153
  experiments: Record<string, ExperimentInput>;
143
154
  /** Cookie / localStorage key for the visitor id. Defaults to `sh_vid`. */
144
155
  visitorKey?: string;
156
+ /**
157
+ * Treat `status: 'draft'` experiments as running while the app runs in
158
+ * development (`NODE_ENV === 'development'`: `next dev`, `vite`). Lets you
159
+ * see a test before you start it. Production builds ignore drafts as usual.
160
+ */
161
+ runDraftsInDev?: boolean;
145
162
  }
146
163
  interface Variant {
147
164
  key: string;
@@ -149,6 +166,13 @@ interface Variant {
149
166
  weight: number;
150
167
  value?: unknown;
151
168
  to?: string;
169
+ /** Multivariate: which level of each factor this combination uses. */
170
+ levels?: Record<string, string>;
171
+ }
172
+ /** Multivariate factor: its levels in declared order (the first is the control level). */
173
+ interface Factor {
174
+ key: string;
175
+ levels: string[];
152
176
  }
153
177
  interface Experiment {
154
178
  key: string;
@@ -172,6 +196,8 @@ interface Experiment {
172
196
  origin?: 'config' | 'dashboard';
173
197
  /** Targeting / branching graph; null or absent = plain weights. */
174
198
  flow?: Flow | null;
199
+ /** Multivariate: the factors whose combinations the variants are. */
200
+ factors?: Factor[];
175
201
  }
176
202
  interface Goal {
177
203
  key: string;
@@ -186,6 +212,7 @@ interface SplitHubConfig {
186
212
  project: string;
187
213
  storage: StorageInput;
188
214
  visitorKey: string;
215
+ runDraftsInDev: boolean;
189
216
  goals: Goal[];
190
217
  experiments: Experiment[];
191
218
  /** Branded marker so plain objects are rejected by the SDK. */
@@ -222,13 +249,25 @@ interface Assignment {
222
249
  experiment: string;
223
250
  /** Null when the visitor is outside the traffic share or the experiment is not running. */
224
251
  variant: Variant | null;
225
- /** Why the variant was (not) assigned. Useful for `splithub doctor`. */
226
- reason: 'assigned' | 'not_running' | 'outside_traffic' | 'unknown_experiment' | 'override' | 'targeting';
252
+ /** Why the variant was (not) assigned. Useful for `splithub doctor`. `dev`: a draft served because of `runDraftsInDev`. */
253
+ reason: 'assigned' | 'dev' | 'not_running' | 'outside_traffic' | 'unknown_experiment' | 'override' | 'targeting';
227
254
  }
228
255
 
229
256
  declare class ConfigError extends Error {
230
257
  constructor(message: string);
231
258
  }
259
+ declare const MVT_MAX_FACTORS = 4;
260
+ declare const MVT_MAX_LEVELS = 4;
261
+ declare const MVT_MAX_COMBINATIONS = 16;
262
+ /**
263
+ * Every combination of the factors' levels as a variant, in order (first levels
264
+ * first, so the all-control combination is the control), equal weights. The
265
+ * variant's `value` is `{ factor: levelValue }`, what `useValue()` returns.
266
+ */
267
+ declare function mvtVariants(expKey: string, factors: Record<string, Record<string, unknown>>): {
268
+ variants: Variant[];
269
+ factors: Factor[];
270
+ };
232
271
  /**
233
272
  * Validate and normalize a config. Call it once in `splithub.config.ts`:
234
273
  *
@@ -240,6 +279,16 @@ declare function defineConfig(input: SplitHubConfigInput): SplitHubConfig;
240
279
  declare function isSplitHubConfig(value: unknown): value is SplitHubConfig;
241
280
  declare function getExperiment(config: SplitHubConfig, key: string): Experiment | undefined;
242
281
 
282
+ /**
283
+ * True in `next dev` / `vite` and on the server of a dev build. Bundlers
284
+ * replace `process.env.NODE_ENV` with a literal, so the expression is kept
285
+ * verbatim; where nothing replaces it and no `process` exists, it is false.
286
+ */
287
+ declare function isDevEnvironment(): boolean;
288
+ /** A draft shown in development because the config says `runDraftsInDev: true`. */
289
+ declare function isDevDraft(config: Pick<SplitHubConfig, 'runDraftsInDev'>, experiment: Pick<Experiment, 'status'>): boolean;
290
+ /** Running now, or a draft served in development. What the middleware and the drop-in script check before assigning. */
291
+ declare function isActive(config: Pick<SplitHubConfig, 'runDraftsInDev'>, experiment: Pick<Experiment, 'status' | 'schedule'>, now?: number): boolean;
243
292
  /**
244
293
  * Deterministic bucketing. Same visitor + same experiment + same seed always
245
294
  * yields the same variant, on any runtime, with no network call.
@@ -470,4 +519,4 @@ declare function debugLog(kind: DebugKind, message: string, data?: Record<string
470
519
  /** Subscribe to debug entries (the devtools panel). Returns an unsubscribe function. */
471
520
  declare function onDebug(listener: (e: DebugEntry) => void): () => void;
472
521
 
473
- export { type AssignOptions, type Assignment, CLOUD_ENDPOINT, type ClientOptions, type ComponentExperimentInput, type ComponentVariantInput, ConfigError, type DebugEntry, type DebugKind, EMPTY_OVERRIDES, type EventBatch, EventQueue, type EventQueueOptions, type Experiment, type ExperimentBase, type ExperimentInput, type ExperimentKind, type ExperimentOverride, type ExperimentStatus, type ExposureEvent, type Flow, type FlowNode, type FlowOutcome, type Goal, type GoalEvent, type GoalInput, KEYED_FIELDS, REMOTE_TTL_MS, type RedirectExperimentInput, type RedirectVariantInput, type RemoteOverrides, SDK_VERSION, type SplitHubClient, type SplitHubConfig, type SplitHubConfigInput, type SplitHubEvent, type StorageInput, TARGET_FIELDS, TARGET_OPS, type TargetCondition, type TargetField, type TargetOp, type TargetingContext, type Transport, type TransportOptions, type ValueExperimentInput, type ValueVariantInput, type Variant, applyRemoteOverrides, assign, browserContext, contextValue, controlVariant, createClient, createFetchTransport, debugLog, debugMode, defineConfig, evaluateCondition, fetchRemoteOverrides, getExperiment, getOrCreateSessionId, getOrCreateVisitorId, hasVisitorId, hashToUnit, inSchedule, isBrowser, isDebug, isRemoteOverrides, isSplitHubConfig, matchConditions, murmur3, newId, newSessionId, newVisitorId, onDebug, parseCookies, parseForceParam, parseUserAgent, pickVariant, readRemoteCache, resolveOverridesUrl, runFlow, validateFlow, writeRemoteCache };
522
+ export { type AssignOptions, type Assignment, CLOUD_ENDPOINT, type ClientOptions, type ComponentExperimentInput, type ComponentVariantInput, ConfigError, type DebugEntry, type DebugKind, EMPTY_OVERRIDES, type EventBatch, EventQueue, type EventQueueOptions, type Experiment, type ExperimentBase, type ExperimentInput, type ExperimentKind, type ExperimentOverride, type ExperimentStatus, type ExposureEvent, type Factor, type Flow, type FlowNode, type FlowOutcome, type Goal, type GoalEvent, type GoalInput, KEYED_FIELDS, MVT_MAX_COMBINATIONS, MVT_MAX_FACTORS, MVT_MAX_LEVELS, type MvtExperimentInput, REMOTE_TTL_MS, type RedirectExperimentInput, type RedirectVariantInput, type RemoteOverrides, SDK_VERSION, type SplitHubClient, type SplitHubConfig, type SplitHubConfigInput, type SplitHubEvent, type StorageInput, TARGET_FIELDS, TARGET_OPS, type TargetCondition, type TargetField, type TargetOp, type TargetingContext, type Transport, type TransportOptions, type ValueExperimentInput, type ValueVariantInput, type Variant, applyRemoteOverrides, assign, browserContext, contextValue, controlVariant, createClient, createFetchTransport, debugLog, debugMode, defineConfig, evaluateCondition, fetchRemoteOverrides, getExperiment, getOrCreateSessionId, getOrCreateVisitorId, hasVisitorId, hashToUnit, inSchedule, isActive, isBrowser, isDebug, isDevDraft, isDevEnvironment, isRemoteOverrides, isSplitHubConfig, matchConditions, murmur3, mvtVariants, newId, newSessionId, newVisitorId, onDebug, parseCookies, parseForceParam, parseUserAgent, pickVariant, readRemoteCache, resolveOverridesUrl, runFlow, validateFlow, writeRemoteCache };
package/dist/index.js CHANGED
@@ -308,7 +308,36 @@ function assertKey(kind, key) {
308
308
  );
309
309
  }
310
310
  }
311
+ var MVT_MAX_FACTORS = 4;
312
+ var MVT_MAX_LEVELS = 4;
313
+ var MVT_MAX_COMBINATIONS = 16;
314
+ function mvtVariants(expKey, factors) {
315
+ const list2 = [];
316
+ const valuesOf = /* @__PURE__ */ new Map();
317
+ for (const [key, levels] of Object.entries(factors ?? {})) {
318
+ assertKey("factor", key);
319
+ const levelKeys = Object.keys(levels ?? {});
320
+ if (levelKeys.length < 2) throw new ConfigError(`experiment "${expKey}", factor "${key}": needs at least 2 levels.`);
321
+ if (levelKeys.length > MVT_MAX_LEVELS) throw new ConfigError(`experiment "${expKey}", factor "${key}": at most ${MVT_MAX_LEVELS} levels.`);
322
+ for (const l of levelKeys) assertKey("level", l);
323
+ list2.push({ key, levels: levelKeys });
324
+ valuesOf.set(key, levels);
325
+ }
326
+ if (list2.length === 0) throw new ConfigError(`experiment "${expKey}": mvt experiments need "factors".`);
327
+ if (list2.length > MVT_MAX_FACTORS) throw new ConfigError(`experiment "${expKey}": at most ${MVT_MAX_FACTORS} factors.`);
328
+ let combos = [{}];
329
+ for (const f of list2) combos = combos.flatMap((c) => f.levels.map((l) => ({ ...c, [f.key]: l })));
330
+ if (combos.length > MVT_MAX_COMBINATIONS) throw new ConfigError(`experiment "${expKey}": ${combos.length} combinations; at most ${MVT_MAX_COMBINATIONS}.`);
331
+ const variants = combos.map((levels) => ({
332
+ key: list2.map((f) => levels[f.key]).join("-"),
333
+ weight: 1 / combos.length,
334
+ value: Object.fromEntries(list2.map((f) => [f.key, valuesOf.get(f.key)[levels[f.key]]])),
335
+ levels
336
+ }));
337
+ return { variants, factors: list2 };
338
+ }
311
339
  function normalizeVariants(expKey, input) {
340
+ if (input.kind === "mvt") return mvtVariants(expKey, input.factors).variants;
312
341
  const entries = Object.entries(input.variants);
313
342
  if (entries.length < 2) {
314
343
  throw new ConfigError(`experiment "${expKey}" needs at least 2 variants.`);
@@ -364,6 +393,7 @@ function normalizeExperiment(key, input, goals) {
364
393
  description: input.description ?? null,
365
394
  match: input.kind === "redirect" ? input.match : null,
366
395
  variants,
396
+ ...input.kind === "mvt" ? { factors: mvtVariants(key, input.factors).factors } : {},
367
397
  ...input.flow ? { flow: input.flow } : {},
368
398
  ...input.maxExposures ? { maxExposures: Math.floor(input.maxExposures) } : {},
369
399
  ...input.schedule && (input.schedule.startAt || input.schedule.endAt) ? { schedule: { startAt: input.schedule.startAt ?? null, endAt: input.schedule.endAt ?? null } } : {}
@@ -394,6 +424,7 @@ function defineConfig(input) {
394
424
  project: input.project,
395
425
  storage: input.storage,
396
426
  visitorKey: input.visitorKey ?? "sh_vid",
427
+ runDraftsInDev: input.runDraftsInDev === true,
397
428
  goals,
398
429
  experiments,
399
430
  __splithub: 2
@@ -407,6 +438,19 @@ function getExperiment(config, key) {
407
438
  }
408
439
 
409
440
  // src/assignment.ts
441
+ function isDevEnvironment() {
442
+ try {
443
+ return process.env.NODE_ENV === "development";
444
+ } catch {
445
+ return false;
446
+ }
447
+ }
448
+ function isDevDraft(config, experiment) {
449
+ return experiment.status === "draft" && config.runDraftsInDev && isDevEnvironment();
450
+ }
451
+ function isActive(config, experiment, now) {
452
+ return experiment.status === "running" && inSchedule(experiment, now) || isDevDraft(config, experiment);
453
+ }
410
454
  function pickVariant(experiment, visitorId) {
411
455
  const trafficUnit = hashToUnit(`${experiment.seed}:${experiment.key}:traffic:${visitorId}`);
412
456
  if (trafficUnit >= experiment.traffic) return null;
@@ -426,18 +470,20 @@ function assign(config, experimentKey, visitorId, options = {}) {
426
470
  const variant2 = experiment.variants.find((v) => v.key === forced) ?? null;
427
471
  if (variant2) return { experiment: experimentKey, variant: variant2, reason: "override" };
428
472
  }
429
- if (experiment.status !== "running" || !inSchedule(experiment, options.context?.now)) {
473
+ const devDraft = isDevDraft(config, experiment);
474
+ if (!devDraft && (experiment.status !== "running" || !inSchedule(experiment, options.context?.now))) {
430
475
  return { experiment: experimentKey, variant: null, reason: "not_running" };
431
476
  }
477
+ const reason = devDraft ? "dev" : "assigned";
432
478
  if (experiment.flow) {
433
479
  const trafficUnit = hashToUnit(`${experiment.seed}:${experiment.key}:traffic:${visitorId}`);
434
480
  if (trafficUnit >= experiment.traffic) return { experiment: experimentKey, variant: null, reason: "outside_traffic" };
435
481
  const outcome = runFlow(experiment, experiment.flow, visitorId, options.context ?? {});
436
- return outcome.variant ? { experiment: experimentKey, variant: outcome.variant, reason: "assigned" } : { experiment: experimentKey, variant: null, reason: "targeting" };
482
+ return outcome.variant ? { experiment: experimentKey, variant: outcome.variant, reason } : { experiment: experimentKey, variant: null, reason: "targeting" };
437
483
  }
438
484
  const variant = pickVariant(experiment, visitorId);
439
485
  if (!variant) return { experiment: experimentKey, variant: null, reason: "outside_traffic" };
440
- return { experiment: experimentKey, variant, reason: "assigned" };
486
+ return { experiment: experimentKey, variant, reason };
441
487
  }
442
488
  function inSchedule(experiment, now = Date.now()) {
443
489
  const s = experiment.schedule;
@@ -921,6 +967,9 @@ export {
921
967
  EMPTY_OVERRIDES,
922
968
  EventQueue,
923
969
  KEYED_FIELDS,
970
+ MVT_MAX_COMBINATIONS,
971
+ MVT_MAX_FACTORS,
972
+ MVT_MAX_LEVELS,
924
973
  REMOTE_TTL_MS,
925
974
  SDK_VERSION,
926
975
  TARGET_FIELDS,
@@ -943,12 +992,16 @@ export {
943
992
  hasVisitorId,
944
993
  hashToUnit,
945
994
  inSchedule,
995
+ isActive,
946
996
  isBrowser,
947
997
  isDebug,
998
+ isDevDraft,
999
+ isDevEnvironment,
948
1000
  isRemoteOverrides,
949
1001
  isSplitHubConfig,
950
1002
  matchConditions,
951
1003
  murmur3,
1004
+ mvtVariants,
952
1005
  newId,
953
1006
  newSessionId,
954
1007
  newVisitorId,