@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.
Files changed (68) hide show
  1. package/dist/dedup/decision-dedup.d.ts +74 -0
  2. package/dist/dedup/decision-dedup.d.ts.map +1 -0
  3. package/dist/dedup/decision-dedup.js +132 -0
  4. package/dist/dedup/decision-dedup.js.map +1 -0
  5. package/dist/dedup/index.d.ts +5 -0
  6. package/dist/dedup/index.d.ts.map +1 -0
  7. package/dist/dedup/index.js +5 -0
  8. package/dist/dedup/index.js.map +1 -0
  9. package/dist/edge/client.d.ts +109 -0
  10. package/dist/edge/client.d.ts.map +1 -0
  11. package/dist/edge/client.js +154 -0
  12. package/dist/edge/client.js.map +1 -0
  13. package/dist/edge/index.d.ts +7 -0
  14. package/dist/edge/index.d.ts.map +1 -0
  15. package/dist/edge/index.js +7 -0
  16. package/dist/edge/index.js.map +1 -0
  17. package/dist/hashing/bucket.d.ts +56 -0
  18. package/dist/hashing/bucket.d.ts.map +1 -0
  19. package/dist/hashing/bucket.js +89 -0
  20. package/dist/hashing/bucket.js.map +1 -0
  21. package/dist/hashing/fnv1a.d.ts +17 -0
  22. package/dist/hashing/fnv1a.d.ts.map +1 -0
  23. package/dist/hashing/fnv1a.js +27 -0
  24. package/dist/hashing/fnv1a.js.map +1 -0
  25. package/dist/hashing/index.d.ts +8 -0
  26. package/dist/hashing/index.d.ts.map +1 -0
  27. package/dist/hashing/index.js +8 -0
  28. package/dist/hashing/index.js.map +1 -0
  29. package/dist/ids/index.d.ts +83 -0
  30. package/dist/ids/index.d.ts.map +1 -0
  31. package/dist/ids/index.js +165 -0
  32. package/dist/ids/index.js.map +1 -0
  33. package/dist/index.d.ts +20 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +32 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/resolution/conditions.d.ts +81 -0
  38. package/dist/resolution/conditions.d.ts.map +1 -0
  39. package/dist/resolution/conditions.js +197 -0
  40. package/dist/resolution/conditions.js.map +1 -0
  41. package/dist/resolution/engine.d.ts +54 -0
  42. package/dist/resolution/engine.d.ts.map +1 -0
  43. package/dist/resolution/engine.js +382 -0
  44. package/dist/resolution/engine.js.map +1 -0
  45. package/dist/resolution/index.d.ts +8 -0
  46. package/dist/resolution/index.d.ts.map +1 -0
  47. package/dist/resolution/index.js +10 -0
  48. package/dist/resolution/index.js.map +1 -0
  49. package/dist/types/index.d.ts +440 -0
  50. package/dist/types/index.d.ts.map +1 -0
  51. package/dist/types/index.js +8 -0
  52. package/dist/types/index.js.map +1 -0
  53. package/package.json +51 -0
  54. package/src/dedup/decision-dedup.ts +175 -0
  55. package/src/dedup/index.ts +6 -0
  56. package/src/edge/client.ts +256 -0
  57. package/src/edge/index.ts +16 -0
  58. package/src/hashing/bucket.ts +115 -0
  59. package/src/hashing/fnv1a.test.ts +87 -0
  60. package/src/hashing/fnv1a.ts +31 -0
  61. package/src/hashing/index.ts +15 -0
  62. package/src/ids/index.ts +221 -0
  63. package/src/index.ts +136 -0
  64. package/src/resolution/conditions.ts +253 -0
  65. package/src/resolution/engine.test.ts +242 -0
  66. package/src/resolution/engine.ts +480 -0
  67. package/src/resolution/index.ts +32 -0
  68. package/src/types/index.ts +508 -0
@@ -0,0 +1,197 @@
1
+ /**
2
+ * Condition Evaluation
3
+ *
4
+ * Evaluates context predicates to determine policy eligibility.
5
+ * Conditions are AND-ed together: all must match for a policy to apply.
6
+ */
7
+ /**
8
+ * Evaluates a single condition against a context.
9
+ *
10
+ * @param condition - The condition to evaluate
11
+ * @param context - The context to evaluate against
12
+ * @returns True if the condition matches
13
+ */
14
+ export function evaluateCondition(condition, context) {
15
+ const { field, op, value, values } = condition;
16
+ // Get the context value using dot notation
17
+ const contextValue = getNestedValue(context, field);
18
+ switch (op) {
19
+ case "eq":
20
+ return contextValue === value;
21
+ case "neq":
22
+ return contextValue !== value;
23
+ case "in":
24
+ if (!Array.isArray(values))
25
+ return false;
26
+ return values.includes(contextValue);
27
+ case "nin":
28
+ if (!Array.isArray(values))
29
+ return true;
30
+ return !values.includes(contextValue);
31
+ case "gt":
32
+ return (typeof contextValue === "number" && contextValue > value);
33
+ case "gte":
34
+ return (typeof contextValue === "number" && contextValue >= value);
35
+ case "lt":
36
+ return (typeof contextValue === "number" && contextValue < value);
37
+ case "lte":
38
+ return (typeof contextValue === "number" && contextValue <= value);
39
+ case "contains":
40
+ return (typeof contextValue === "string" &&
41
+ typeof value === "string" &&
42
+ contextValue.includes(value));
43
+ case "startsWith":
44
+ return (typeof contextValue === "string" &&
45
+ typeof value === "string" &&
46
+ contextValue.startsWith(value));
47
+ case "endsWith":
48
+ return (typeof contextValue === "string" &&
49
+ typeof value === "string" &&
50
+ contextValue.endsWith(value));
51
+ case "regex":
52
+ if (typeof contextValue !== "string" || typeof value !== "string") {
53
+ return false;
54
+ }
55
+ try {
56
+ const regex = new RegExp(value);
57
+ return regex.test(contextValue);
58
+ }
59
+ catch {
60
+ return false;
61
+ }
62
+ case "exists":
63
+ return contextValue !== undefined && contextValue !== null;
64
+ case "notExists":
65
+ return contextValue === undefined || contextValue === null;
66
+ default:
67
+ // Unknown operator, fail safe by not matching
68
+ return false;
69
+ }
70
+ }
71
+ /**
72
+ * Evaluates all conditions against a context.
73
+ * All conditions must match (AND logic).
74
+ *
75
+ * @param conditions - Array of conditions
76
+ * @param context - The context to evaluate against
77
+ * @returns True if all conditions match (or if there are no conditions)
78
+ */
79
+ export function evaluateConditions(conditions, context) {
80
+ // Empty conditions = always match
81
+ if (conditions.length === 0) {
82
+ return true;
83
+ }
84
+ // All conditions must match (AND)
85
+ return conditions.every((condition) => evaluateCondition(condition, context));
86
+ }
87
+ /**
88
+ * Gets a nested value from an object using dot notation.
89
+ *
90
+ * @example
91
+ * getNestedValue({ user: { name: "Alice" } }, "user.name") // "Alice"
92
+ * getNestedValue({ tags: ["a", "b"] }, "tags.0") // "a"
93
+ */
94
+ function getNestedValue(obj, path) {
95
+ const parts = path.split(".");
96
+ let current = obj;
97
+ for (const part of parts) {
98
+ if (current === null || current === undefined) {
99
+ return undefined;
100
+ }
101
+ if (typeof current === "object") {
102
+ current = current[part];
103
+ }
104
+ else {
105
+ return undefined;
106
+ }
107
+ }
108
+ return current;
109
+ }
110
+ // =============================================================================
111
+ // Condition Builder Helpers
112
+ // =============================================================================
113
+ /**
114
+ * Creates an equality condition.
115
+ */
116
+ export function eq(field, value) {
117
+ return { field, op: "eq", value };
118
+ }
119
+ /**
120
+ * Creates a not-equal condition.
121
+ */
122
+ export function neq(field, value) {
123
+ return { field, op: "neq", value };
124
+ }
125
+ /**
126
+ * Creates an "in" condition.
127
+ */
128
+ export function inValues(field, values) {
129
+ return { field, op: "in", values };
130
+ }
131
+ /**
132
+ * Creates a "not in" condition.
133
+ */
134
+ export function notIn(field, values) {
135
+ return { field, op: "nin", values };
136
+ }
137
+ /**
138
+ * Creates a greater-than condition.
139
+ */
140
+ export function gt(field, value) {
141
+ return { field, op: "gt", value };
142
+ }
143
+ /**
144
+ * Creates a greater-than-or-equal condition.
145
+ */
146
+ export function gte(field, value) {
147
+ return { field, op: "gte", value };
148
+ }
149
+ /**
150
+ * Creates a less-than condition.
151
+ */
152
+ export function lt(field, value) {
153
+ return { field, op: "lt", value };
154
+ }
155
+ /**
156
+ * Creates a less-than-or-equal condition.
157
+ */
158
+ export function lte(field, value) {
159
+ return { field, op: "lte", value };
160
+ }
161
+ /**
162
+ * Creates a string contains condition.
163
+ */
164
+ export function contains(field, value) {
165
+ return { field, op: "contains", value };
166
+ }
167
+ /**
168
+ * Creates a string starts-with condition.
169
+ */
170
+ export function startsWith(field, value) {
171
+ return { field, op: "startsWith", value };
172
+ }
173
+ /**
174
+ * Creates a string ends-with condition.
175
+ */
176
+ export function endsWith(field, value) {
177
+ return { field, op: "endsWith", value };
178
+ }
179
+ /**
180
+ * Creates a regex match condition.
181
+ */
182
+ export function regex(field, pattern) {
183
+ return { field, op: "regex", value: pattern };
184
+ }
185
+ /**
186
+ * Creates an exists condition.
187
+ */
188
+ export function exists(field) {
189
+ return { field, op: "exists" };
190
+ }
191
+ /**
192
+ * Creates a not-exists condition.
193
+ */
194
+ export function notExists(field) {
195
+ return { field, op: "notExists" };
196
+ }
197
+ //# sourceMappingURL=conditions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conditions.js","sourceRoot":"","sources":["../../src/resolution/conditions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,SAA0B,EAC1B,OAAgB;IAEhB,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAE/C,2CAA2C;IAC3C,MAAM,YAAY,GAAG,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAEpD,QAAQ,EAAE,EAAE,CAAC;QACX,KAAK,IAAI;YACP,OAAO,YAAY,KAAK,KAAK,CAAC;QAEhC,KAAK,KAAK;YACR,OAAO,YAAY,KAAK,KAAK,CAAC;QAEhC,KAAK,IAAI;YACP,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;gBAAE,OAAO,KAAK,CAAC;YACzC,OAAO,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAEvC,KAAK,KAAK;YACR,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;gBAAE,OAAO,IAAI,CAAC;YACxC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAExC,KAAK,IAAI;YACP,OAAO,CACL,OAAO,YAAY,KAAK,QAAQ,IAAI,YAAY,GAAI,KAAgB,CACrE,CAAC;QAEJ,KAAK,KAAK;YACR,OAAO,CACL,OAAO,YAAY,KAAK,QAAQ,IAAI,YAAY,IAAK,KAAgB,CACtE,CAAC;QAEJ,KAAK,IAAI;YACP,OAAO,CACL,OAAO,YAAY,KAAK,QAAQ,IAAI,YA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EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,MAAM,CAAC,KAAa;IAClC,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC;AACpC,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Resolution Engine
3
+ *
4
+ * Pure functions for parameter resolution using layered config and policies.
5
+ * Implements the Google-inspired layering system where:
6
+ * - Parameters are partitioned into layers
7
+ * - Within a layer, only one policy can be active for a unit
8
+ * - Across layers, policies overlap freely (different parameters)
9
+ *
10
+ * Resolution order (lowest to highest priority):
11
+ * 1. Caller defaults (always safe fallback)
12
+ * 2. Parameter defaults (from bundle)
13
+ * 3. Layer policies (each parameter belongs to exactly one layer)
14
+ */
15
+ import type { ConfigBundle, Context, ParameterValue, DecisionResult } from "../types/index.js";
16
+ /**
17
+ * Extracts the unit key value from context using the bundle's hashing config.
18
+ *
19
+ * @param bundle - The config bundle
20
+ * @param context - The evaluation context
21
+ * @returns The unit key value as a string, or null if not found
22
+ */
23
+ export declare function getUnitKeyValue(bundle: ConfigBundle, context: Context): string | null;
24
+ /**
25
+ * Resolves parameters with required defaults as fallback.
26
+ * This is the primary SDK function that guarantees safe defaults.
27
+ *
28
+ * Resolution priority (highest wins):
29
+ * 1. Policy overrides (from bundle)
30
+ * 2. Parameter defaults (from bundle)
31
+ * 3. Caller defaults (always safe fallback)
32
+ *
33
+ * @param bundle - The config bundle (can be null if unavailable)
34
+ * @param context - The evaluation context
35
+ * @param defaults - Default values for parameters (required, used as fallback)
36
+ * @returns Resolved parameter assignments (always returns safe values with inferred types)
37
+ */
38
+ export declare function resolveParameters<T extends Record<string, ParameterValue>>(bundle: ConfigBundle | null, context: Context, defaults: T): T;
39
+ /**
40
+ * Makes a decision with full metadata for tracking.
41
+ * Requires defaults for graceful degradation.
42
+ *
43
+ * Resolution priority (highest wins):
44
+ * 1. Policy overrides (from bundle)
45
+ * 2. Parameter defaults (from bundle)
46
+ * 3. Caller defaults (always safe fallback)
47
+ *
48
+ * @param bundle - The config bundle (can be null if unavailable)
49
+ * @param context - The evaluation context
50
+ * @param defaults - Default values for parameters (required, used as fallback)
51
+ * @returns Decision result with metadata (always returns safe values)
52
+ */
53
+ export declare function decide<T extends Record<string, ParameterValue>>(bundle: ConfigBundle | null, context: Context, defaults: T): DecisionResult;
54
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/resolution/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EACV,YAAY,EAIZ,OAAO,EACP,cAAc,EACd,cAAc,EAGf,MAAM,mBAAmB,CAAC;AAyN3B;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,OAAO,GACf,MAAM,GAAG,IAAI,CAQf;AA+JD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EACxE,MAAM,EAAE,YAAY,GAAG,IAAI,EAC3B,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,CAAC,GACV,CAAC,CAEH;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EAC7D,MAAM,EAAE,YAAY,GAAG,IAAI,EAC3B,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,CAAC,GACV,cAAc,CAoBhB"}
@@ -0,0 +1,382 @@
1
+ /**
2
+ * Resolution Engine
3
+ *
4
+ * Pure functions for parameter resolution using layered config and policies.
5
+ * Implements the Google-inspired layering system where:
6
+ * - Parameters are partitioned into layers
7
+ * - Within a layer, only one policy can be active for a unit
8
+ * - Across layers, policies overlap freely (different parameters)
9
+ *
10
+ * Resolution order (lowest to highest priority):
11
+ * 1. Caller defaults (always safe fallback)
12
+ * 2. Parameter defaults (from bundle)
13
+ * 3. Layer policies (each parameter belongs to exactly one layer)
14
+ */
15
+ import { computeBucket, findMatchingAllocation } from "../hashing/bucket.js";
16
+ import { evaluateConditions } from "./conditions.js";
17
+ import { generateDecisionId } from "../ids/index.js";
18
+ import { fnv1a } from "../hashing/fnv1a.js";
19
+ /**
20
+ * Filters context to only include fields allowed by matched policies.
21
+ * Collects the union of all allowed fields from policies with contextLogging config.
22
+ *
23
+ * @param context - The full evaluation context
24
+ * @param policies - Matched policies from resolution
25
+ * @returns Filtered context with only allowed fields, or undefined if no fields allowed
26
+ */
27
+ function filterContext(context, policies) {
28
+ // Collect union of all allowed fields from matched policies
29
+ const allowedFields = new Set();
30
+ for (const policy of policies) {
31
+ if (policy.contextLogging?.allowedFields) {
32
+ for (const field of policy.contextLogging.allowedFields) {
33
+ allowedFields.add(field);
34
+ }
35
+ }
36
+ }
37
+ // If no fields are allowed, return undefined
38
+ if (allowedFields.size === 0) {
39
+ return undefined;
40
+ }
41
+ // Filter context to only include allowed fields
42
+ const filtered = {};
43
+ for (const field of allowedFields) {
44
+ if (field in context) {
45
+ filtered[field] = context[field];
46
+ }
47
+ }
48
+ // Return undefined if no fields matched
49
+ return Object.keys(filtered).length > 0 ? filtered : undefined;
50
+ }
51
+ // =============================================================================
52
+ // Per-Entity Resolution Helpers
53
+ // =============================================================================
54
+ /**
55
+ * Builds an entity ID from context using the policy's entityKeys.
56
+ *
57
+ * @param entityKeys - Array of context keys that identify the entity
58
+ * @param context - The evaluation context
59
+ * @returns Entity ID string, or null if any key is missing
60
+ */
61
+ function buildEntityId(entityKeys, context) {
62
+ const parts = [];
63
+ for (const key of entityKeys) {
64
+ const value = context[key];
65
+ if (value === undefined || value === null) {
66
+ return null;
67
+ }
68
+ parts.push(String(value));
69
+ }
70
+ return parts.join("_");
71
+ }
72
+ /**
73
+ * Performs deterministic weighted selection using a hash.
74
+ *
75
+ * Uses the entity ID + unit key + policy ID to deterministically select
76
+ * an allocation based on weights. This ensures the same entity always
77
+ * gets the same allocation for a given weight distribution.
78
+ *
79
+ * @param weights - Array of weights (should sum to 1.0)
80
+ * @param seed - Seed string for deterministic hashing
81
+ * @returns Index of selected allocation
82
+ */
83
+ function weightedSelection(weights, seed) {
84
+ if (weights.length === 0)
85
+ return 0;
86
+ if (weights.length === 1)
87
+ return 0;
88
+ // Compute a deterministic random value in [0, 1) using hash
89
+ const hash = fnv1a(seed);
90
+ const random = (hash % 10000) / 10000;
91
+ // Select based on cumulative weights
92
+ let cumulative = 0;
93
+ for (let i = 0; i < weights.length; i++) {
94
+ cumulative += weights[i];
95
+ if (random < cumulative) {
96
+ return i;
97
+ }
98
+ }
99
+ // Fallback to last allocation (handles floating point edge cases)
100
+ return weights.length - 1;
101
+ }
102
+ /**
103
+ * Creates uniform weights for dynamic allocations.
104
+ *
105
+ * @param count - Number of allocations
106
+ * @returns Array of equal weights summing to 1.0
107
+ */
108
+ function createUniformWeights(count) {
109
+ if (count <= 0)
110
+ return [];
111
+ const weight = 1 / count;
112
+ return Array(count).fill(weight);
113
+ }
114
+ /**
115
+ * Gets entity weights from the bundle's entityState.
116
+ *
117
+ * @param bundle - The config bundle
118
+ * @param policyId - The policy ID
119
+ * @param entityId - The entity ID
120
+ * @param allocationCount - Number of allocations (for dynamic allocations)
121
+ * @returns Entity weights or uniform weights for cold start
122
+ */
123
+ function getEntityWeights(bundle, policyId, entityId, allocationCount) {
124
+ const policyState = bundle.entityState?.[policyId];
125
+ if (!policyState) {
126
+ // No state for this policy - use uniform weights
127
+ return createUniformWeights(allocationCount);
128
+ }
129
+ // Try entity-specific weights first
130
+ const entityWeights = policyState.entities[entityId];
131
+ if (entityWeights && entityWeights.weights.length === allocationCount) {
132
+ return entityWeights.weights;
133
+ }
134
+ // Fall back to global prior
135
+ const globalWeights = policyState._global;
136
+ if (globalWeights && globalWeights.weights.length === allocationCount) {
137
+ return globalWeights.weights;
138
+ }
139
+ // Last resort: uniform weights
140
+ return createUniformWeights(allocationCount);
141
+ }
142
+ /**
143
+ * Resolves a per-entity policy using weighted selection.
144
+ *
145
+ * @param bundle - The config bundle
146
+ * @param policy - The policy with entityConfig
147
+ * @param context - The evaluation context
148
+ * @param unitKeyValue - The unit key value for hashing
149
+ * @returns The selected allocation and entity ID, or null if cannot resolve
150
+ */
151
+ function resolvePerEntityPolicy(bundle, policy, context, unitKeyValue) {
152
+ const entityConfig = policy.entityConfig;
153
+ if (!entityConfig)
154
+ return null;
155
+ // Build entity ID from context
156
+ const entityId = buildEntityId(entityConfig.entityKeys, context);
157
+ if (!entityId) {
158
+ // Missing entity keys - cannot resolve
159
+ return null;
160
+ }
161
+ // Determine allocations
162
+ let allocations;
163
+ let allocationCount;
164
+ if (entityConfig.dynamicAllocations) {
165
+ // Dynamic allocations from context
166
+ const countKey = entityConfig.dynamicAllocations.countKey;
167
+ const count = context[countKey];
168
+ if (typeof count !== "number" || count <= 0) {
169
+ return null;
170
+ }
171
+ allocationCount = Math.floor(count);
172
+ // Create synthetic allocations for dynamic mode
173
+ // Each allocation is an index (0, 1, 2, ..., count-1)
174
+ allocations = Array.from({ length: allocationCount }, (_, i) => ({
175
+ id: `${policy.id}_dynamic_${i}`,
176
+ name: String(i),
177
+ bucketRange: [0, 0], // Not used for per-entity
178
+ overrides: {}, // Overrides are applied differently for dynamic
179
+ }));
180
+ }
181
+ else {
182
+ // Fixed allocations from policy
183
+ allocations = policy.allocations;
184
+ allocationCount = allocations.length;
185
+ }
186
+ if (allocationCount === 0)
187
+ return null;
188
+ // Get weights for this entity
189
+ const weights = getEntityWeights(bundle, policy.id, entityId, allocationCount);
190
+ // Deterministic weighted selection
191
+ const seed = `${entityId}:${unitKeyValue}:${policy.id}`;
192
+ const selectedIndex = weightedSelection(weights, seed);
193
+ return {
194
+ allocation: allocations[selectedIndex],
195
+ entityId,
196
+ };
197
+ }
198
+ /**
199
+ * Extracts the unit key value from context using the bundle's hashing config.
200
+ *
201
+ * @param bundle - The config bundle
202
+ * @param context - The evaluation context
203
+ * @returns The unit key value as a string, or null if not found
204
+ */
205
+ export function getUnitKeyValue(bundle, context) {
206
+ const value = context[bundle.hashing.unitKey];
207
+ if (value === undefined || value === null) {
208
+ return null;
209
+ }
210
+ return String(value);
211
+ }
212
+ /**
213
+ * Internal function that performs parameter resolution with metadata tracking.
214
+ * This is the single source of truth for resolution logic.
215
+ *
216
+ * @param bundle - The config bundle (can be null if unavailable)
217
+ * @param context - The evaluation context
218
+ * @param defaults - Default values for parameters (required, used as fallback)
219
+ * @returns Resolution result with assignments and metadata
220
+ */
221
+ function resolveInternal(bundle, context, defaults) {
222
+ // Start with caller defaults (always safe)
223
+ const assignments = { ...defaults };
224
+ const layers = [];
225
+ const matchedPolicies = [];
226
+ // If no bundle, return defaults with empty metadata
227
+ if (!bundle) {
228
+ return { assignments: assignments, unitKeyValue: "", layers, matchedPolicies };
229
+ }
230
+ // Try to get unit key
231
+ const unitKeyValue = getUnitKeyValue(bundle, context);
232
+ if (!unitKeyValue) {
233
+ // Missing unit key - return defaults
234
+ return { assignments: assignments, unitKeyValue: "", layers, matchedPolicies };
235
+ }
236
+ // Get requested parameter keys from defaults
237
+ const requestedKeys = new Set(Object.keys(defaults));
238
+ // Filter bundle parameters to only those requested
239
+ const params = bundle.parameters.filter((p) => requestedKeys.has(p.key));
240
+ // Apply bundle defaults (overrides caller defaults)
241
+ for (const param of params) {
242
+ if (param.key in assignments) {
243
+ assignments[param.key] = param.default;
244
+ }
245
+ }
246
+ // Group by layer
247
+ const paramsByLayer = new Map();
248
+ for (const param of params) {
249
+ const existing = paramsByLayer.get(param.layerId) || [];
250
+ existing.push(param);
251
+ paramsByLayer.set(param.layerId, existing);
252
+ }
253
+ // Process each layer (order doesn't matter since params are partitioned)
254
+ for (const layer of bundle.layers) {
255
+ const layerParams = paramsByLayer.get(layer.id);
256
+ if (!layerParams || layerParams.length === 0)
257
+ continue;
258
+ // Compute bucket
259
+ const bucket = computeBucket(unitKeyValue, layer.id, bundle.hashing.bucketCount);
260
+ let matchedPolicy;
261
+ let matchedAllocation;
262
+ // Find matching policy
263
+ for (const policy of layer.policies) {
264
+ if (policy.state !== "running")
265
+ continue;
266
+ // Check bucket eligibility BEFORE conditions (performance optimization)
267
+ // This enables non-overlapping experiments within a layer
268
+ if (policy.eligibleBucketRange) {
269
+ const { start, end } = policy.eligibleBucketRange;
270
+ if (bucket < start || bucket > end) {
271
+ continue; // User's bucket not eligible for this policy
272
+ }
273
+ }
274
+ if (!evaluateConditions(policy.conditions, context))
275
+ continue;
276
+ // Check if this is a per-entity policy
277
+ if (policy.entityConfig && policy.entityConfig.resolutionMode === "bundle") {
278
+ const result = resolvePerEntityPolicy(bundle, policy, context, unitKeyValue);
279
+ if (result) {
280
+ matchedPolicy = policy;
281
+ matchedAllocation = result.allocation;
282
+ // Track matched policy for context filtering
283
+ matchedPolicies.push(policy);
284
+ // Apply overrides
285
+ // For dynamic allocations, the allocation name IS the value
286
+ if (policy.entityConfig.dynamicAllocations) {
287
+ // For per-entity dynamic policies, we return the selected index
288
+ // The SDK caller should use metadata.allocationName to get the index
289
+ // No parameter overrides to apply in this mode
290
+ }
291
+ else {
292
+ // For fixed allocations, apply normal overrides
293
+ for (const [key, value] of Object.entries(result.allocation.overrides)) {
294
+ if (key in assignments) {
295
+ assignments[key] = value;
296
+ }
297
+ }
298
+ }
299
+ break; // Only one policy per layer
300
+ }
301
+ }
302
+ else if (policy.entityConfig && policy.entityConfig.resolutionMode === "edge") {
303
+ // Edge mode: skip for now, will be handled by SDK's async resolution
304
+ // In synchronous resolution, we fall through to bucket-based resolution
305
+ // The SDK should use async decide() for edge mode policies
306
+ continue;
307
+ }
308
+ else {
309
+ // Standard bucket-based resolution
310
+ const allocation = findMatchingAllocation(bucket, policy.allocations);
311
+ if (allocation) {
312
+ matchedPolicy = policy;
313
+ matchedAllocation = allocation;
314
+ // Track matched policy for context filtering
315
+ matchedPolicies.push(policy);
316
+ // Apply overrides
317
+ for (const [key, value] of Object.entries(allocation.overrides)) {
318
+ if (key in assignments) {
319
+ assignments[key] = value;
320
+ }
321
+ }
322
+ break; // Only one policy per layer
323
+ }
324
+ }
325
+ }
326
+ layers.push({
327
+ layerId: layer.id,
328
+ bucket,
329
+ policyId: matchedPolicy?.id,
330
+ allocationId: matchedAllocation?.id,
331
+ allocationName: matchedAllocation?.name,
332
+ });
333
+ }
334
+ return { assignments: assignments, unitKeyValue, layers, matchedPolicies };
335
+ }
336
+ /**
337
+ * Resolves parameters with required defaults as fallback.
338
+ * This is the primary SDK function that guarantees safe defaults.
339
+ *
340
+ * Resolution priority (highest wins):
341
+ * 1. Policy overrides (from bundle)
342
+ * 2. Parameter defaults (from bundle)
343
+ * 3. Caller defaults (always safe fallback)
344
+ *
345
+ * @param bundle - The config bundle (can be null if unavailable)
346
+ * @param context - The evaluation context
347
+ * @param defaults - Default values for parameters (required, used as fallback)
348
+ * @returns Resolved parameter assignments (always returns safe values with inferred types)
349
+ */
350
+ export function resolveParameters(bundle, context, defaults) {
351
+ return resolveInternal(bundle, context, defaults).assignments;
352
+ }
353
+ /**
354
+ * Makes a decision with full metadata for tracking.
355
+ * Requires defaults for graceful degradation.
356
+ *
357
+ * Resolution priority (highest wins):
358
+ * 1. Policy overrides (from bundle)
359
+ * 2. Parameter defaults (from bundle)
360
+ * 3. Caller defaults (always safe fallback)
361
+ *
362
+ * @param bundle - The config bundle (can be null if unavailable)
363
+ * @param context - The evaluation context
364
+ * @param defaults - Default values for parameters (required, used as fallback)
365
+ * @returns Decision result with metadata (always returns safe values)
366
+ */
367
+ export function decide(bundle, context, defaults) {
368
+ const { assignments, unitKeyValue, layers, matchedPolicies } = resolveInternal(bundle, context, defaults);
369
+ // Filter context based on matched policies' contextLogging config
370
+ const filteredContext = filterContext(context, matchedPolicies);
371
+ return {
372
+ decisionId: generateDecisionId(),
373
+ assignments,
374
+ metadata: {
375
+ timestamp: new Date().toISOString(),
376
+ unitKeyValue,
377
+ layers,
378
+ filteredContext,
379
+ },
380
+ };
381
+ }
382
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/resolution/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAaH,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C;;;;;;;GAOG;AACH,SAAS,aAAa,CACpB,OAAgB,EAChB,QAAwB;IAExB,4DAA4D;IAC5D,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAC;IACxC,KAAK,MAAM,MAAM,IAAI,QAAQ,EAAE,CAAC;QAC9B,IAAI,MAAM,CAAC,cAAc,EAAE,aAAa,EAAE,CAAC;YACzC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC;gBACxD,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED,6CAA6C;IAC7C,IAAI,aAAa,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,gDAAgD;IAChD,MAAM,QAAQ,GAAY,EAAE,CAAC;IAC7B,KAAK,MAAM,KAAK,IAAI,aAAa,EAAE,CAAC;QAClC,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;YACrB,QAAQ,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QACnC,CAA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AAM,EAAE,eAAe,EAAE,CAAC;AAClF,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAA2B,EAC3B,OAAgB,EAChB,QAAW;IAEX,OAAO,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,WAAW,CAAC;AAChE,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,MAAM,CACpB,MAA2B,EAC3B,OAAgB,EAChB,QAAW;IAEX,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,eAAe,CAC5E,MAAM,EACN,OAAO,EACP,QAAQ,CACT,CAAC;IAEF,kEAAkE;IAClE,MAAM,eAAe,GAAG,aAAa,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IAEhE,OAAO;QACL,UAAU,EAAE,kBAAkB,EAAE;QAChC,WAAW;QACX,QAAQ,EAAE;YACR,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,YAAY;YACZ,MAAM;YACN,eAAe;SAChB;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Resolution Module
3
+ *
4
+ * Exports all resolution-related functions.
5
+ */
6
+ export { resolveParameters, decide, getUnitKeyValue, } from "./engine.js";
7
+ export { evaluateCondition, evaluateConditions, eq, neq, inValues, notIn, gt, gte, lt, lte, contains, startsWith, endsWith, regex, exists, notExists, } from "./conditions.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resolution/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,iBAAiB,EACjB,MAAM,EACN,eAAe,GAChB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAElB,EAAE,EACF,GAAG,EACH,QAAQ,EACR,KAAK,EACL,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,KAAK,EACL,MAAM,EACN,SAAS,GACV,MAAM,iBAAiB,CAAC"}