@funnelsgrove/runtime 0.1.24 → 0.1.25
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,6 +1,16 @@
|
|
|
1
1
|
import type { FunnelManifest, FunnelManifestExperiment } from '../config/funnel.manifest.types.js';
|
|
2
2
|
export type FunnelStepId = string;
|
|
3
|
+
export type FunnelStepOrderGraph = {
|
|
4
|
+
steps: readonly {
|
|
5
|
+
id: string;
|
|
6
|
+
}[];
|
|
7
|
+
entryPointStepIds?: readonly string[];
|
|
8
|
+
edgesByStepId?: Partial<Record<string, readonly {
|
|
9
|
+
toStepId: string;
|
|
10
|
+
}[]>>;
|
|
11
|
+
};
|
|
3
12
|
export declare const getFunnelStepSequence: (manifest: FunnelManifest) => FunnelStepId[];
|
|
13
|
+
export declare const getFunnelStepIdsByEdgeOrder: (graph: FunnelStepOrderGraph) => FunnelStepId[];
|
|
4
14
|
export declare const getFunnelEntryPoints: (manifest: FunnelManifest) => {
|
|
5
15
|
stepId: FunnelStepId;
|
|
6
16
|
id: string;
|
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
import { getChoiceTargetsFromEdges, isManifestStepId, resolveInitialStepId, resolveNextStepId, } from './route-resolver.js';
|
|
2
2
|
export const getFunnelStepSequence = (manifest) => manifest.steps.map((step) => step.id);
|
|
3
|
+
export const getFunnelStepIdsByEdgeOrder = (graph) => {
|
|
4
|
+
const stepIds = graph.steps.map((step) => step.id).filter(Boolean);
|
|
5
|
+
const firstStepId = stepIds[0];
|
|
6
|
+
if (!firstStepId || !graph.edgesByStepId || Object.keys(graph.edgesByStepId).length === 0) {
|
|
7
|
+
return stepIds;
|
|
8
|
+
}
|
|
9
|
+
const stepIdSet = new Set(stepIds);
|
|
10
|
+
const orderedStepIds = [];
|
|
11
|
+
const visitedStepIds = new Set();
|
|
12
|
+
const visit = (stepId) => {
|
|
13
|
+
var _a;
|
|
14
|
+
if (!stepIdSet.has(stepId) || visitedStepIds.has(stepId)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
visitedStepIds.add(stepId);
|
|
18
|
+
orderedStepIds.push(stepId);
|
|
19
|
+
for (const edge of ((_a = graph.edgesByStepId) === null || _a === void 0 ? void 0 : _a[stepId]) || []) {
|
|
20
|
+
visit(edge.toStepId);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
visit(firstStepId);
|
|
24
|
+
for (const entryPointStepId of graph.entryPointStepIds || []) {
|
|
25
|
+
visit(entryPointStepId);
|
|
26
|
+
}
|
|
27
|
+
return orderedStepIds.length > 0 ? orderedStepIds : stepIds;
|
|
28
|
+
};
|
|
3
29
|
export const getFunnelEntryPoints = (manifest) => (manifest.entryPoints || []).map((entryPoint) => (Object.assign(Object.assign({}, entryPoint), { stepId: entryPoint.stepId })));
|
|
4
30
|
export const getFunnelExperiments = (manifest) => manifest.experiments.map((experiment) => (Object.assign(Object.assign({}, experiment), { stepId: experiment.stepId, variants: experiment.variants.map((variant) => (Object.assign(Object.assign({}, variant), { routeToStepId: variant.routeToStepId }))) })));
|
|
5
31
|
export const getDefaultFunnelStepId = (manifest) => getFunnelStepSequence(manifest)[0];
|