@datadog/openfeature-node-server 2.0.0 → 2.0.1
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/cjs/configuration/evaluateForSubject.d.ts +1 -6
- package/cjs/configuration/evaluateForSubject.d.ts.map +1 -1
- package/cjs/configuration/evaluateForSubject.js +4 -164
- package/cjs/configuration/evaluateForSubject.js.map +1 -1
- package/cjs/configuration/evaluation.d.ts +1 -4
- package/cjs/configuration/evaluation.d.ts.map +1 -1
- package/cjs/configuration/evaluation.js +3 -46
- package/cjs/configuration/evaluation.js.map +1 -1
- package/cjs/configuration/evaluationMetadata.d.ts +2 -0
- package/cjs/configuration/evaluationMetadata.d.ts.map +1 -0
- package/cjs/configuration/evaluationMetadata.js +6 -0
- package/cjs/configuration/evaluationMetadata.js.map +1 -0
- package/cjs/configuration/ufc-v1.d.ts +2 -53
- package/cjs/configuration/ufc-v1.d.ts.map +1 -1
- package/cjs/configuration/ufc-v1.js +3 -16
- package/cjs/configuration/ufc-v1.js.map +1 -1
- package/cjs/provider.d.ts.map +1 -1
- package/cjs/provider.js +2 -1
- package/cjs/provider.js.map +1 -1
- package/cjs/rules/rules.d.ts +2 -50
- package/cjs/rules/rules.d.ts.map +1 -1
- package/cjs/rules/rules.js +4 -68
- package/cjs/rules/rules.js.map +1 -1
- package/cjs/shards/matchesShard.d.ts +1 -3
- package/cjs/shards/matchesShard.d.ts.map +1 -1
- package/cjs/shards/matchesShard.js +3 -13
- package/cjs/shards/matchesShard.js.map +1 -1
- package/cjs/shards/sharders.d.ts +1 -11
- package/cjs/shards/sharders.d.ts.map +1 -1
- package/cjs/shards/sharders.js +5 -27
- package/cjs/shards/sharders.js.map +1 -1
- package/esm/configuration/evaluateForSubject.d.ts +1 -6
- package/esm/configuration/evaluateForSubject.d.ts.map +1 -1
- package/esm/configuration/evaluateForSubject.js +1 -162
- package/esm/configuration/evaluateForSubject.js.map +1 -1
- package/esm/configuration/evaluation.d.ts +1 -4
- package/esm/configuration/evaluation.d.ts.map +1 -1
- package/esm/configuration/evaluation.js +1 -45
- package/esm/configuration/evaluation.js.map +1 -1
- package/esm/configuration/evaluationMetadata.d.ts +2 -0
- package/esm/configuration/evaluationMetadata.d.ts.map +1 -0
- package/esm/configuration/evaluationMetadata.js +2 -0
- package/esm/configuration/evaluationMetadata.js.map +1 -0
- package/esm/configuration/ufc-v1.d.ts +2 -53
- package/esm/configuration/ufc-v1.d.ts.map +1 -1
- package/esm/configuration/ufc-v1.js +1 -15
- package/esm/configuration/ufc-v1.js.map +1 -1
- package/esm/provider.d.ts.map +1 -1
- package/esm/provider.js +2 -1
- package/esm/provider.js.map +1 -1
- package/esm/rules/rules.d.ts +2 -50
- package/esm/rules/rules.d.ts.map +1 -1
- package/esm/rules/rules.js +1 -66
- package/esm/rules/rules.js.map +1 -1
- package/esm/shards/matchesShard.d.ts +1 -3
- package/esm/shards/matchesShard.d.ts.map +1 -1
- package/esm/shards/matchesShard.js +1 -12
- package/esm/shards/matchesShard.js.map +1 -1
- package/esm/shards/sharders.d.ts +1 -11
- package/esm/shards/sharders.d.ts.map +1 -1
- package/esm/shards/sharders.js +1 -23
- package/esm/shards/sharders.js.map +1 -1
- package/package.json +3 -2
package/cjs/shards/sharders.d.ts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
abstract getShard(input: string, totalShards: number): number;
|
|
3
|
-
}
|
|
4
|
-
export declare class MD5Sharder extends Sharder {
|
|
5
|
-
getShard(input: string, totalShards: number): number;
|
|
6
|
-
}
|
|
7
|
-
export declare class DeterministicSharder extends Sharder {
|
|
8
|
-
private lookup;
|
|
9
|
-
constructor(lookup: Record<string, number>);
|
|
10
|
-
getShard(input: string, _totalShards: number): number;
|
|
11
|
-
}
|
|
1
|
+
export { DeterministicSharder, MD5Sharder, Sharder } from '@datadog/flagging-core';
|
|
12
2
|
//# sourceMappingURL=sharders.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharders.d.ts","sourceRoot":"","sources":["../../src/shards/sharders.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sharders.d.ts","sourceRoot":"","sources":["../../src/shards/sharders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA"}
|
package/cjs/shards/sharders.js
CHANGED
|
@@ -1,30 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
exports
|
|
8
|
-
class MD5Sharder extends Sharder {
|
|
9
|
-
getShard(input, totalShards) {
|
|
10
|
-
const hashOutput = (0, flagging_core_1.getMD5Hash)(input);
|
|
11
|
-
// get the first 4 bytes of the md5 hex string and parse it using base 16
|
|
12
|
-
// (8 hex characters represent 4 bytes, e.g. 0xffffffff represents the max 4-byte integer)
|
|
13
|
-
const intFromHash = parseInt(hashOutput.slice(0, 8), 16);
|
|
14
|
-
return intFromHash % totalShards;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.MD5Sharder = MD5Sharder;
|
|
18
|
-
class DeterministicSharder extends Sharder {
|
|
19
|
-
constructor(lookup) {
|
|
20
|
-
super();
|
|
21
|
-
this.lookup = lookup;
|
|
22
|
-
}
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
24
|
-
getShard(input, _totalShards) {
|
|
25
|
-
var _a;
|
|
26
|
-
return (_a = this.lookup[input]) !== null && _a !== void 0 ? _a : 0;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.DeterministicSharder = DeterministicSharder;
|
|
3
|
+
exports.Sharder = exports.MD5Sharder = exports.DeterministicSharder = void 0;
|
|
4
|
+
var flagging_core_1 = require("@datadog/flagging-core");
|
|
5
|
+
Object.defineProperty(exports, "DeterministicSharder", { enumerable: true, get: function () { return flagging_core_1.DeterministicSharder; } });
|
|
6
|
+
Object.defineProperty(exports, "MD5Sharder", { enumerable: true, get: function () { return flagging_core_1.MD5Sharder; } });
|
|
7
|
+
Object.defineProperty(exports, "Sharder", { enumerable: true, get: function () { return flagging_core_1.Sharder; } });
|
|
30
8
|
//# sourceMappingURL=sharders.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharders.js","sourceRoot":"","sources":["../../src/shards/sharders.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"sharders.js","sourceRoot":"","sources":["../../src/shards/sharders.ts"],"names":[],"mappings":";;;AAAA,wDAAkF;AAAzE,qHAAA,oBAAoB,OAAA;AAAE,2GAAA,UAAU,OAAA;AAAE,wGAAA,OAAO,OAAA"}
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { type EvaluationContext, type FlagValueType, type Logger, type ResolutionDetails } from '@openfeature/server-sdk';
|
|
3
|
-
import { type Rule } from '../rules/rules';
|
|
4
|
-
import { type Flag } from './ufc-v1';
|
|
5
|
-
export declare function evaluateForSubject<T extends FlagValueType>(flag: Flag, type: T, subjectKey: string | null | undefined, subjectAttributes: EvaluationContext, defaultValue: FlagTypeToValue<T>, logger: Logger): ResolutionDetails<FlagTypeToValue<T>>;
|
|
6
|
-
export declare function containsMatchingRule(rules: Rule[] | undefined, subjectAttributes: EvaluationContext, logger: Logger): boolean;
|
|
1
|
+
export { containsMatchingRule, evaluateForSubject } from '@datadog/flagging-core';
|
|
7
2
|
//# sourceMappingURL=evaluateForSubject.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluateForSubject.d.ts","sourceRoot":"","sources":["../../src/configuration/evaluateForSubject.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"evaluateForSubject.d.ts","sourceRoot":"","sources":["../../src/configuration/evaluateForSubject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -1,163 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { matchesRule } from '../rules/rules';
|
|
3
|
-
import { matchesShard } from '../shards/matchesShard';
|
|
4
|
-
import { variantTypeToFlagValueType } from './ufc-v1';
|
|
5
|
-
export function evaluateForSubject(flag, type, subjectKey, subjectAttributes, defaultValue, logger) {
|
|
6
|
-
if (!flag.enabled) {
|
|
7
|
-
logger.debug(`returning default assignment because flag is disabled`, {
|
|
8
|
-
flagKey: flag.key,
|
|
9
|
-
subjectKey,
|
|
10
|
-
});
|
|
11
|
-
return {
|
|
12
|
-
value: defaultValue,
|
|
13
|
-
reason: StandardResolutionReasons.DISABLED,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
const isValid = validateTypeMatch(type, flag.variationType);
|
|
17
|
-
if (!isValid) {
|
|
18
|
-
logger.debug(`variant value type mismatch, returning default value`, {
|
|
19
|
-
flagKey: flag.key,
|
|
20
|
-
subjectKey,
|
|
21
|
-
expectedType: type,
|
|
22
|
-
variantType: flag.variationType,
|
|
23
|
-
});
|
|
24
|
-
return {
|
|
25
|
-
value: defaultValue,
|
|
26
|
-
reason: StandardResolutionReasons.ERROR,
|
|
27
|
-
errorCode: ErrorCode.TYPE_MISMATCH,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const now = new Date();
|
|
31
|
-
for (const allocation of flag.allocations) {
|
|
32
|
-
if (allocation.startAt && now < new Date(allocation.startAt)) {
|
|
33
|
-
logger.debug(`allocation before start date`, {
|
|
34
|
-
flagKey: flag.key,
|
|
35
|
-
subjectKey,
|
|
36
|
-
allocationKey: allocation.key,
|
|
37
|
-
startAt: allocation.startAt,
|
|
38
|
-
});
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
if (allocation.endAt && now >= new Date(allocation.endAt)) {
|
|
42
|
-
logger.debug(`allocation after end date`, {
|
|
43
|
-
flagKey: flag.key,
|
|
44
|
-
subjectKey,
|
|
45
|
-
allocationKey: allocation.key,
|
|
46
|
-
endAt: allocation.endAt,
|
|
47
|
-
});
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
const matched = containsMatchingRule(allocation.rules, subjectAttributes, logger);
|
|
51
|
-
if (!matched) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
const selectedSplit = selectSplitUsingSharding(allocation.splits, subjectKey, flag.key, logger);
|
|
55
|
-
if (selectedSplit) {
|
|
56
|
-
const variant = flag.variations[selectedSplit.variationKey];
|
|
57
|
-
if (variant) {
|
|
58
|
-
logger.debug(`evaluated a flag`, {
|
|
59
|
-
flagKey: flag.key,
|
|
60
|
-
subjectKey,
|
|
61
|
-
assignment: variant.value,
|
|
62
|
-
});
|
|
63
|
-
return {
|
|
64
|
-
value: variant.value,
|
|
65
|
-
reason: StandardResolutionReasons.TARGETING_MATCH,
|
|
66
|
-
variant: variant.key,
|
|
67
|
-
flagMetadata: {
|
|
68
|
-
// Keys for dd-trace-js
|
|
69
|
-
__dd_allocation_key: allocation.key,
|
|
70
|
-
__dd_do_log: !!allocation.doLog,
|
|
71
|
-
__dd_split_serial_id: selectedSplit.serialId,
|
|
72
|
-
// Legacy keys (internal) - to be removed from server-side
|
|
73
|
-
allocationKey: allocation.key,
|
|
74
|
-
variationType: variantTypeToFlagValueType(flag.variationType),
|
|
75
|
-
doLog: !!allocation.doLog,
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
logger.debug(`no matching split found for subject`, {
|
|
82
|
-
flagKey: flag.key,
|
|
83
|
-
subjectKey,
|
|
84
|
-
allocationKey: allocation.key,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
// This shouldn't happen since a default allocation is generated by the server
|
|
89
|
-
logger.debug(`returning default assignment because no allocation matched`, {
|
|
90
|
-
flagKey: flag.key,
|
|
91
|
-
subjectKey,
|
|
92
|
-
});
|
|
93
|
-
return {
|
|
94
|
-
value: defaultValue,
|
|
95
|
-
reason: StandardResolutionReasons.DEFAULT,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
function validateTypeMatch(expectedType, variantType) {
|
|
99
|
-
if (expectedType === 'boolean') {
|
|
100
|
-
return variantType === 'BOOLEAN';
|
|
101
|
-
}
|
|
102
|
-
if (expectedType === 'string') {
|
|
103
|
-
return variantType === 'STRING';
|
|
104
|
-
}
|
|
105
|
-
if (expectedType === 'number') {
|
|
106
|
-
return variantType === 'INTEGER' || variantType === 'NUMERIC';
|
|
107
|
-
}
|
|
108
|
-
if (expectedType === 'object') {
|
|
109
|
-
return variantType === 'JSON';
|
|
110
|
-
}
|
|
111
|
-
throw new Error(`Invalid expected type: ${expectedType}`);
|
|
112
|
-
}
|
|
113
|
-
export function containsMatchingRule(rules, subjectAttributes, logger) {
|
|
114
|
-
if (!(rules === null || rules === void 0 ? void 0 : rules.length)) {
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
logger.debug(`evaluating rules`, {
|
|
118
|
-
rules: JSON.stringify(rules),
|
|
119
|
-
subjectAttributes,
|
|
120
|
-
});
|
|
121
|
-
return rules.some((rule) => matchesRule(rule, subjectAttributes));
|
|
122
|
-
}
|
|
123
|
-
function selectSplitUsingSharding(splits, subjectKey, flagKey, logger) {
|
|
124
|
-
if (!splits || splits.length === 0) {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
for (const split of splits) {
|
|
128
|
-
logger.debug(`evaluating split sharding`, {
|
|
129
|
-
flagKey,
|
|
130
|
-
subjectKey,
|
|
131
|
-
variationKey: split.variationKey,
|
|
132
|
-
shards: split.shards,
|
|
133
|
-
});
|
|
134
|
-
const matches = split.shards.every((shard) => {
|
|
135
|
-
if (subjectKey == null) {
|
|
136
|
-
throw new TargetingKeyMissingError();
|
|
137
|
-
}
|
|
138
|
-
const shardMatches = matchesShard(shard, subjectKey);
|
|
139
|
-
logger.debug(`shard match result`, {
|
|
140
|
-
flagKey,
|
|
141
|
-
subjectKey,
|
|
142
|
-
variationKey: split.variationKey,
|
|
143
|
-
shard: shard,
|
|
144
|
-
matches: shardMatches,
|
|
145
|
-
});
|
|
146
|
-
return shardMatches;
|
|
147
|
-
});
|
|
148
|
-
if (matches) {
|
|
149
|
-
logger.debug(`subject matches split`, {
|
|
150
|
-
flagKey,
|
|
151
|
-
subjectKey,
|
|
152
|
-
variationKey: split.variationKey,
|
|
153
|
-
});
|
|
154
|
-
return split;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
logger.debug(`subject matches no splits`, {
|
|
158
|
-
flagKey,
|
|
159
|
-
subjectKey,
|
|
160
|
-
});
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
1
|
+
export { containsMatchingRule, evaluateForSubject } from '@datadog/flagging-core';
|
|
163
2
|
//# sourceMappingURL=evaluateForSubject.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluateForSubject.js","sourceRoot":"","sources":["../../src/configuration/evaluateForSubject.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"evaluateForSubject.js","sourceRoot":"","sources":["../../src/configuration/evaluateForSubject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { type EvaluationContext, type FlagValueType, type Logger, type ResolutionDetails } from '@openfeature/server-sdk';
|
|
3
|
-
import type { UniversalFlagConfigurationV1 } from './ufc-v1';
|
|
4
|
-
export declare function evaluate<T extends FlagValueType>(config: UniversalFlagConfigurationV1 | undefined, type: T, flagKey: string, defaultValue: FlagTypeToValue<T>, context: EvaluationContext, logger: Logger): ResolutionDetails<FlagTypeToValue<T>>;
|
|
1
|
+
export { evaluateRulesBasedConfiguration as evaluate } from '@datadog/flagging-core';
|
|
5
2
|
//# sourceMappingURL=evaluation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluation.d.ts","sourceRoot":"","sources":["../../src/configuration/evaluation.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"evaluation.d.ts","sourceRoot":"","sources":["../../src/configuration/evaluation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,IAAI,QAAQ,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -1,46 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { evaluateForSubject } from './evaluateForSubject';
|
|
3
|
-
export function evaluate(config, type, flagKey, defaultValue, context, logger) {
|
|
4
|
-
if (!config) {
|
|
5
|
-
return {
|
|
6
|
-
value: defaultValue,
|
|
7
|
-
reason: 'ERROR',
|
|
8
|
-
errorCode: ErrorCode.PROVIDER_NOT_READY,
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
const { targetingKey: subjectKey, ...remainingContext } = context;
|
|
12
|
-
// Include the subjectKey as an "id" attribute for rule matching only when present
|
|
13
|
-
const subjectAttributes = {
|
|
14
|
-
...(subjectKey != null ? { id: subjectKey } : {}),
|
|
15
|
-
...remainingContext,
|
|
16
|
-
};
|
|
17
|
-
const flag = config.flags[flagKey];
|
|
18
|
-
if (!flag) {
|
|
19
|
-
logger.debug('returning default value because flag is not found', { flagKey, subjectKey });
|
|
20
|
-
return {
|
|
21
|
-
value: defaultValue,
|
|
22
|
-
reason: StandardResolutionReasons.ERROR,
|
|
23
|
-
errorCode: ErrorCode.FLAG_NOT_FOUND,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
const resultWithDetails = evaluateForSubject(flag, type, subjectKey, subjectAttributes, defaultValue, logger);
|
|
28
|
-
return resultWithDetails;
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
if (error instanceof TargetingKeyMissingError) {
|
|
32
|
-
return {
|
|
33
|
-
value: defaultValue,
|
|
34
|
-
reason: StandardResolutionReasons.ERROR,
|
|
35
|
-
errorCode: ErrorCode.TARGETING_KEY_MISSING,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
logger.error('Error evaluating flag', { error });
|
|
39
|
-
return {
|
|
40
|
-
value: defaultValue,
|
|
41
|
-
reason: StandardResolutionReasons.ERROR,
|
|
42
|
-
errorCode: ErrorCode.GENERAL,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
export { evaluateRulesBasedConfiguration as evaluate } from '@datadog/flagging-core';
|
|
46
2
|
//# sourceMappingURL=evaluation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluation.js","sourceRoot":"","sources":["../../src/configuration/evaluation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"evaluation.js","sourceRoot":"","sources":["../../src/configuration/evaluation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,IAAI,QAAQ,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluationMetadata.d.ts","sourceRoot":"","sources":["../../src/configuration/evaluationMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluationMetadata.js","sourceRoot":"","sources":["../../src/configuration/evaluationMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -1,54 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export type VariantType = 'BOOLEAN' | 'INTEGER' | 'NUMERIC' | 'STRING' | 'JSON';
|
|
4
|
-
export interface VariantConfiguration {
|
|
5
|
-
key: string;
|
|
6
|
-
value: FlagValue;
|
|
7
|
-
}
|
|
8
|
-
export interface ShardRange {
|
|
9
|
-
start: number;
|
|
10
|
-
end: number;
|
|
11
|
-
}
|
|
12
|
-
export interface Shard {
|
|
13
|
-
salt: string;
|
|
14
|
-
ranges: ShardRange[];
|
|
15
|
-
totalShards: number;
|
|
16
|
-
}
|
|
17
|
-
export interface Split {
|
|
18
|
-
variationKey: string;
|
|
19
|
-
shards: Shard[];
|
|
20
|
-
extraLogging?: Record<string, string>;
|
|
21
|
-
serialId?: number;
|
|
22
|
-
}
|
|
23
|
-
export interface Allocation {
|
|
24
|
-
key: string;
|
|
25
|
-
rules?: Rule[];
|
|
26
|
-
startAt?: Date;
|
|
27
|
-
endAt?: Date;
|
|
28
|
-
splits: Split[];
|
|
29
|
-
doLog?: boolean;
|
|
30
|
-
}
|
|
31
|
-
export interface Flag {
|
|
32
|
-
key: string;
|
|
33
|
-
enabled: boolean;
|
|
34
|
-
variationType: VariantType;
|
|
35
|
-
variations: Record<string, VariantConfiguration>;
|
|
36
|
-
allocations: Allocation[];
|
|
37
|
-
}
|
|
38
|
-
export interface UniversalFlagConfigurationV1 {
|
|
39
|
-
createdAt: string;
|
|
40
|
-
format: string;
|
|
41
|
-
environment: {
|
|
42
|
-
name: string;
|
|
43
|
-
};
|
|
44
|
-
flags: Record<string, Flag>;
|
|
45
|
-
}
|
|
46
|
-
export interface UniversalFlagConfigurationV1Response {
|
|
47
|
-
data: {
|
|
48
|
-
type: 'universal-flag-configuration';
|
|
49
|
-
id: string;
|
|
50
|
-
attributes: UniversalFlagConfigurationV1;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
export declare function variantTypeToFlagValueType(variantType: VariantType): FlagValueType;
|
|
1
|
+
export type { Allocation, Flag, Shard, ShardRange, Split, UniversalFlagConfigurationV1, UniversalFlagConfigurationV1Response, VariantConfiguration, VariantType, } from '@datadog/flagging-core';
|
|
2
|
+
export { variantTypeToFlagValueType } from '@datadog/flagging-core';
|
|
54
3
|
//# sourceMappingURL=ufc-v1.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ufc-v1.d.ts","sourceRoot":"","sources":["../../src/configuration/ufc-v1.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"ufc-v1.d.ts","sourceRoot":"","sources":["../../src/configuration/ufc-v1.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,IAAI,EACJ,KAAK,EACL,UAAU,EACV,KAAK,EACL,4BAA4B,EAC5B,oCAAoC,EACpC,oBAAoB,EACpB,WAAW,GACZ,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
if (variantType === 'BOOLEAN') {
|
|
3
|
-
return 'boolean';
|
|
4
|
-
}
|
|
5
|
-
if (variantType === 'STRING') {
|
|
6
|
-
return 'string';
|
|
7
|
-
}
|
|
8
|
-
if (variantType === 'INTEGER' || variantType === 'NUMERIC') {
|
|
9
|
-
return 'number';
|
|
10
|
-
}
|
|
11
|
-
if (variantType === 'JSON') {
|
|
12
|
-
return 'object';
|
|
13
|
-
}
|
|
14
|
-
throw new Error(`Cannot convert variant type to flag value type: ${variantType}`);
|
|
15
|
-
}
|
|
1
|
+
export { variantTypeToFlagValueType } from '@datadog/flagging-core';
|
|
16
2
|
//# sourceMappingURL=ufc-v1.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ufc-v1.js","sourceRoot":"","sources":["../../src/configuration/ufc-v1.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ufc-v1.js","sourceRoot":"","sources":["../../src/configuration/ufc-v1.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAA"}
|
package/esm/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["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AMtE;;OAEG;IACH,gBAAgB;IAIhB;;OAEG;IACH,gBAAgB,CAAC,aAAa,EAAE,4BAA4B;IA2B5D;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO;IAQvB;;;;;;;;OAQG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAc3B,wBAAwB,CAC5B,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,OAAO,EACrB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAMhC,uBAAuB,CAC3B,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAM/B,uBAAuB,CAC3B,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAM/B,uBAAuB,CAAC,CAAC,SAAS,SAAS,EAC/C,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,CAAC,EACf,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAmBhC,OAAO,CAAC,cAAc;CAwBvB"}
|
package/esm/provider.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createExposureEvent, LRUInMemoryAssignmentCache, } from '@datadog/flagging-core';
|
|
2
|
+
import { timeStampNow } from '@datadog/js-core/time';
|
|
2
3
|
import { OpenFeatureEventEmitter, ProviderEvents } from '@openfeature/server-sdk';
|
|
3
4
|
import { evaluate } from './configuration/evaluation';
|
|
4
5
|
import { InitializationController } from './initialization-controller';
|
|
@@ -110,7 +111,7 @@ export class DatadogNodeServerProvider {
|
|
|
110
111
|
}
|
|
111
112
|
handleExposure(flagKey, context, resolutionDetails) {
|
|
112
113
|
var _a, _b, _c;
|
|
113
|
-
const timestamp =
|
|
114
|
+
const timestamp = timeStampNow();
|
|
114
115
|
const evalutationDetails = {
|
|
115
116
|
...resolutionDetails,
|
|
116
117
|
flagKey: flagKey,
|
package/esm/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,mBAAmB,EAEnB,0BAA0B,GAC3B,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,mBAAmB,EAEnB,0BAA0B,GAC3B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAcpD,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAErD,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAA;AAEtE;;GAEG;AACH,MAAM,iCAAiC,GAAG,KAAM,CAAA;AAehD,MAAM,OAAO,yBAAyB;IAapC,YAA6B,OAAyC;QAAzC,YAAO,GAAP,OAAO,CAAkC;QAZ7D,aAAQ,GAAqB;YACpC,IAAI,EAAE,qBAAqB;SAC5B,CAAA;QACQ,WAAM,GAAa,QAAQ,CAAA;QAUlC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;QACf,IAAI,CAAC,MAAM,GAAG,IAAI,uBAAuB,EAAE,CAAA;QAC3C,IAAI,CAAC,aAAa,GAAG,IAAI,0BAA0B,CAAC,KAAM,CAAC,CAAA;IAC7D,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,OAAO,IAAI,CAAC,aAAa,CAAA;IAC3B,CAAC;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AI,CAAC,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,GAAG,aAAa,EAAE,SAAS,EAAE,CAAC,CAAA;YACrE,MAAA,IAAI,CAAC,aAAa,0CAAE,GAAG,CAAC,aAAa,CAAC,CAAA;QACxC,CAAC;IACH,CAAC;CACF"}
|
package/esm/rules/rules.d.ts
CHANGED
|
@@ -1,51 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export declare enum OperatorType {
|
|
4
|
-
MATCHES = "MATCHES",
|
|
5
|
-
NOT_MATCHES = "NOT_MATCHES",
|
|
6
|
-
GTE = "GTE",
|
|
7
|
-
GT = "GT",
|
|
8
|
-
LTE = "LTE",
|
|
9
|
-
LT = "LT",
|
|
10
|
-
ONE_OF = "ONE_OF",
|
|
11
|
-
NOT_ONE_OF = "NOT_ONE_OF",
|
|
12
|
-
IS_NULL = "IS_NULL"
|
|
13
|
-
}
|
|
14
|
-
type NumericOperator = OperatorType.GTE | OperatorType.GT | OperatorType.LTE | OperatorType.LT;
|
|
15
|
-
type MatchesCondition = {
|
|
16
|
-
operator: OperatorType.MATCHES;
|
|
17
|
-
attribute: string;
|
|
18
|
-
value: string;
|
|
19
|
-
};
|
|
20
|
-
type NotMatchesCondition = {
|
|
21
|
-
operator: OperatorType.NOT_MATCHES;
|
|
22
|
-
attribute: string;
|
|
23
|
-
value: string;
|
|
24
|
-
};
|
|
25
|
-
type OneOfCondition = {
|
|
26
|
-
operator: OperatorType.ONE_OF;
|
|
27
|
-
attribute: string;
|
|
28
|
-
value: string[];
|
|
29
|
-
};
|
|
30
|
-
type NotOneOfCondition = {
|
|
31
|
-
operator: OperatorType.NOT_ONE_OF;
|
|
32
|
-
attribute: string;
|
|
33
|
-
value: string[];
|
|
34
|
-
};
|
|
35
|
-
type NumericCondition = {
|
|
36
|
-
operator: NumericOperator;
|
|
37
|
-
attribute: string;
|
|
38
|
-
value: number;
|
|
39
|
-
};
|
|
40
|
-
type NullCondition = {
|
|
41
|
-
operator: OperatorType.IS_NULL;
|
|
42
|
-
attribute: string;
|
|
43
|
-
value: boolean;
|
|
44
|
-
};
|
|
45
|
-
export type Condition = MatchesCondition | NotMatchesCondition | OneOfCondition | NotOneOfCondition | NumericCondition | NullCondition;
|
|
46
|
-
export interface Rule {
|
|
47
|
-
conditions: Condition[];
|
|
48
|
-
}
|
|
49
|
-
export declare function matchesRule(rule: Rule, subjectAttributes: EvaluationContext): boolean;
|
|
50
|
-
export {};
|
|
1
|
+
export type { Condition, ConditionValueType, Rule } from '@datadog/flagging-core';
|
|
2
|
+
export { matchesRule, OperatorType } from '@datadog/flagging-core';
|
|
51
3
|
//# sourceMappingURL=rules.d.ts.map
|
package/esm/rules/rules.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/rules/rules.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/rules/rules.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AACjF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA"}
|
package/esm/rules/rules.js
CHANGED
|
@@ -1,67 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
(function (OperatorType) {
|
|
3
|
-
OperatorType["MATCHES"] = "MATCHES";
|
|
4
|
-
OperatorType["NOT_MATCHES"] = "NOT_MATCHES";
|
|
5
|
-
OperatorType["GTE"] = "GTE";
|
|
6
|
-
OperatorType["GT"] = "GT";
|
|
7
|
-
OperatorType["LTE"] = "LTE";
|
|
8
|
-
OperatorType["LT"] = "LT";
|
|
9
|
-
OperatorType["ONE_OF"] = "ONE_OF";
|
|
10
|
-
OperatorType["NOT_ONE_OF"] = "NOT_ONE_OF";
|
|
11
|
-
OperatorType["IS_NULL"] = "IS_NULL";
|
|
12
|
-
})(OperatorType || (OperatorType = {}));
|
|
13
|
-
export function matchesRule(rule, subjectAttributes) {
|
|
14
|
-
const conditionEvaluations = evaluateRuleConditions(subjectAttributes, rule.conditions);
|
|
15
|
-
// TODO: short-circuit return when false condition is found
|
|
16
|
-
return !conditionEvaluations.includes(false);
|
|
17
|
-
}
|
|
18
|
-
function evaluateRuleConditions(subjectAttributes, conditions) {
|
|
19
|
-
return conditions.map((condition) => evaluateCondition(subjectAttributes, condition));
|
|
20
|
-
}
|
|
21
|
-
function evaluateCondition(subjectAttributes, condition) {
|
|
22
|
-
const value = subjectAttributes[condition.attribute];
|
|
23
|
-
if (condition.operator === OperatorType.IS_NULL) {
|
|
24
|
-
if (condition.value) {
|
|
25
|
-
return value === null || value === undefined;
|
|
26
|
-
}
|
|
27
|
-
return value !== null && value !== undefined;
|
|
28
|
-
}
|
|
29
|
-
if (value !== null && value !== undefined) {
|
|
30
|
-
switch (condition.operator) {
|
|
31
|
-
case OperatorType.GTE:
|
|
32
|
-
case OperatorType.GT:
|
|
33
|
-
case OperatorType.LTE:
|
|
34
|
-
case OperatorType.LT: {
|
|
35
|
-
const comparator = (a, b) => condition.operator === OperatorType.GTE
|
|
36
|
-
? a >= b
|
|
37
|
-
: condition.operator === OperatorType.GT
|
|
38
|
-
? a > b
|
|
39
|
-
: condition.operator === OperatorType.LTE
|
|
40
|
-
? a <= b
|
|
41
|
-
: a < b;
|
|
42
|
-
return compareNumber(value, condition.value, comparator);
|
|
43
|
-
}
|
|
44
|
-
case OperatorType.MATCHES:
|
|
45
|
-
// ReDoS mitigation should happen on user input to avoid event loop saturation (https://datadoghq.atlassian.net/browse/FFL-1060)
|
|
46
|
-
return new RegExp(condition.value).test(String(value)); // dd-iac-scan ignore-line
|
|
47
|
-
case OperatorType.NOT_MATCHES:
|
|
48
|
-
// ReDoS mitigation should happen on user input to avoid event loop saturation (https://datadoghq.atlassian.net/browse/FFL-1060)
|
|
49
|
-
return !new RegExp(condition.value).test(String(value)); // dd-iac-scan ignore-line
|
|
50
|
-
case OperatorType.ONE_OF:
|
|
51
|
-
return isOneOf(value.toString(), condition.value);
|
|
52
|
-
case OperatorType.NOT_ONE_OF:
|
|
53
|
-
return isNotOneOf(value.toString(), condition.value);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
function isOneOf(attributeValue, conditionValues) {
|
|
59
|
-
return conditionValues.includes(attributeValue);
|
|
60
|
-
}
|
|
61
|
-
function isNotOneOf(attributeValue, conditionValues) {
|
|
62
|
-
return !isOneOf(attributeValue, conditionValues);
|
|
63
|
-
}
|
|
64
|
-
function compareNumber(attributeValue, conditionValue, compareFn) {
|
|
65
|
-
return compareFn(Number(attributeValue), Number(conditionValue));
|
|
66
|
-
}
|
|
1
|
+
export { matchesRule, OperatorType } from '@datadog/flagging-core';
|
|
67
2
|
//# sourceMappingURL=rules.js.map
|
package/esm/rules/rules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/rules/rules.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/rules/rules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { type Sharder } from './sharders';
|
|
3
|
-
export declare function matchesShard(shard: Shard, subjectKey: string, customSharder?: Sharder): boolean;
|
|
1
|
+
export { matchesShard } from '@datadog/flagging-core';
|
|
4
2
|
//# sourceMappingURL=matchesShard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matchesShard.d.ts","sourceRoot":"","sources":["../../src/shards/matchesShard.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"matchesShard.d.ts","sourceRoot":"","sources":["../../src/shards/matchesShard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA"}
|