@funnelsgrove/runtime 0.1.47 → 0.1.48

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.
@@ -1,9 +1,30 @@
1
1
  import { resolveExperimentVariant } from './posthog-flags.js';
2
+ const resolveForcedVariant = (input) => {
3
+ var _a, _b;
4
+ if (typeof window === 'undefined') {
5
+ return null;
6
+ }
7
+ try {
8
+ const params = new URLSearchParams(window.location.search);
9
+ if (params.get('mode') !== 'test' || params.get('experiment') !== input.experimentId) {
10
+ return null;
11
+ }
12
+ const variantKey = (_a = params.get('variant')) === null || _a === void 0 ? void 0 : _a.trim();
13
+ return variantKey ? (_b = input.variants.find((variant) => variant.variantKey === variantKey)) !== null && _b !== void 0 ? _b : null : null;
14
+ }
15
+ catch (_c) {
16
+ return null;
17
+ }
18
+ };
2
19
  export const resolveExperimentAssignment = (input) => {
3
20
  var _a;
4
21
  if (input.variants.length === 0) {
5
22
  return null;
6
23
  }
24
+ const forcedVariant = resolveForcedVariant(input);
25
+ if (forcedVariant) {
26
+ return { variantKey: forcedVariant.variantKey, routeToStepId: forcedVariant.routeToStepId };
27
+ }
7
28
  const resolved = resolveExperimentVariant(input.experimentId);
8
29
  const match = resolved ? input.variants.find((variant) => variant.variantKey === resolved) : undefined;
9
30
  if (match) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/runtime",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",