@boboddy/sdk 0.3.1 → 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/client.js CHANGED
@@ -1069,7 +1069,7 @@ class StepExecutions extends HeyApiClient {
1069
1069
  class PipelineDefinitions extends HeyApiClient {
1070
1070
  createPipelineDefinition(options) {
1071
1071
  return (options.client ?? this.client).post({
1072
- url: "/api/linear-pipeline-definitions",
1072
+ url: "/api/pipeline-definitions",
1073
1073
  ...options,
1074
1074
  headers: {
1075
1075
  "Content-Type": "application/json",
@@ -1079,7 +1079,7 @@ class PipelineDefinitions extends HeyApiClient {
1079
1079
  }
1080
1080
  upsertPipelineDefinition(options) {
1081
1081
  return (options.client ?? this.client).put({
1082
- url: "/api/linear-pipeline-definitions",
1082
+ url: "/api/pipeline-definitions",
1083
1083
  ...options,
1084
1084
  headers: {
1085
1085
  "Content-Type": "application/json",
@@ -1088,14 +1088,14 @@ class PipelineDefinitions extends HeyApiClient {
1088
1088
  });
1089
1089
  }
1090
1090
  archivePipelineDefinition(options) {
1091
- return (options.client ?? this.client).put({ url: "/api/linear-pipeline-definitions/{linearPipelineDefinitionId}/archive", ...options });
1091
+ return (options.client ?? this.client).put({ url: "/api/pipeline-definitions/{pipelineDefinitionId}/archive", ...options });
1092
1092
  }
1093
1093
  unarchivePipelineDefinition(options) {
1094
- return (options.client ?? this.client).put({ url: "/api/linear-pipeline-definitions/{linearPipelineDefinitionId}/unarchive", ...options });
1094
+ return (options.client ?? this.client).put({ url: "/api/pipeline-definitions/{pipelineDefinitionId}/unarchive", ...options });
1095
1095
  }
1096
1096
  addPipelineStep(options) {
1097
1097
  return (options.client ?? this.client).post({
1098
- url: "/api/linear-pipeline-definitions/{linearPipelineDefinitionId}/steps",
1098
+ url: "/api/pipeline-definitions/{pipelineDefinitionId}/steps",
1099
1099
  ...options,
1100
1100
  headers: {
1101
1101
  "Content-Type": "application/json",
@@ -1104,11 +1104,11 @@ class PipelineDefinitions extends HeyApiClient {
1104
1104
  });
1105
1105
  }
1106
1106
  removePipelineStep(options) {
1107
- return (options.client ?? this.client).delete({ url: "/api/linear-pipeline-definitions/{linearPipelineDefinitionId}/steps/{linearPipelineStepDefinitionId}", ...options });
1107
+ return (options.client ?? this.client).delete({ url: "/api/pipeline-definitions/{pipelineDefinitionId}/steps/{pipelineStepDefinitionId}", ...options });
1108
1108
  }
1109
1109
  updatePipelineStep(options) {
1110
1110
  return (options.client ?? this.client).put({
1111
- url: "/api/linear-pipeline-definitions/{linearPipelineDefinitionId}/steps/{linearPipelineStepDefinitionId}",
1111
+ url: "/api/pipeline-definitions/{pipelineDefinitionId}/steps/{pipelineStepDefinitionId}",
1112
1112
  ...options,
1113
1113
  headers: {
1114
1114
  "Content-Type": "application/json",
@@ -1118,7 +1118,7 @@ class PipelineDefinitions extends HeyApiClient {
1118
1118
  }
1119
1119
  setPipelineStepAdvancementPolicy(options) {
1120
1120
  return (options.client ?? this.client).put({
1121
- url: "/api/linear-pipeline-definitions/{linearPipelineDefinitionId}/steps/{linearPipelineStepDefinitionId}/advancement-policy",
1121
+ url: "/api/pipeline-definitions/{pipelineDefinitionId}/steps/{pipelineStepDefinitionId}/advancement-policy",
1122
1122
  ...options,
1123
1123
  headers: {
1124
1124
  "Content-Type": "application/json",
@@ -1127,20 +1127,20 @@ class PipelineDefinitions extends HeyApiClient {
1127
1127
  });
1128
1128
  }
1129
1129
  getPipelineDefinition(options) {
1130
- return (options.client ?? this.client).get({ url: "/api/linear-pipeline-definitions/{linearPipelineDefinitionId}", ...options });
1130
+ return (options.client ?? this.client).get({ url: "/api/pipeline-definitions/{pipelineDefinitionId}", ...options });
1131
1131
  }
1132
1132
  listPipelineDefinitions(options) {
1133
- return (options.client ?? this.client).get({ url: "/api/projects/{projectId}/linear-pipeline-definitions", ...options });
1133
+ return (options.client ?? this.client).get({ url: "/api/projects/{projectId}/pipeline-definitions", ...options });
1134
1134
  }
1135
1135
  }
1136
1136
 
1137
1137
  class PipelineExecutions extends HeyApiClient {
1138
1138
  listPipelineExecutions(options) {
1139
- return (options.client ?? this.client).get({ url: "/api/linear-pipeline-executions", ...options });
1139
+ return (options.client ?? this.client).get({ url: "/api/pipeline-executions", ...options });
1140
1140
  }
1141
1141
  createPipelineExecution(options) {
1142
1142
  return (options.client ?? this.client).post({
1143
- url: "/api/linear-pipeline-executions",
1143
+ url: "/api/pipeline-executions",
1144
1144
  ...options,
1145
1145
  headers: {
1146
1146
  "Content-Type": "application/json",
@@ -1149,17 +1149,17 @@ class PipelineExecutions extends HeyApiClient {
1149
1149
  });
1150
1150
  }
1151
1151
  startPipelineExecution(options) {
1152
- return (options.client ?? this.client).put({ url: "/api/linear-pipeline-executions/{linearPipelineExecutionId}/start", ...options });
1152
+ return (options.client ?? this.client).put({ url: "/api/pipeline-executions/{pipelineExecutionId}/start", ...options });
1153
1153
  }
1154
1154
  queueFirstPipelineStepRun(options) {
1155
- return (options.client ?? this.client).post({ url: "/api/linear-pipeline-executions/{linearPipelineExecutionId}/step-runs/first", ...options });
1155
+ return (options.client ?? this.client).post({ url: "/api/pipeline-executions/{pipelineExecutionId}/step-runs/first", ...options });
1156
1156
  }
1157
1157
  markPipelineStepRunRunning(options) {
1158
- return (options.client ?? this.client).put({ url: "/api/linear-pipeline-executions/{linearPipelineExecutionId}/step-runs/{linearPipelineStepRunId}/running", ...options });
1158
+ return (options.client ?? this.client).put({ url: "/api/pipeline-executions/{pipelineExecutionId}/step-runs/{pipelineStepRunId}/running", ...options });
1159
1159
  }
1160
1160
  applyPipelineStepResult(options) {
1161
1161
  return (options.client ?? this.client).post({
1162
- url: "/api/linear-pipeline-executions/{linearPipelineExecutionId}/step-runs/{linearPipelineStepRunId}/results",
1162
+ url: "/api/pipeline-executions/{pipelineExecutionId}/step-runs/{pipelineStepRunId}/results",
1163
1163
  ...options,
1164
1164
  headers: {
1165
1165
  "Content-Type": "application/json",
@@ -1169,7 +1169,17 @@ class PipelineExecutions extends HeyApiClient {
1169
1169
  }
1170
1170
  acceptPipelineStepRun(options) {
1171
1171
  return (options.client ?? this.client).post({
1172
- url: "/api/linear-pipeline-executions/{linearPipelineExecutionId}/step-runs/{linearPipelineStepRunId}/accept",
1172
+ url: "/api/pipeline-executions/{pipelineExecutionId}/step-runs/{pipelineStepRunId}/accept",
1173
+ ...options,
1174
+ headers: {
1175
+ "Content-Type": "application/json",
1176
+ ...options.headers
1177
+ }
1178
+ });
1179
+ }
1180
+ acceptPipelineCohort(options) {
1181
+ return (options.client ?? this.client).post({
1182
+ url: "/api/pipeline-executions/{pipelineExecutionId}/cohorts/{originNodeDefinitionId}/accept",
1173
1183
  ...options,
1174
1184
  headers: {
1175
1185
  "Content-Type": "application/json",
@@ -1179,7 +1189,7 @@ class PipelineExecutions extends HeyApiClient {
1179
1189
  }
1180
1190
  rerunPipelineExecution(options) {
1181
1191
  return (options.client ?? this.client).post({
1182
- url: "/api/linear-pipeline-executions/{linearPipelineExecutionId}/rerun",
1192
+ url: "/api/pipeline-executions/{pipelineExecutionId}/rerun",
1183
1193
  ...options,
1184
1194
  headers: {
1185
1195
  "Content-Type": "application/json",
@@ -1188,19 +1198,22 @@ class PipelineExecutions extends HeyApiClient {
1188
1198
  });
1189
1199
  }
1190
1200
  cancelPipelineExecution(options) {
1191
- return (options.client ?? this.client).put({ url: "/api/linear-pipeline-executions/{linearPipelineExecutionId}/cancel", ...options });
1201
+ return (options.client ?? this.client).put({ url: "/api/pipeline-executions/{pipelineExecutionId}/cancel", ...options });
1192
1202
  }
1193
1203
  getPipelineExecution(options) {
1194
- return (options.client ?? this.client).get({ url: "/api/linear-pipeline-executions/{linearPipelineExecutionId}", ...options });
1204
+ return (options.client ?? this.client).get({ url: "/api/pipeline-executions/{pipelineExecutionId}", ...options });
1205
+ }
1206
+ getPipelineExecutionRoutedChain(options) {
1207
+ return (options.client ?? this.client).get({ url: "/api/pipeline-executions/{pipelineExecutionId}/routed-chain", ...options });
1195
1208
  }
1196
1209
  countPipelineExecutionsByPipeline(options) {
1197
- return (options.client ?? this.client).get({ url: "/api/linear-pipeline-executions/counts/by-pipeline", ...options });
1210
+ return (options.client ?? this.client).get({ url: "/api/pipeline-executions/counts/by-pipeline", ...options });
1198
1211
  }
1199
1212
  listPipelineDefinitionStepRollups(options) {
1200
- return (options.client ?? this.client).get({ url: "/api/linear-pipeline-executions/step-rollups/by-definition/{linearPipelineDefinitionId}", ...options });
1213
+ return (options.client ?? this.client).get({ url: "/api/pipeline-executions/step-rollups/by-definition/{pipelineDefinitionId}", ...options });
1201
1214
  }
1202
1215
  listPipelineDefinitionStepRuns(options) {
1203
- return (options.client ?? this.client).get({ url: "/api/linear-pipeline-executions/step-runs/by-definition/{linearPipelineDefinitionId}", ...options });
1216
+ return (options.client ?? this.client).get({ url: "/api/pipeline-executions/step-runs/by-definition/{pipelineDefinitionId}", ...options });
1204
1217
  }
1205
1218
  }
1206
1219
 
@@ -0,0 +1,117 @@
1
+ /** Restricted outcome domain for both `advanceEach` and `advanceAll`. */
2
+ export declare const cohortAdvancementEventTypeValues: readonly ["continue", "block"];
3
+ export type CohortAdvancementEventType = (typeof cohortAdvancementEventTypeValues)[number];
4
+ export type StepSignalsListConditionOperator = "equal" | "notEqual" | "lessThan" | "lessThanInclusive" | "greaterThan" | "greaterThanInclusive" | "in" | "notIn" | "contains" | "doesNotContain";
5
+ export type StepSignalsListTransformOp = {
6
+ op: "pluck";
7
+ signalKey: string;
8
+ } | {
9
+ op: "filter";
10
+ operator: StepSignalsListConditionOperator;
11
+ value: unknown;
12
+ } | {
13
+ op: "sortBy";
14
+ direction: "asc" | "desc";
15
+ } | {
16
+ op: "unique";
17
+ };
18
+ export type StepSignalsListReducerOp = {
19
+ op: "count";
20
+ } | {
21
+ op: "sum";
22
+ } | {
23
+ op: "avg";
24
+ } | {
25
+ op: "min";
26
+ } | {
27
+ op: "max";
28
+ } | {
29
+ op: "booleanAll";
30
+ } | {
31
+ op: "booleanAny";
32
+ } | {
33
+ op: "join";
34
+ separator: string;
35
+ } | {
36
+ op: "first";
37
+ } | {
38
+ op: "last";
39
+ };
40
+ /** Wire-format `ctx.stepSignalsList`-derived value, hoisted onto the `cohortGate` node. */
41
+ export type SerializedStepSignalsListDefinition = {
42
+ key: string;
43
+ ops: StepSignalsListTransformOp[];
44
+ reducer: StepSignalsListReducerOp;
45
+ };
46
+ /**
47
+ * An inline `ctx.stepSignalsList`-derived token, embedded in a rule's
48
+ * condition tree at the position a signal key would normally go. At
49
+ * serialize time, hoisted into the `cohortGate` node's
50
+ * `stepSignalsListDefinitions` and replaced by its bare `key` — the same
51
+ * "author inline, hoist, replace with bare key" discipline
52
+ * `extractInlineComputedSignals` already runs for `Computed.*`.
53
+ */
54
+ export type InlineStepSignalsListValue<TKey extends string = string> = {
55
+ readonly _tag: "step_signals_list";
56
+ readonly key: TKey;
57
+ readonly ops: StepSignalsListTransformOp[];
58
+ readonly reducer: StepSignalsListReducerOp;
59
+ };
60
+ /**
61
+ * A leaf condition, restricted to the cohort's own fact vocabulary: a bare
62
+ * fact name (`branchOutcomes.total()`/`.count(outcome)`, or a
63
+ * `ctx.stepSignalsList`-derived key) or an inline `InlineStepSignalsListValue`
64
+ * token (hoisted at serialize time). `value` may itself be a dynamic
65
+ * fact-reference (`{ fact: "branchCount" }`) — the same
66
+ * json-rules-engine-native mechanism `branchOutcomes.every()` compiles to.
67
+ */
68
+ export type CohortSignalCondition = {
69
+ readonly _tag: "signal";
70
+ signal: string | InlineStepSignalsListValue;
71
+ operator: StepSignalsListConditionOperator;
72
+ value: unknown;
73
+ };
74
+ export type CohortAllCondition = {
75
+ readonly _tag: "all";
76
+ conditions: CohortRuleCondition[];
77
+ };
78
+ export type CohortAnyCondition = {
79
+ readonly _tag: "any";
80
+ conditions: CohortRuleCondition[];
81
+ };
82
+ export type CohortRuleCondition = CohortSignalCondition | CohortAllCondition | CohortAnyCondition;
83
+ export type CohortRule = {
84
+ readonly _tag: "rule";
85
+ mode: "all" | "any";
86
+ conditions: CohortRuleCondition[];
87
+ outcome: CohortAdvancementEventType;
88
+ outcomeJson?: Record<string, unknown> | null;
89
+ };
90
+ export type SerializedCohortRule = {
91
+ conditions: Record<string, unknown>;
92
+ event: {
93
+ type: CohortAdvancementEventType;
94
+ params?: Record<string, unknown>;
95
+ };
96
+ };
97
+ /** Serialized shape expected by core's `CohortAdvancementPolicyDefinition`. */
98
+ export type SerializedCohortAdvancementPolicy = {
99
+ rules: SerializedCohortRule[];
100
+ defaultEventType: CohortAdvancementEventType;
101
+ defaultEventParamsJson: Record<string, unknown> | null;
102
+ };
103
+ export type CohortAdvancementPolicy = {
104
+ default: CohortAdvancementEventType;
105
+ defaultParamsJson?: Record<string, unknown> | null;
106
+ rules?: CohortRule[];
107
+ };
108
+ /** Serializes an authored `CohortAdvancementPolicy` (`advanceEach`/`advanceAll`) to its wire shape. */
109
+ export declare function serializeCohortAdvancementPolicy(policy: CohortAdvancementPolicy | undefined): SerializedCohortAdvancementPolicy;
110
+ /**
111
+ * Walks a `CohortAdvancementPolicy`'s rules tree, extracts every inline
112
+ * `ctx.stepSignalsList`-derived token embedded in a `CohortSignalCondition
113
+ * .signal` position, dedupes by key, and returns the resulting
114
+ * `stepSignalsListDefinitions` — the `cohortGate` node's counterpart to
115
+ * `extractInlineComputedSignals`.
116
+ */
117
+ export declare function extractInlineStepSignalsListDefinitions(policy: CohortAdvancementPolicy | undefined): SerializedStepSignalsListDefinition[];
@@ -0,0 +1,126 @@
1
+ import { type CohortAdvancementEventType, type CohortRule, type CohortRuleCondition, type CohortSignalCondition, type StepSignalsListConditionOperator } from "./cohort-advancement-policy";
2
+ declare const LEAF_BRAND: unique symbol;
3
+ declare const GROUP_BRAND: unique symbol;
4
+ /**
5
+ * A leaf condition + outcome attacher for the cohort scope
6
+ * (`advanceEach`/`advanceAll`). Built by `signal(key).<op>(value)`,
7
+ * `stepSignalsList.pluck(...).<reducer>()`, or `branchOutcomes.total()`/
8
+ * `.count(...)` chained with a comparator. Nestable inside `all()`/`any()`,
9
+ * or terminable with `.then(outcome)` — restricted to `continue`/`block`
10
+ * (AC4: no `route`/`complete`, unlike a regular step's `RuleLeaf`).
11
+ */
12
+ export interface CohortRuleLeaf {
13
+ readonly [LEAF_BRAND]: CohortSignalCondition;
14
+ then(outcome: CohortAdvancementEventType, paramsJson?: Record<string, unknown>): CohortRule;
15
+ }
16
+ /** A grouped condition + outcome attacher. Built by `all(...)` or `any(...)`. */
17
+ export interface CohortRuleGroup {
18
+ readonly [GROUP_BRAND]: {
19
+ mode: "all" | "any";
20
+ conditions: CohortRuleCondition[];
21
+ };
22
+ then(outcome: CohortAdvancementEventType, paramsJson?: Record<string, unknown>): CohortRule;
23
+ }
24
+ type CohortNestable = CohortRuleLeaf | CohortRuleGroup;
25
+ /**
26
+ * A comparator-bound reference into the cohort scope's facts — a branch's
27
+ * own signal (`advanceEach`), a `branchOutcomes.total()`/`.count(outcome)`
28
+ * aggregate, or a `stepSignalsList` reducer's result (`advanceAll`).
29
+ * Calling any comparator produces a `CohortRuleLeaf`.
30
+ */
31
+ export interface CohortSignalRef<TValue = unknown> {
32
+ eq(value: TValue): CohortRuleLeaf;
33
+ ne(value: TValue): CohortRuleLeaf;
34
+ gt(value: number): CohortRuleLeaf;
35
+ gte(value: number): CohortRuleLeaf;
36
+ lt(value: number): CohortRuleLeaf;
37
+ lte(value: number): CohortRuleLeaf;
38
+ in(values: ReadonlyArray<TValue>): CohortRuleLeaf;
39
+ notIn(values: ReadonlyArray<TValue>): CohortRuleLeaf;
40
+ contains(value: unknown): CohortRuleLeaf;
41
+ doesNotContain(value: unknown): CohortRuleLeaf;
42
+ }
43
+ type SignalValue<TSignalKeys extends string, TSignalTypeMap extends Partial<Record<string, unknown>>, K extends TSignalKeys> = K extends keyof TSignalTypeMap ? TSignalTypeMap[K] : unknown;
44
+ /**
45
+ * `advanceEach`'s callback context: one fan-out branch's own step result,
46
+ * evaluated the same way a regular step's `.advance()` evaluates its own
47
+ * signals (`evaluateBranchAgainstPolicy` — the same shared rules-engine
48
+ * pass, just restricted to `continue`/`block`). No `route`/`complete`, and
49
+ * — unlike `.advance()`'s `AdvanceCtx` — no `avg`/`sum`/`min`/`max`/`count`/
50
+ * `booleanAny`/`booleanAll` computed-signal factories: core's `fanOut` node
51
+ * config has no `computedSignalDefinitions` field to hoist them onto and
52
+ * `evaluateBranchAgainstPolicy` never resolves them, so exposing them here
53
+ * would silently produce dead wire fields. A later ticket can add that
54
+ * support to core first, then extend this ctx to match.
55
+ */
56
+ export interface AdvanceEachCtx<TSignalKeys extends string = string, TSignalTypeMap extends Partial<Record<string, unknown>> = Record<string, unknown>> {
57
+ signal<K extends TSignalKeys>(key: K): CohortSignalRef<SignalValue<TSignalKeys, TSignalTypeMap, K>>;
58
+ stepSignals: {
59
+ [K in TSignalKeys]: CohortSignalRef<SignalValue<TSignalKeys, TSignalTypeMap, K>>;
60
+ };
61
+ all(...refs: CohortNestable[]): CohortRuleGroup;
62
+ any(...refs: CohortNestable[]): CohortRuleGroup;
63
+ }
64
+ export interface AdvanceEachResult {
65
+ default: CohortAdvancementEventType;
66
+ rules?: CohortRule[];
67
+ }
68
+ export declare function makeAdvanceEachCtx<TSignalKeys extends string, TSignalTypeMap extends Partial<Record<string, unknown>> = Record<string, unknown>>(): AdvanceEachCtx<TSignalKeys, TSignalTypeMap>;
69
+ /** The 4-value branch outcome classification (mirrors core's `branchOutcomeValues`). */
70
+ export declare const branchOutcomeValues: readonly ["continue", "block", "error", "abandoned"];
71
+ export type BranchOutcome = (typeof branchOutcomeValues)[number];
72
+ /**
73
+ * A `ctx.stepSignalsList`-derived op-list builder: seeded by `.pluck(key)`,
74
+ * optionally narrowed/reshaped by `.filter()`/`.sortBy()`/`.unique()`, then
75
+ * finalized by exactly one reducer into a comparator-bound
76
+ * `CohortSignalRef` — the same "author fluently, hoist to a serializable
77
+ * definition" shape `Computed.*` uses, but resolved server-side against a
78
+ * cohort's real per-branch signals (`resolveStepSignalsListValue`) rather
79
+ * than a single step's own signals.
80
+ */
81
+ export interface StepSignalsListValueRef {
82
+ filter(operator: StepSignalsListConditionOperator, value: unknown): StepSignalsListValueRef;
83
+ sortBy(direction?: "asc" | "desc"): StepSignalsListValueRef;
84
+ unique(): StepSignalsListValueRef;
85
+ count(): CohortSignalRef;
86
+ sum(): CohortSignalRef;
87
+ avg(): CohortSignalRef;
88
+ min(): CohortSignalRef;
89
+ max(): CohortSignalRef;
90
+ booleanAll(): CohortSignalRef;
91
+ booleanAny(): CohortSignalRef;
92
+ join(separator?: string): CohortSignalRef;
93
+ first(): CohortSignalRef;
94
+ last(): CohortSignalRef;
95
+ }
96
+ /**
97
+ * `advanceAll`'s callback context: the whole cohort's aggregate branch
98
+ * outcomes (`branchOutcomes`) and any per-branch signal aggregation
99
+ * (`stepSignalsList`) — evaluated exactly once per cohort
100
+ * (`evaluateCohortAgainstPolicy`). Restricted to `continue`/`block`, no
101
+ * `stepSignals`/`route` (this is a whole-cohort decision, not one step's
102
+ * own).
103
+ */
104
+ export interface AdvanceAllCtx {
105
+ branchOutcomes: {
106
+ /** The cohort's total branch count. Compiles to fact `branchCount`. */
107
+ total(): CohortSignalRef<number>;
108
+ /** A single outcome's count across the cohort. Compiles to fact `${outcome}Count`. */
109
+ count(outcome: BranchOutcome): CohortSignalRef<number>;
110
+ /** True iff every branch resolved to this outcome. */
111
+ every(outcome: BranchOutcome): CohortRuleLeaf;
112
+ /** True iff at least one branch resolved to this outcome. */
113
+ some(outcome: BranchOutcome): CohortRuleLeaf;
114
+ };
115
+ stepSignalsList: {
116
+ pluck(signalKey: string): StepSignalsListValueRef;
117
+ };
118
+ all(...refs: CohortNestable[]): CohortRuleGroup;
119
+ any(...refs: CohortNestable[]): CohortRuleGroup;
120
+ }
121
+ export interface AdvanceAllResult {
122
+ default: CohortAdvancementEventType;
123
+ rules?: CohortRule[];
124
+ }
125
+ export declare function makeAdvanceAllCtx(): AdvanceAllCtx;
126
+ export {};
@@ -1,2 +1,4 @@
1
1
  export * from "./define-advancement-policy";
2
2
  export * from "./fluent-rules";
3
+ export * from "./cohort-advancement-policy";
4
+ export * from "./cohort-fluent-rules";
@@ -242,10 +242,252 @@ function makeAdvanceCtx() {
242
242
  route: (pipelineKey, inputJson) => inputJson !== undefined ? { outcome: "route", pipelineKey, inputJson } : { outcome: "route", pipelineKey }
243
243
  };
244
244
  }
245
+ // src/definitions/advancement-policies/cohort-advancement-policy.ts
246
+ var cohortAdvancementEventTypeValues = ["continue", "block"];
247
+ function serializeCohortCondition(condition) {
248
+ if (condition._tag === "signal") {
249
+ return {
250
+ fact: typeof condition.signal === "string" ? condition.signal : condition.signal.key,
251
+ operator: condition.operator,
252
+ value: condition.value
253
+ };
254
+ }
255
+ if (condition._tag === "all") {
256
+ return { all: condition.conditions.map(serializeCohortCondition) };
257
+ }
258
+ return { any: condition.conditions.map(serializeCohortCondition) };
259
+ }
260
+ function serializeCohortRule(rule) {
261
+ return {
262
+ conditions: { [rule.mode]: rule.conditions.map(serializeCohortCondition) },
263
+ event: {
264
+ type: rule.outcome,
265
+ ...rule.outcomeJson ? { params: rule.outcomeJson } : {}
266
+ }
267
+ };
268
+ }
269
+ function serializeCohortAdvancementPolicy(policy) {
270
+ if (!policy) {
271
+ return { rules: [], defaultEventType: "continue", defaultEventParamsJson: null };
272
+ }
273
+ return {
274
+ rules: (policy.rules ?? []).map(serializeCohortRule),
275
+ defaultEventType: policy.default,
276
+ defaultEventParamsJson: policy.defaultParamsJson ?? null
277
+ };
278
+ }
279
+ function visitCohortSignalConditions(conditions, visit) {
280
+ for (const c of conditions) {
281
+ if (c._tag === "signal") {
282
+ visit(c);
283
+ } else {
284
+ visitCohortSignalConditions(c.conditions, visit);
285
+ }
286
+ }
287
+ }
288
+ function isSameStepSignalsListDefinition(a, b) {
289
+ return JSON.stringify(a.ops) === JSON.stringify(b.ops) && JSON.stringify(a.reducer) === JSON.stringify(b.reducer);
290
+ }
291
+ function extractInlineStepSignalsListDefinitions(policy) {
292
+ if (!policy?.rules)
293
+ return [];
294
+ const byKey = new Map;
295
+ for (const rule of policy.rules) {
296
+ visitCohortSignalConditions(rule.conditions, (cond) => {
297
+ if (typeof cond.signal === "string")
298
+ return;
299
+ const inline = cond.signal;
300
+ const def = {
301
+ key: inline.key,
302
+ ops: inline.ops,
303
+ reducer: inline.reducer
304
+ };
305
+ const existing = byKey.get(def.key);
306
+ if (existing) {
307
+ if (!isSameStepSignalsListDefinition(existing, def)) {
308
+ throw new Error(`Conflicting inline stepSignalsList definitions for key "${def.key}"`);
309
+ }
310
+ return;
311
+ }
312
+ byKey.set(def.key, def);
313
+ });
314
+ }
315
+ return [...byKey.values()];
316
+ }
317
+ // src/definitions/advancement-policies/cohort-fluent-rules.ts
318
+ var LEAF_BRAND2 = Symbol("boboddy.cohortRule.leaf");
319
+ var GROUP_BRAND2 = Symbol("boboddy.cohortRule.group");
320
+ function createCohortSignalRef(signal2) {
321
+ const leaf = (operator, value) => {
322
+ const condition = {
323
+ _tag: "signal",
324
+ signal: signal2,
325
+ operator,
326
+ value
327
+ };
328
+ return {
329
+ [LEAF_BRAND2]: condition,
330
+ then(outcome, paramsJson) {
331
+ return {
332
+ _tag: "rule",
333
+ mode: "all",
334
+ conditions: [condition],
335
+ outcome,
336
+ ...paramsJson ? { outcomeJson: paramsJson } : {}
337
+ };
338
+ }
339
+ };
340
+ };
341
+ return {
342
+ eq: (v) => leaf("equal", v),
343
+ ne: (v) => leaf("notEqual", v),
344
+ gt: (v) => leaf("greaterThan", v),
345
+ gte: (v) => leaf("greaterThanInclusive", v),
346
+ lt: (v) => leaf("lessThan", v),
347
+ lte: (v) => leaf("lessThanInclusive", v),
348
+ in: (vs) => leaf("in", vs),
349
+ notIn: (vs) => leaf("notIn", vs),
350
+ contains: (v) => leaf("contains", v),
351
+ doesNotContain: (v) => leaf("doesNotContain", v)
352
+ };
353
+ }
354
+ function createCohortLeafFromCondition(condition) {
355
+ return {
356
+ [LEAF_BRAND2]: condition,
357
+ then(outcome, paramsJson) {
358
+ return {
359
+ _tag: "rule",
360
+ mode: "all",
361
+ conditions: [condition],
362
+ outcome,
363
+ ...paramsJson ? { outcomeJson: paramsJson } : {}
364
+ };
365
+ }
366
+ };
367
+ }
368
+ function extractCohortCondition(ref) {
369
+ if (LEAF_BRAND2 in ref)
370
+ return ref[LEAF_BRAND2];
371
+ const group = ref[GROUP_BRAND2];
372
+ return group.mode === "all" ? { _tag: "all", conditions: group.conditions } : { _tag: "any", conditions: group.conditions };
373
+ }
374
+ function createCohortGroup(mode, refs) {
375
+ const conditions = refs.map(extractCohortCondition);
376
+ return {
377
+ [GROUP_BRAND2]: { mode, conditions },
378
+ then(outcome, paramsJson) {
379
+ return {
380
+ _tag: "rule",
381
+ mode,
382
+ conditions,
383
+ outcome,
384
+ ...paramsJson ? { outcomeJson: paramsJson } : {}
385
+ };
386
+ }
387
+ };
388
+ }
389
+ function makeKeyedCohortSignalRef(key) {
390
+ return createCohortSignalRef(key);
391
+ }
392
+ function makeAdvanceEachCtx() {
393
+ return {
394
+ signal: (key) => makeKeyedCohortSignalRef(key),
395
+ stepSignals: new Proxy({}, {
396
+ get(_, key) {
397
+ if (typeof key === "string")
398
+ return makeKeyedCohortSignalRef(key);
399
+ return;
400
+ }
401
+ }),
402
+ all: (...refs) => createCohortGroup("all", refs),
403
+ any: (...refs) => createCohortGroup("any", refs)
404
+ };
405
+ }
406
+ var branchOutcomeValues = [
407
+ "continue",
408
+ "block",
409
+ "error",
410
+ "abandoned"
411
+ ];
412
+ function summarizeTransformOp(op) {
413
+ if (op.op === "filter") {
414
+ return `filter_${op.operator}_${JSON.stringify(op.value)}`;
415
+ }
416
+ if (op.op === "sortBy") {
417
+ return `sortBy_${op.direction}`;
418
+ }
419
+ return "unique";
420
+ }
421
+ function deriveStepSignalsListKey(ops, reducer) {
422
+ const pluck = ops.find((op) => op.op === "pluck");
423
+ const base = `${reducer.op}_${pluck?.signalKey ?? "value"}`;
424
+ const extras = ops.filter((op) => op.op !== "pluck").map(summarizeTransformOp);
425
+ const reducerExtra = reducer.op === "join" ? `sep_${reducer.separator}` : null;
426
+ const suffixParts = [...extras, ...reducerExtra ? [reducerExtra] : []];
427
+ return suffixParts.length > 0 ? `${base}_${suffixParts.join("_")}` : base;
428
+ }
429
+ function createStepSignalsListBuilder(ops) {
430
+ const withOp = (op) => createStepSignalsListBuilder([...ops, op]);
431
+ const reduce = (reducer) => {
432
+ const token = {
433
+ _tag: "step_signals_list",
434
+ key: deriveStepSignalsListKey(ops, reducer),
435
+ ops: [...ops],
436
+ reducer
437
+ };
438
+ return createCohortSignalRef(token);
439
+ };
440
+ return {
441
+ filter: (operator, value) => withOp({ op: "filter", operator, value }),
442
+ sortBy: (direction = "asc") => withOp({ op: "sortBy", direction }),
443
+ unique: () => withOp({ op: "unique" }),
444
+ count: () => reduce({ op: "count" }),
445
+ sum: () => reduce({ op: "sum" }),
446
+ avg: () => reduce({ op: "avg" }),
447
+ min: () => reduce({ op: "min" }),
448
+ max: () => reduce({ op: "max" }),
449
+ booleanAll: () => reduce({ op: "booleanAll" }),
450
+ booleanAny: () => reduce({ op: "booleanAny" }),
451
+ join: (separator = ",") => reduce({ op: "join", separator }),
452
+ first: () => reduce({ op: "first" }),
453
+ last: () => reduce({ op: "last" })
454
+ };
455
+ }
456
+ function makeAdvanceAllCtx() {
457
+ return {
458
+ branchOutcomes: {
459
+ total: () => createCohortSignalRef("branchCount"),
460
+ count: (outcome) => createCohortSignalRef(`${outcome}Count`),
461
+ every: (outcome) => createCohortLeafFromCondition({
462
+ _tag: "signal",
463
+ signal: `${outcome}Count`,
464
+ operator: "equal",
465
+ value: { fact: "branchCount" }
466
+ }),
467
+ some: (outcome) => createCohortLeafFromCondition({
468
+ _tag: "signal",
469
+ signal: `${outcome}Count`,
470
+ operator: "greaterThan",
471
+ value: 0
472
+ })
473
+ },
474
+ stepSignalsList: {
475
+ pluck: (signalKey) => createStepSignalsListBuilder([{ op: "pluck", signalKey }])
476
+ },
477
+ all: (...refs) => createCohortGroup("all", refs),
478
+ any: (...refs) => createCohortGroup("any", refs)
479
+ };
480
+ }
245
481
  export {
482
+ serializeCohortAdvancementPolicy,
246
483
  serializeAdvancementPolicy,
484
+ makeAdvanceEachCtx,
247
485
  makeAdvanceCtx,
486
+ makeAdvanceAllCtx,
487
+ extractInlineStepSignalsListDefinitions,
248
488
  extractInlineComputedSignals,
489
+ cohortAdvancementEventTypeValues,
490
+ branchOutcomeValues,
249
491
  Rule,
250
492
  Computed
251
493
  };