@datadog/openfeature-node-server 0.1.0-preview.3
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 +7 -0
- package/cjs/configuration/evaluateForSubject.d.ts.map +1 -0
- package/cjs/configuration/evaluateForSubject.js +151 -0
- package/cjs/configuration/evaluateForSubject.js.map +1 -0
- package/cjs/configuration/evaluation.d.ts +5 -0
- package/cjs/configuration/evaluation.d.ts.map +1 -0
- package/cjs/configuration/evaluation.js +33 -0
- package/cjs/configuration/evaluation.js.map +1 -0
- package/cjs/configuration/ufc-v1.d.ts +52 -0
- package/cjs/configuration/ufc-v1.d.ts.map +1 -0
- package/cjs/configuration/ufc-v1.js +3 -0
- package/cjs/configuration/ufc-v1.js.map +1 -0
- package/cjs/index.d.ts +2 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js +4 -0
- package/cjs/index.js.map +1 -0
- package/cjs/provider.d.ts +25 -0
- package/cjs/provider.d.ts.map +1 -0
- package/cjs/provider.js +42 -0
- package/cjs/provider.js.map +1 -0
- package/cjs/rules/rules.d.ts +51 -0
- package/cjs/rules/rules.d.ts.map +1 -0
- package/cjs/rules/rules.js +71 -0
- package/cjs/rules/rules.js.map +1 -0
- package/cjs/shards/matchesShard.d.ts +4 -0
- package/cjs/shards/matchesShard.d.ts.map +1 -0
- package/cjs/shards/matchesShard.js +16 -0
- package/cjs/shards/matchesShard.js.map +1 -0
- package/cjs/shards/obfuscation.d.ts +9 -0
- package/cjs/shards/obfuscation.d.ts.map +1 -0
- package/cjs/shards/obfuscation.js +23 -0
- package/cjs/shards/obfuscation.js.map +1 -0
- package/cjs/shards/sharders.d.ts +12 -0
- package/cjs/shards/sharders.d.ts.map +1 -0
- package/cjs/shards/sharders.js +30 -0
- package/cjs/shards/sharders.js.map +1 -0
- package/esm/configuration/evaluateForSubject.d.ts +7 -0
- package/esm/configuration/evaluateForSubject.d.ts.map +1 -0
- package/esm/configuration/evaluateForSubject.js +147 -0
- package/esm/configuration/evaluateForSubject.js.map +1 -0
- package/esm/configuration/evaluation.d.ts +5 -0
- package/esm/configuration/evaluation.d.ts.map +1 -0
- package/esm/configuration/evaluation.js +30 -0
- package/esm/configuration/evaluation.js.map +1 -0
- package/esm/configuration/ufc-v1.d.ts +52 -0
- package/esm/configuration/ufc-v1.d.ts.map +1 -0
- package/esm/configuration/ufc-v1.js +2 -0
- package/esm/configuration/ufc-v1.js.map +1 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +4 -0
- package/esm/index.js.map +1 -0
- package/esm/provider.d.ts +25 -0
- package/esm/provider.d.ts.map +1 -0
- package/esm/provider.js +38 -0
- package/esm/provider.js.map +1 -0
- package/esm/rules/rules.d.ts +51 -0
- package/esm/rules/rules.d.ts.map +1 -0
- package/esm/rules/rules.js +67 -0
- package/esm/rules/rules.js.map +1 -0
- package/esm/shards/matchesShard.d.ts +4 -0
- package/esm/shards/matchesShard.d.ts.map +1 -0
- package/esm/shards/matchesShard.js +13 -0
- package/esm/shards/matchesShard.js.map +1 -0
- package/esm/shards/obfuscation.d.ts +9 -0
- package/esm/shards/obfuscation.d.ts.map +1 -0
- package/esm/shards/obfuscation.js +16 -0
- package/esm/shards/obfuscation.js.map +1 -0
- package/esm/shards/sharders.d.ts +12 -0
- package/esm/shards/sharders.d.ts.map +1 -0
- package/esm/shards/sharders.js +24 -0
- package/esm/shards/sharders.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeterministicSharder = exports.MD5Sharder = exports.Sharder = void 0;
|
|
4
|
+
const obfuscation_1 = require("./obfuscation");
|
|
5
|
+
class Sharder {
|
|
6
|
+
}
|
|
7
|
+
exports.Sharder = Sharder;
|
|
8
|
+
class MD5Sharder extends Sharder {
|
|
9
|
+
getShard(input, totalShards) {
|
|
10
|
+
const hashOutput = (0, obfuscation_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;
|
|
30
|
+
//# sourceMappingURL=sharders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharders.js","sourceRoot":"","sources":["../../src/shards/sharders.ts"],"names":[],"mappings":";;;AAAA,+CAA0C;AAE1C,MAAsB,OAAO;CAE5B;AAFD,0BAEC;AAED,MAAa,UAAW,SAAQ,OAAO;IACrC,QAAQ,CAAC,KAAa,EAAE,WAAmB;QACzC,MAAM,UAAU,GAAG,IAAA,wBAAU,EAAC,KAAK,CAAC,CAAA;QACpC,yEAAyE;QACzE,0FAA0F;QAC1F,MAAM,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;QACxD,OAAO,WAAW,GAAG,WAAW,CAAA;IAClC,CAAC;CACF;AARD,gCAQC;AAED,MAAa,oBAAqB,SAAQ,OAAO;IAO/C,YAAY,MAA8B;QACxC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,6DAA6D;IAC7D,QAAQ,CAAC,KAAa,EAAE,YAAoB;;QAC1C,OAAO,MAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mCAAI,CAAC,CAAA;IAChC,CAAC;CACF;AAhBD,oDAgBC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Rule } from '../rules/rules';
|
|
2
|
+
import { Flag } from './ufc-v1';
|
|
3
|
+
import { EvaluationContext, FlagValueType, Logger, ResolutionDetails } from '@openfeature/server-sdk';
|
|
4
|
+
import { FlagTypeToValue } from '@datadog/flagging-core';
|
|
5
|
+
export declare function evaluateForSubject<T extends FlagValueType>(flag: Flag | undefined, type: T, subjectKey: string, subjectAttributes: EvaluationContext, defaultValue: FlagTypeToValue<T>, logger: Logger): ResolutionDetails<FlagTypeToValue<T>>;
|
|
6
|
+
export declare function containsMatchingRule(rules: Rule[] | undefined, subjectAttributes: EvaluationContext, logger: Logger): boolean;
|
|
7
|
+
//# sourceMappingURL=evaluateForSubject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluateForSubject.d.ts","sourceRoot":"","sources":["../../src/configuration/evaluateForSubject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAElD,OAAO,EAAE,IAAI,EAAsB,MAAM,UAAU,CAAA;AACnD,OAAO,EAAa,iBAAiB,EAAa,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAA6B,MAAM,yBAAyB,CAAA;AACtJ,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAExD,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,aAAa,EACxD,IAAI,EAAE,IAAI,GAAG,SAAS,EACtB,IAAI,EAAE,CAAC,EACP,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,iBAAiB,EACpC,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC,EAChC,MAAM,EAAE,MAAM,GACb,iBAAiB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAuFvC;AAqBD,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,IAAI,EAAE,GAAG,SAAS,EACzB,iBAAiB,EAAE,iBAAiB,EACpC,MAAM,EAAE,MAAM,GACb,OAAO,CAST"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { matchesRule } from '../rules/rules';
|
|
2
|
+
import { matchesShard } from '../shards/matchesShard';
|
|
3
|
+
import { ErrorCode, StandardResolutionReasons } from '@openfeature/server-sdk';
|
|
4
|
+
export function evaluateForSubject(flag, type, subjectKey, subjectAttributes, defaultValue, logger) {
|
|
5
|
+
if (!(flag === null || flag === void 0 ? void 0 : flag.enabled)) {
|
|
6
|
+
logger.debug(`returning default assignment because flag is disabled`, {
|
|
7
|
+
flagKey: flag ? flag.key : 'undefined',
|
|
8
|
+
subjectKey,
|
|
9
|
+
});
|
|
10
|
+
return {
|
|
11
|
+
value: defaultValue,
|
|
12
|
+
reason: StandardResolutionReasons.DISABLED,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const isValid = validateTypeMatch(type, flag.variationType);
|
|
16
|
+
if (!isValid) {
|
|
17
|
+
logger.debug(`variant value type mismatch, returning default value`, {
|
|
18
|
+
flagKey: flag.key,
|
|
19
|
+
subjectKey,
|
|
20
|
+
expectedType: type,
|
|
21
|
+
variantType: flag.variationType,
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
value: defaultValue,
|
|
25
|
+
reason: StandardResolutionReasons.ERROR,
|
|
26
|
+
errorCode: ErrorCode.TYPE_MISMATCH,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const now = new Date();
|
|
30
|
+
for (const allocation of flag.allocations) {
|
|
31
|
+
if (allocation.startAt && now < new Date(allocation.startAt)) {
|
|
32
|
+
logger.debug(`allocation before start date`, {
|
|
33
|
+
flagKey: flag.key,
|
|
34
|
+
subjectKey,
|
|
35
|
+
allocationKey: allocation.key,
|
|
36
|
+
startAt: allocation.startAt,
|
|
37
|
+
});
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (allocation.endAt && now >= new Date(allocation.endAt)) {
|
|
41
|
+
logger.debug(`allocation after end date`, {
|
|
42
|
+
flagKey: flag.key,
|
|
43
|
+
subjectKey,
|
|
44
|
+
allocationKey: allocation.key,
|
|
45
|
+
endAt: allocation.endAt,
|
|
46
|
+
});
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const matched = containsMatchingRule(allocation.rules, subjectAttributes, logger);
|
|
50
|
+
if (!matched) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const selectedSplit = selectSplitUsingSharding(allocation.splits, subjectKey, flag.key, logger);
|
|
54
|
+
if (selectedSplit) {
|
|
55
|
+
const variation = flag.variations[selectedSplit.variationKey];
|
|
56
|
+
if (variation) {
|
|
57
|
+
logger.debug(`evaluated a flag`, {
|
|
58
|
+
flagKey: flag.key,
|
|
59
|
+
subjectKey,
|
|
60
|
+
assignment: variation.value,
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
value: variation.value,
|
|
64
|
+
reason: StandardResolutionReasons.TARGETING_MATCH,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
logger.debug(`no matching split found for subject`, {
|
|
70
|
+
flagKey: flag.key,
|
|
71
|
+
subjectKey,
|
|
72
|
+
allocationKey: allocation.key,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
logger.debug(`returning default assignment because no allocation matched`, {
|
|
77
|
+
flagKey: flag.key,
|
|
78
|
+
subjectKey,
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
value: defaultValue,
|
|
82
|
+
reason: StandardResolutionReasons.DEFAULT,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function validateTypeMatch(expectedType, variantType) {
|
|
86
|
+
if (expectedType === 'boolean') {
|
|
87
|
+
return variantType === 'BOOLEAN';
|
|
88
|
+
}
|
|
89
|
+
if (expectedType === 'string') {
|
|
90
|
+
return variantType === 'STRING';
|
|
91
|
+
}
|
|
92
|
+
if (expectedType === 'number') {
|
|
93
|
+
return variantType === 'INTEGER' || variantType === 'NUMERIC';
|
|
94
|
+
}
|
|
95
|
+
if (expectedType === 'object') {
|
|
96
|
+
return variantType === 'JSON';
|
|
97
|
+
}
|
|
98
|
+
throw new Error(`Invalid expected type: ${expectedType}`);
|
|
99
|
+
}
|
|
100
|
+
export function containsMatchingRule(rules, subjectAttributes, logger) {
|
|
101
|
+
if (!(rules === null || rules === void 0 ? void 0 : rules.length)) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
logger.debug(`evaluating rules`, {
|
|
105
|
+
rules: JSON.stringify(rules),
|
|
106
|
+
subjectAttributes,
|
|
107
|
+
});
|
|
108
|
+
return rules.some((rule) => matchesRule(rule, subjectAttributes));
|
|
109
|
+
}
|
|
110
|
+
function selectSplitUsingSharding(splits, subjectKey, flagKey, logger) {
|
|
111
|
+
if (!splits || splits.length === 0) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
for (const split of splits) {
|
|
115
|
+
logger.debug(`evaluating split sharding`, {
|
|
116
|
+
flagKey,
|
|
117
|
+
subjectKey,
|
|
118
|
+
variationKey: split.variationKey,
|
|
119
|
+
shards: split.shards,
|
|
120
|
+
});
|
|
121
|
+
const matches = split.shards.every((shard) => {
|
|
122
|
+
const shardMatches = matchesShard(shard, subjectKey);
|
|
123
|
+
logger.debug(`shard match result`, {
|
|
124
|
+
flagKey,
|
|
125
|
+
subjectKey,
|
|
126
|
+
variationKey: split.variationKey,
|
|
127
|
+
shard: shard,
|
|
128
|
+
matches: shardMatches,
|
|
129
|
+
});
|
|
130
|
+
return shardMatches;
|
|
131
|
+
});
|
|
132
|
+
if (matches) {
|
|
133
|
+
logger.debug(`subject matches split`, {
|
|
134
|
+
flagKey,
|
|
135
|
+
subjectKey,
|
|
136
|
+
variationKey: split.variationKey,
|
|
137
|
+
});
|
|
138
|
+
return split;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
logger.debug(`subject matches no splits`, {
|
|
142
|
+
flagKey,
|
|
143
|
+
subjectKey,
|
|
144
|
+
});
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=evaluateForSubject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluateForSubject.js","sourceRoot":"","sources":["../../src/configuration/evaluateForSubject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAQ,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAErD,OAAO,EAAE,SAAS,EAA0E,yBAAyB,EAAE,MAAM,yBAAyB,CAAA;AAGtJ,MAAM,UAAU,kBAAkB,CAChC,IAAsB,EACtB,IAAO,EACP,UAAkB,EAClB,iBAAoC,EACpC,YAAgC,EAChC,MAAc;IAEd,IAAI,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,CAAA,EAAE,CAAC;QACnB,MAAM,CAAC,KAAK,CAAC,uDAAuD,EAAE;YACpE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW;YACtC,UAAU;SACX,CAAC,CAAA;QACF,OAAO;YACL,KAAK,EAAE,YAAY;YACnB,MAAM,EAAE,yBAAyB,CAAC,QAAQ;SAC3C,CAAA;IACH,CAAC;IAED,MAAM,OAAO,GAAG,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,CAAA;IAC3D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,CAAC,KAAK,CAAC,sDAAsD,EAAE;YACnE,OAAO,EAAE,IAA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Y;aACtB,CAAC,CAAA;YACF,OAAO,YAAY,CAAA;QACrB,CAAC,CAAC,CAAA;QAEF,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,CAAC,KAAK,CAAC,uBAAuB,EAAE;gBACpC,OAAO;gBACP,UAAU;gBACV,YAAY,EAAE,KAAK,CAAC,YAAY;aACjC,CAAC,CAAA;YACF,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,2BAA2B,EAAE;QACxC,OAAO;QACP,UAAU;KACX,CAAC,CAAA;IAEF,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { FlagTypeToValue } from '@datadog/flagging-core';
|
|
2
|
+
import { EvaluationContext, FlagValueType, Logger, ResolutionDetails } from '@openfeature/server-sdk';
|
|
3
|
+
import { UniversalFlagConfigurationV1 } from './ufc-v1';
|
|
4
|
+
export declare function evaluate<T extends FlagValueType>(config: UniversalFlagConfigurationV1, type: T, flagKey: string, defaultValue: FlagTypeToValue<T>, context: EvaluationContext, logger: Logger): ResolutionDetails<FlagTypeToValue<T>>;
|
|
5
|
+
//# sourceMappingURL=evaluation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluation.d.ts","sourceRoot":"","sources":["../../src/configuration/evaluation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAEL,iBAAiB,EACjB,aAAa,EACb,MAAM,EACN,iBAAiB,EAElB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAA;AAGvD,wBAAgB,QAAQ,CAAC,CAAC,SAAS,aAAa,EAC9C,MAAM,EAAE,4BAA4B,EACpC,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC,EAChC,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,MAAM,GACb,iBAAiB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAiCvC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ErrorCode, StandardResolutionReasons, } from '@openfeature/server-sdk';
|
|
2
|
+
import { evaluateForSubject } from './evaluateForSubject';
|
|
3
|
+
export function evaluate(config, type, flagKey, defaultValue, context, logger) {
|
|
4
|
+
const { targetingKey: subjectKey, ...remainingContext } = context;
|
|
5
|
+
if (!subjectKey) {
|
|
6
|
+
return {
|
|
7
|
+
value: defaultValue,
|
|
8
|
+
reason: 'ERROR',
|
|
9
|
+
errorCode: ErrorCode.TARGETING_KEY_MISSING,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
// Include the subjectKey as an "id" attribute for rule matching
|
|
13
|
+
const subjectAttributes = {
|
|
14
|
+
id: subjectKey,
|
|
15
|
+
...remainingContext,
|
|
16
|
+
};
|
|
17
|
+
try {
|
|
18
|
+
const resultWithDetails = evaluateForSubject(config.flags[flagKey], type, subjectKey, subjectAttributes, defaultValue, logger);
|
|
19
|
+
return resultWithDetails;
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
logger.error('Error evaluating flag', { error });
|
|
23
|
+
return {
|
|
24
|
+
value: defaultValue,
|
|
25
|
+
reason: StandardResolutionReasons.ERROR,
|
|
26
|
+
errorCode: ErrorCode.GENERAL,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=evaluation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluation.js","sourceRoot":"","sources":["../../src/configuration/evaluation.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EAKT,yBAAyB,GAC1B,MAAM,yBAAyB,CAAA;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,MAAM,UAAU,QAAQ,CACtB,MAAoC,EACpC,IAAO,EACP,OAAe,EACf,YAAgC,EAChC,OAA0B,EAC1B,MAAc;IAEd,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,gBAAgB,EAAE,GAAG,OAAO,CAAA;IACjE,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO;YACL,KAAK,EAAE,YAAY;YACnB,MAAM,EAAE,OAAO;YACf,SAAS,EAAE,SAAS,CAAC,qBAAqB;SAC3C,CAAA;IACH,CAAC;IAED,gEAAgE;IAChE,MAAM,iBAAiB,GAAG;QACxB,EAAE,EAAE,UAAU;QACd,GAAG,gBAAgB;KACpB,CAAA;IACD,IAAI,CAAC;QACH,MAAM,iBAAiB,GAAG,kBAAkB,CAC1C,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EACrB,IAAI,EACJ,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,MAAM,CACP,CAAA;QACD,OAAO,iBAAiB,CAAA;IAC1B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QAChD,OAAO;YACL,KAAK,EAAE,YAAY;YACnB,MAAM,EAAE,yBAAyB,CAAC,KAAK;YACvC,SAAS,EAAE,SAAS,CAAC,OAAO;SAC7B,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { FlagValue } from '@openfeature/core';
|
|
2
|
+
import { Rule } from '../rules/rules';
|
|
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
|
+
}
|
|
22
|
+
export interface Allocation {
|
|
23
|
+
key: string;
|
|
24
|
+
rules?: Rule[];
|
|
25
|
+
startAt?: Date;
|
|
26
|
+
endAt?: Date;
|
|
27
|
+
splits: Split[];
|
|
28
|
+
doLog?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface Flag {
|
|
31
|
+
key: string;
|
|
32
|
+
enabled: boolean;
|
|
33
|
+
variationType: VariantType;
|
|
34
|
+
variations: Record<string, VariantConfiguration>;
|
|
35
|
+
allocations: Allocation[];
|
|
36
|
+
}
|
|
37
|
+
export interface UniversalFlagConfigurationV1 {
|
|
38
|
+
createdAt: string;
|
|
39
|
+
format: string;
|
|
40
|
+
environment: {
|
|
41
|
+
name: string;
|
|
42
|
+
};
|
|
43
|
+
flags: Record<string, Flag>;
|
|
44
|
+
}
|
|
45
|
+
export interface UniversalFlagConfigurationV1Response {
|
|
46
|
+
data: {
|
|
47
|
+
type: 'universal-flag-configuration';
|
|
48
|
+
id: string;
|
|
49
|
+
attributes: UniversalFlagConfigurationV1;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=ufc-v1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ufc-v1.d.ts","sourceRoot":"","sources":["../../src/configuration/ufc-v1.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAiB,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAErC,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAA;AAE/E,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,C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ACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ufc-v1.js","sourceRoot":"","sources":["../../src/configuration/ufc-v1.ts"],"names":[],"mappings":""}
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,WAAW,QAA6B,CAAA"}
|
package/esm/index.js
ADDED
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,MAAM,WAAW,GAAG,0BAA0B,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { JsonValue, Logger, Provider, ProviderMetadata, ResolutionDetails, Paradigm, Hook } from '@openfeature/server-sdk';
|
|
2
|
+
import { EvaluationContext } from '@openfeature/core';
|
|
3
|
+
import { ProviderStatus } from '@openfeature/server-sdk';
|
|
4
|
+
import { UniversalFlagConfigurationV1 } from './configuration/ufc-v1';
|
|
5
|
+
export interface DatadogNodeServerProviderOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Remote config agent
|
|
8
|
+
*/
|
|
9
|
+
configuration: UniversalFlagConfigurationV1;
|
|
10
|
+
}
|
|
11
|
+
export declare class DatadogNodeServerProvider implements Provider {
|
|
12
|
+
readonly metadata: ProviderMetadata;
|
|
13
|
+
readonly runsOn: Paradigm;
|
|
14
|
+
hooks?: Hook[];
|
|
15
|
+
status: ProviderStatus;
|
|
16
|
+
private configuration;
|
|
17
|
+
constructor(options: DatadogNodeServerProviderOptions);
|
|
18
|
+
getConfiguration(): UniversalFlagConfigurationV1;
|
|
19
|
+
setConfiguration(configuration: UniversalFlagConfigurationV1): void;
|
|
20
|
+
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext, _logger: Logger): Promise<ResolutionDetails<boolean>>;
|
|
21
|
+
resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext, _logger: Logger): Promise<ResolutionDetails<string>>;
|
|
22
|
+
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext, _logger: Logger): Promise<ResolutionDetails<number>>;
|
|
23
|
+
resolveObjectEvaluation<T extends JsonValue>(flagKey: string, defaultValue: T, context: EvaluationContext, _logger: Logger): Promise<ResolutionDetails<T>>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,IAAI,EACL,MAAM,yBAAyB,CAAA;AAEhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAExD,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAA;AAErE,MAAM,WAAW,gCAAgC;IAC/C;;OAEG;IACH,aAAa,EAAE,4BAA4B,CAAA;CAC5C;AAED,qBAAa,yBAA0B,YAAW,QAAQ;IACxD,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAElC;IACD,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAW;IACpC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAA;IAEd,MAAM,EAAE,cAAc,CAA2B;IACjD,OAAO,CAAC,aAAa,CAA8B;gBAEvC,OAAO,EAAE,gCAAgC;IAKrD,gBAAgB;IAIhB,gBAAgB,CAAC,aAAa,EAAE,4BAA4B;IAItD,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;IAIhC,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;IAI/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;IAI/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;CASjC"}
|
package/esm/provider.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ProviderStatus } from '@openfeature/server-sdk';
|
|
2
|
+
import { evaluate } from './configuration/evaluation';
|
|
3
|
+
export class DatadogNodeServerProvider {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
this.metadata = {
|
|
6
|
+
name: 'datadog-node-server',
|
|
7
|
+
};
|
|
8
|
+
this.runsOn = 'server';
|
|
9
|
+
this.status = ProviderStatus.NOT_READY;
|
|
10
|
+
this.configuration = options.configuration;
|
|
11
|
+
this.status = ProviderStatus.READY;
|
|
12
|
+
}
|
|
13
|
+
getConfiguration() {
|
|
14
|
+
return this.configuration;
|
|
15
|
+
}
|
|
16
|
+
setConfiguration(configuration) {
|
|
17
|
+
this.configuration = configuration;
|
|
18
|
+
}
|
|
19
|
+
async resolveBooleanEvaluation(flagKey, defaultValue, context, _logger) {
|
|
20
|
+
return evaluate(this.configuration, 'boolean', flagKey, defaultValue, context, _logger);
|
|
21
|
+
}
|
|
22
|
+
async resolveStringEvaluation(flagKey, defaultValue, context, _logger) {
|
|
23
|
+
return evaluate(this.configuration, 'string', flagKey, defaultValue, context, _logger);
|
|
24
|
+
}
|
|
25
|
+
async resolveNumberEvaluation(flagKey, defaultValue, context, _logger) {
|
|
26
|
+
return evaluate(this.configuration, 'number', flagKey, defaultValue, context, _logger);
|
|
27
|
+
}
|
|
28
|
+
async resolveObjectEvaluation(flagKey, defaultValue, context, _logger) {
|
|
29
|
+
// type safety: OpenFeature interface requires us to return a
|
|
30
|
+
// specific T for *any* value of T (which could be any subtype of
|
|
31
|
+
// JsonValue). We can't even theoretically implement it in a
|
|
32
|
+
// type-sound way because there's no runtime information passed to
|
|
33
|
+
// learn what type the user expects. So it's up to the user to
|
|
34
|
+
// make sure they pass the appropriate type.
|
|
35
|
+
return evaluate(this.configuration, 'object', flagKey, defaultValue, context, _logger);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAUrD,MAAM,OAAO,yBAAyB;IAUpC,YAAY,OAAyC;QAT5C,aAAQ,GAAqB;YACpC,IAAI,EAAE,qBAAqB;SAC5B,CAAA;QACQ,WAAM,GAAa,QAAQ,CAAA;QAGpC,WAAM,GAAmB,cAAc,CAAC,SAAS,CAAA;QAI/C,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAA;QAC1C,IAAI,CAAC,MAAM,GAAG,cAAc,CAAC,KAAK,CAAA;IACpC,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,CAAC,aAAa,CAAA;IAC3B,CAAC;IAED,gBAAgB,CAAC,aAA2C;QAC1D,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;IACpC,CAAC;IAED,KAAK,CAAC,wBAAwB,CAC5B,OAAe,EACf,YAAqB,EACrB,OAA0B,EAC1B,OAAe;QAEf,OAAO,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACzF,CAAC;IAED,KAAK,CAAC,uBAAuB,CAC3B,OAAe,EACf,YAAoB,EACpB,OAA0B,EAC1B,OAAe;QAEf,OAAO,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACxF,CAAC;IAED,KAAK,CAAC,uBAAuB,CAC3B,OAAe,EACf,YAAoB,EACpB,OAA0B,EAC1B,OAAe;QAEf,OAAO,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACxF,CAAC;IAED,KAAK,CAAC,uBAAuB,CAC3B,OAAe,EACf,YAAe,EACf,OAA0B,EAC1B,OAAe;QAEf,6DAA6D;QAC7D,iEAAiE;QACjE,4DAA4D;QAC5D,kEAAkE;QAClE,8DAA8D;QAC9D,4CAA4C;QAC5C,OAAO,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,CAAyB,CAAA;IAChH,CAAC;CACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { EvaluationContext, EvaluationContextValue } from "@openfeature/server-sdk";
|
|
2
|
+
export type ConditionValueType = EvaluationContextValue | EvaluationContextValue[];
|
|
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 {};
|
|
51
|
+
//# sourceMappingURL=rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/rules/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,sBA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CAAA;CACf,CAAA;AAED,MAAM,MAAM,SAAS,GACjB,gBAAgB,GAChB,mBAAmB,GACnB,cAAc,GACd,iBAAiB,GACjB,gBAAgB,GAChB,aAAa,CAAA;AAEjB,MAAM,WAAW,IAAI;IACnB,UAAU,EAAE,SAAS,EAAE,CAAA;CACxB;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,iBAAiB,EAAE,iBAAiB,GAAG,OAAO,CAIrF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export var OperatorType;
|
|
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
|
+
}
|
|
67
|
+
//# sourceMappingURL=rules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,KAAK,CAAC,CAAA;QACxD,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,OAAO,CAAC,cAAsB,EAAE,eAAyB;IAChE,OAAO,eAAe,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAA;AACjD,CAAC;AAED,SAAS,UAAU,CAAC,cAAsB,EAAE,eAAyB;IACnE,OAAO,CAAC,OAAO,CAAC,cAAc,EAAE,eAAe,CAAC,CAAA;AAClD,CAAC;AAED,SAAS,aAAa,CACpB,cAAsC,EACtC,cAAkC,EAClC,SAA4C;IAE5C,OAAO,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC,CAAA;AAClE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchesShard.d.ts","sourceRoot":"","sources":["../../src/shards/matchesShard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAc,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAc,OAAO,EAAE,MAAM,YAAY,CAAA;AAEhD,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO,GAAG,OAAO,CAI/F"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MD5Sharder } from './sharders';
|
|
2
|
+
export function matchesShard(shard, subjectKey, customSharder) {
|
|
3
|
+
const sharder = customSharder !== null && customSharder !== void 0 ? customSharder : new MD5Sharder();
|
|
4
|
+
const assignedShard = sharder.getShard(hashKey(shard.salt, subjectKey), shard.totalShards);
|
|
5
|
+
return shard.ranges.some((range) => isInShardRange(assignedShard, range));
|
|
6
|
+
}
|
|
7
|
+
function isInShardRange(shard, range) {
|
|
8
|
+
return range.start <= shard && shard < range.end;
|
|
9
|
+
}
|
|
10
|
+
function hashKey(salt, subjectKey) {
|
|
11
|
+
return `${salt}-${subjectKey}`;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=matchesShard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchesShard.js","sourceRoot":"","sources":["../../src/shards/matchesShard.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAW,MAAM,YAAY,CAAA;AAEhD,MAAM,UAAU,YAAY,CAAC,KAAY,EAAE,UAAkB,EAAE,aAAuB;IACpF,MAAM,OAAO,GAAG,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,IAAI,UAAU,EAAE,CAAA;IACjD,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,CAAA;IAC1F,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC,CAAA;AAC3E,CAAC;AAED,SAAS,cAAc,CAAC,KAAa,EAAE,KAAiB;IACtD,OAAO,KAAK,CAAC,KAAK,IAAI,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,GAAG,CAAA;AAClD,CAAC;AAED,SAAS,OAAO,CAAC,IAAY,EAAE,UAAkB;IAC/C,OAAO,GAAG,IAAI,IAAI,UAAU,EAAE,CAAA;AAChC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function getMD5Hash(input: string, salt?: string): string;
|
|
2
|
+
/**
|
|
3
|
+
* Builds a storage key suffix from an API key.
|
|
4
|
+
* @param apiKey - The API key to build the suffix from
|
|
5
|
+
* @returns A string suffix for storage keys
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildStorageKeySuffix(apiKey: string): string;
|
|
9
|
+
//# sourceMappingURL=obfuscation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"obfuscation.d.ts","sourceRoot":"","sources":["../../src/shards/obfuscation.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,SAAK,GAAG,MAAM,CAE3D;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAI5D"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import SparkMD5 from 'spark-md5';
|
|
2
|
+
export function getMD5Hash(input, salt = '') {
|
|
3
|
+
return new SparkMD5().append(salt).append(input).end();
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Builds a storage key suffix from an API key.
|
|
7
|
+
* @param apiKey - The API key to build the suffix from
|
|
8
|
+
* @returns A string suffix for storage keys
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export function buildStorageKeySuffix(apiKey) {
|
|
12
|
+
// Note that we hash the API key and use the first 16 characters of the digest.
|
|
13
|
+
const hashed = getMD5Hash(apiKey);
|
|
14
|
+
return hashed.slice(0, 16);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=obfuscation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"obfuscation.js","sourceRoot":"","sources":["../../src/shards/obfuscation.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,WAAW,CAAA;AAEhC,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,IAAI,GAAG,EAAE;IACjD,OAAO,IAAI,QAAQ,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAA;AACxD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAc;IAClD,+EAA+E;IAC/E,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;IACjC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;AAC5B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare abstract class Sharder {
|
|
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
|
+
}
|
|
12
|
+
//# sourceMappingURL=sharders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharders.d.ts","sourceRoot":"","sources":["../../src/shards/sharders.ts"],"names":[],"mappings":"AAEA,8BAAsB,OAAO;IAC3B,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM;CAC9D;AAED,qBAAa,UAAW,SAAQ,OAAO;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM;CAOrD;AAED,qBAAa,oBAAqB,SAAQ,OAAO;IAK/C,OAAO,CAAC,MAAM,CAAwB;gBAE1B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAM1C,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM;CAGtD"}
|