@depup/launchdarkly-node-server-sdk 7.0.4-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +16 -0
- package/.circleci/config.yml +89 -0
- package/.eslintignore +5 -0
- package/.eslintrc.yaml +114 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
- package/.github/ISSUE_TEMPLATE/config.yml +5 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/pull_request_template.md +21 -0
- package/.github/workflows/stale.yml +8 -0
- package/.hound.yml +33 -0
- package/.ldrelease/config.yml +28 -0
- package/.prettierrc +6 -0
- package/CHANGELOG.md +603 -0
- package/CODEOWNERS +2 -0
- package/CONTRIBUTING.md +55 -0
- package/LICENSE.txt +13 -0
- package/README.md +36 -0
- package/SECURITY.md +5 -0
- package/attribute_reference.js +217 -0
- package/big_segments.js +117 -0
- package/caching_store_wrapper.js +240 -0
- package/changes.json +30 -0
- package/configuration.js +235 -0
- package/context.js +98 -0
- package/context_filter.js +137 -0
- package/contract-tests/README.md +7 -0
- package/contract-tests/index.js +109 -0
- package/contract-tests/log.js +23 -0
- package/contract-tests/package.json +15 -0
- package/contract-tests/sdkClientEntity.js +110 -0
- package/contract-tests/testharness-suppressions.txt +2 -0
- package/diagnostic_events.js +151 -0
- package/docs/typedoc.js +10 -0
- package/errors.js +26 -0
- package/evaluator.js +822 -0
- package/event_factory.js +121 -0
- package/event_processor.js +320 -0
- package/event_summarizer.js +101 -0
- package/feature_store.js +120 -0
- package/feature_store_event_wrapper.js +258 -0
- package/file_data_source.js +192 -0
- package/flags_state.js +46 -0
- package/index.d.ts +2426 -0
- package/index.js +452 -0
- package/integrations.js +7 -0
- package/interfaces.js +2 -0
- package/loggers.js +125 -0
- package/messages.js +31 -0
- package/operators.js +106 -0
- package/package.json +105 -0
- package/polling.js +70 -0
- package/requestor.js +62 -0
- package/scripts/better-audit.sh +76 -0
- package/sharedtest/big_segment_store_tests.js +86 -0
- package/sharedtest/feature_store_tests.js +177 -0
- package/sharedtest/persistent_feature_store_tests.js +183 -0
- package/sharedtest/store_tests.js +7 -0
- package/streaming.js +179 -0
- package/test/LDClient-big-segments-test.js +92 -0
- package/test/LDClient-end-to-end-test.js +218 -0
- package/test/LDClient-evaluation-all-flags-test.js +226 -0
- package/test/LDClient-evaluation-test.js +204 -0
- package/test/LDClient-events-test.js +502 -0
- package/test/LDClient-listeners-test.js +180 -0
- package/test/LDClient-test.js +96 -0
- package/test/LDClient-tls-test.js +110 -0
- package/test/attribute_reference-test.js +494 -0
- package/test/big_segments-test.js +182 -0
- package/test/caching_store_wrapper-test.js +434 -0
- package/test/configuration-test.js +249 -0
- package/test/context-test.js +93 -0
- package/test/context_filter-test.js +424 -0
- package/test/diagnostic_events-test.js +152 -0
- package/test/evaluator-big-segments-test.js +301 -0
- package/test/evaluator-bucketing-test.js +333 -0
- package/test/evaluator-clause-test.js +277 -0
- package/test/evaluator-flag-test.js +452 -0
- package/test/evaluator-pre-conditions-test.js +105 -0
- package/test/evaluator-rule-test.js +131 -0
- package/test/evaluator-segment-match-test.js +310 -0
- package/test/evaluator_helpers.js +106 -0
- package/test/event_processor-test.js +680 -0
- package/test/event_summarizer-test.js +146 -0
- package/test/feature_store-test.js +42 -0
- package/test/feature_store_event_wrapper-test.js +182 -0
- package/test/feature_store_test_base.js +60 -0
- package/test/file_data_source-test.js +255 -0
- package/test/loggers-test.js +126 -0
- package/test/operators-test.js +102 -0
- package/test/polling-test.js +158 -0
- package/test/requestor-test.js +60 -0
- package/test/store_tests_big_segments-test.js +61 -0
- package/test/streaming-test.js +323 -0
- package/test/stubs.js +107 -0
- package/test/test_data-test.js +341 -0
- package/test/update_queue-test.js +61 -0
- package/test-types.ts +210 -0
- package/test_data.js +323 -0
- package/tsconfig.json +14 -0
- package/update_queue.js +28 -0
- package/utils/__tests__/httpUtils-test.js +39 -0
- package/utils/__tests__/wrapPromiseCallback-test.js +33 -0
- package/utils/asyncUtils.js +32 -0
- package/utils/httpUtils.js +105 -0
- package/utils/stringifyAttrs.js +14 -0
- package/utils/wrapPromiseCallback.js +36 -0
- package/versioned_data_kind.js +34 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
const { Evaluator } = require('../evaluator');
|
|
2
|
+
const {
|
|
3
|
+
eventFactory,
|
|
4
|
+
makeBooleanFlagWithRules,
|
|
5
|
+
makeBooleanFlagWithOneClause,
|
|
6
|
+
asyncEvaluate,
|
|
7
|
+
makeClauseThatMatchesUser,
|
|
8
|
+
} = require('./evaluator_helpers');
|
|
9
|
+
|
|
10
|
+
// Tests of flag evaluation at the clause level.
|
|
11
|
+
|
|
12
|
+
describe('Evaluator - clause user contexts', () => {
|
|
13
|
+
|
|
14
|
+
it('coerces user key to string for legacy user', async () => {
|
|
15
|
+
const clause = { 'attribute': 'key', 'op': 'in', 'values': ['999'] };
|
|
16
|
+
const flag = makeBooleanFlagWithOneClause(clause);
|
|
17
|
+
const [err, detail, events] = await asyncEvaluate(Evaluator(), flag, { key: 999 }, eventFactory);
|
|
18
|
+
expect(detail.value).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it.each([{ kind: 'user', key: 999 }, { kind: 'multi', user: { key: 999 } }])
|
|
22
|
+
('does not coerce key for contexts', async (user) => {
|
|
23
|
+
const clause = { 'attribute': 'key', 'op': 'in', 'values': ['999'] };
|
|
24
|
+
const flag = makeBooleanFlagWithOneClause(clause);
|
|
25
|
+
const [err, detail, events] = await asyncEvaluate(Evaluator(), flag, user, eventFactory);
|
|
26
|
+
expect(detail.value).toBe(null);
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
async function testClauseMatch(clause, user, shouldBe) {
|
|
30
|
+
const flag = makeBooleanFlagWithOneClause(clause);
|
|
31
|
+
const [err, detail, events] = await asyncEvaluate(Evaluator(), flag, user, eventFactory);
|
|
32
|
+
expect(detail.value).toBe(shouldBe);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
it.each([
|
|
36
|
+
{ key: 'x', name: 'Bob' },
|
|
37
|
+
{ kind: 'user', key: 'x', name: 'Bob' },
|
|
38
|
+
{ kind: 'multi', user: { key: 'x', name: 'Bob' } },
|
|
39
|
+
])
|
|
40
|
+
('can match built-in attribute', async (user) => {
|
|
41
|
+
const clause = { attribute: 'name', op: 'in', values: ['Bob'] };
|
|
42
|
+
await testClauseMatch(clause, user, true);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it.each([
|
|
46
|
+
{ key: 'x', name: 'Bob', custom: { legs: 4 } },
|
|
47
|
+
{ kind: 'user', key: 'x', name: 'Bob', legs: 4 },
|
|
48
|
+
{ kind: 'multi', user: { key: 'x', name: 'Bob', legs: 4 } },
|
|
49
|
+
])
|
|
50
|
+
('can match custom attribute', async (user) => {
|
|
51
|
+
const clause = { attribute: 'legs', op: 'in', values: [4] };
|
|
52
|
+
await testClauseMatch(clause, user, true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it.each([
|
|
56
|
+
[{ key: 'x', name: 'Bob', custom: { '//': 4 } }, '//'],
|
|
57
|
+
[{ kind: 'user', key: 'x', name: 'Bob', '//': 4 }, '//'],
|
|
58
|
+
[{ kind: 'multi', user: { key: 'x', name: 'Bob', '//': 4 } }, '//'],
|
|
59
|
+
[{ key: 'x', name: 'Bob', custom: { '/~~': 4 } }, '/~~'],
|
|
60
|
+
[{ kind: 'user', key: 'x', name: 'Bob', '/~~': 4 }, '/~~'],
|
|
61
|
+
[{ kind: 'multi', user: { key: 'x', name: 'Bob', '/~~': 4 } }, '/~~'],
|
|
62
|
+
])
|
|
63
|
+
('can match attributes which would have be invalid references, but are valid literals', async (user, attribute) => {
|
|
64
|
+
const clause = { attribute, op: 'in', values: [4] };
|
|
65
|
+
await testClauseMatch(clause, user, true);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it.each([
|
|
69
|
+
{ key: 'x', name: 'Bob' },
|
|
70
|
+
{ kind: 'user', key: 'x', name: 'Bob' },
|
|
71
|
+
{ kind: 'multi', user: { key: 'x', name: 'Bob' } },
|
|
72
|
+
])
|
|
73
|
+
('does not match missing attribute', async (user) => {
|
|
74
|
+
const clause = { attribute: 'legs', op: 'in', values: [4] };
|
|
75
|
+
await testClauseMatch(clause, user, false);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it.each([
|
|
79
|
+
{ key: 'x', name: 'Bob' },
|
|
80
|
+
{ kind: 'user', key: 'x', name: 'Bob' },
|
|
81
|
+
{ kind: 'multi', user: { key: 'x', name: 'Bob' } },
|
|
82
|
+
])
|
|
83
|
+
('can have a negated clause', async (user) => {
|
|
84
|
+
const clause = { attribute: 'name', op: 'in', values: ['Bob'], negate: true };
|
|
85
|
+
await testClauseMatch(clause, user, false);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('does not overflow the call stack when evaluating a huge number of clauses', async () => {
|
|
89
|
+
const user = { key: 'user' };
|
|
90
|
+
const clauseCount = 5000;
|
|
91
|
+
const flag = {
|
|
92
|
+
key: 'flag',
|
|
93
|
+
targets: [],
|
|
94
|
+
on: true,
|
|
95
|
+
variations: [false, true],
|
|
96
|
+
fallthrough: { variation: 0 }
|
|
97
|
+
};
|
|
98
|
+
// Note, for this test to be meaningful, the clauses must all match the user, since we
|
|
99
|
+
// stop evaluating clauses on the first non-match.
|
|
100
|
+
const clause = makeClauseThatMatchesUser(user);
|
|
101
|
+
const clauses = [];
|
|
102
|
+
for (var i = 0; i < clauseCount; i++) {
|
|
103
|
+
clauses.push(clause);
|
|
104
|
+
}
|
|
105
|
+
var rule = { clauses: clauses, variation: 1 };
|
|
106
|
+
flag.rules = [rule];
|
|
107
|
+
const [err, detail, events] = await asyncEvaluate(Evaluator(), flag, user, eventFactory);
|
|
108
|
+
expect(err).toEqual(null);
|
|
109
|
+
expect(detail.value).toEqual(true);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it.each(['kind', '/kind'])('matches kind of implicit user', async (kind) => {
|
|
113
|
+
const clause = { attribute: kind, op: 'in', values: ['user'] };
|
|
114
|
+
const flag = makeBooleanFlagWithOneClause(clause);
|
|
115
|
+
const [err, detail, events] = await asyncEvaluate(Evaluator(), flag, { key: 'x', name: 'Bob' }, eventFactory);
|
|
116
|
+
expect(detail.value).toBe(true);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('implicit user kind does not match rules for non-user kinds', async () => {
|
|
120
|
+
const clause = { attribute: 'key', op: 'in', values: ['userkey'], contextKind: 'org' };
|
|
121
|
+
const flag = makeBooleanFlagWithOneClause(clause);
|
|
122
|
+
const [err, detail, events] = await asyncEvaluate(Evaluator(), flag, { key: 'x', name: 'Bob' }, eventFactory);
|
|
123
|
+
expect(detail.value).toBe(false);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('Evaluator - clause non-user single-kind contexts', () => {
|
|
128
|
+
it('does not match implicit user clauses to non-user contexts', async () => {
|
|
129
|
+
const clause = { attribute: 'name', op: 'in', values: ['Bob'] };
|
|
130
|
+
const flag = makeBooleanFlagWithOneClause(clause);
|
|
131
|
+
const context = { kind: 'org', name: 'Bob', key: 'bobkey' }
|
|
132
|
+
const [err, detail, events] = await asyncEvaluate(Evaluator(), flag, context, eventFactory);
|
|
133
|
+
expect(detail.value).toBe(false);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('cannot use an object attribute for a match.', async () => {
|
|
137
|
+
const clause = { attribute: 'complex', op: 'in', values: [{ thing: true }], contextKind: 'org' };
|
|
138
|
+
const flag = makeBooleanFlagWithOneClause(clause);
|
|
139
|
+
const context = { kind: 'org', name: 'Bob', key: 'bobkey', complex: { thing: true } }
|
|
140
|
+
const [err, detail, events] = await asyncEvaluate(Evaluator(), flag, context, eventFactory);
|
|
141
|
+
expect(detail.value).toBe(false);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('does match clauses for the correct context kind', async () => {
|
|
145
|
+
const clause = { attribute: 'name', op: 'in', values: ['Bob'], contextKind: 'org' };
|
|
146
|
+
const flag = makeBooleanFlagWithOneClause(clause);
|
|
147
|
+
const context = { kind: 'org', name: 'Bob', key: 'bobkey' }
|
|
148
|
+
const [err, detail, events] = await asyncEvaluate(Evaluator(), flag, context, eventFactory);
|
|
149
|
+
expect(detail.value).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it.each(['kind', '/kind'])('matches clauses for the kind attribute', async (kind) => {
|
|
153
|
+
// The context kind here should not matter, but the 'kind' attribute should.
|
|
154
|
+
const clause = { attribute: kind, op: 'in', values: ['org'], contextKind: 'potato' };
|
|
155
|
+
const flag = makeBooleanFlagWithOneClause(clause);
|
|
156
|
+
const context = { kind: 'org', name: 'Bob', key: 'bobkey' }
|
|
157
|
+
const [err, detail, events] = await asyncEvaluate(Evaluator(), flag, context, eventFactory);
|
|
158
|
+
expect(detail.value).toBe(true);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it.each(['kind', '/kind'])('does not match clauses for the kind attribute if the kind does not match',
|
|
162
|
+
async (kind) => {
|
|
163
|
+
// The context kind here should not matter, but the 'kind' attribute should.
|
|
164
|
+
const clause = { attribute: kind, op: 'in', values: ['org'], contextKind: 'potato' };
|
|
165
|
+
const flag = makeBooleanFlagWithOneClause(clause);
|
|
166
|
+
const context = { kind: 'party', name: 'Bob', key: 'bobkey' }
|
|
167
|
+
const [err, detail, events] = await asyncEvaluate(Evaluator(), flag, context, eventFactory);
|
|
168
|
+
expect(detail.value).toBe(false);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe('Evaluator - clause multi-kind contexts', () => {
|
|
173
|
+
it('does match clauses correctly with multiple contexts', async () => {
|
|
174
|
+
const clause1 = { attribute: 'region', op: 'in', values: ['north'], contextKind: 'park' };
|
|
175
|
+
const clause2 = { attribute: 'count', op: 'in', values: [5], contextKind: 'party' };
|
|
176
|
+
|
|
177
|
+
const context = {
|
|
178
|
+
kind: 'multi',
|
|
179
|
+
park: {
|
|
180
|
+
key: 'park',
|
|
181
|
+
region: 'north'
|
|
182
|
+
},
|
|
183
|
+
party: {
|
|
184
|
+
key: 'party',
|
|
185
|
+
count: 5
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const flag = makeBooleanFlagWithRules([{ clauses: [clause1, clause2], variation: 1 }]);
|
|
190
|
+
const [err, detail, events] = await asyncEvaluate(Evaluator(), flag, context, eventFactory);
|
|
191
|
+
expect(detail.value).toBe(true);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('does not match the values from the wrong contexts', async () => {
|
|
195
|
+
const clause1 = { attribute: 'region', op: 'in', values: ['north'], contextKind: 'park' };
|
|
196
|
+
const clause2 = { attribute: 'count', op: 'in', values: [5], contextKind: 'party' };
|
|
197
|
+
|
|
198
|
+
const context = {
|
|
199
|
+
kind: 'multi',
|
|
200
|
+
park: {
|
|
201
|
+
key: 'park',
|
|
202
|
+
count: 5,
|
|
203
|
+
},
|
|
204
|
+
party: {
|
|
205
|
+
key: 'party',
|
|
206
|
+
region: 'north'
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const flag = makeBooleanFlagWithRules([{ clauses: [clause1, clause2], variation: 1 }]);
|
|
211
|
+
const [err, detail, events] = await asyncEvaluate(Evaluator(), flag, context, eventFactory);
|
|
212
|
+
expect(detail.value).toBe(false);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('can check for the presence of contexts', async () => {
|
|
216
|
+
const clause = { attribute: 'kind', op: 'in', values: ['party'] };
|
|
217
|
+
|
|
218
|
+
const context = {
|
|
219
|
+
kind: 'multi',
|
|
220
|
+
park: {
|
|
221
|
+
key: 'park',
|
|
222
|
+
count: 5,
|
|
223
|
+
},
|
|
224
|
+
party: {
|
|
225
|
+
key: 'party',
|
|
226
|
+
region: 'north'
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const flag = makeBooleanFlagWithOneClause(clause);
|
|
231
|
+
const [err, detail, events] = await asyncEvaluate(Evaluator(), flag, context, eventFactory);
|
|
232
|
+
expect(detail.value).toBe(true);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('does not match if the kind is not in the context', async () => {
|
|
236
|
+
const clause = { attribute: 'kind', op: 'in', values: ['zoo'] };
|
|
237
|
+
|
|
238
|
+
const context = {
|
|
239
|
+
kind: 'multi',
|
|
240
|
+
park: {
|
|
241
|
+
key: 'park',
|
|
242
|
+
count: 5,
|
|
243
|
+
},
|
|
244
|
+
party: {
|
|
245
|
+
key: 'party',
|
|
246
|
+
region: 'north'
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const flag = makeBooleanFlagWithOneClause(clause);
|
|
251
|
+
const [err, detail, events] = await asyncEvaluate(Evaluator(), flag, context, eventFactory);
|
|
252
|
+
expect(detail.value).toBe(false);
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
describe('when given malformed flags', () => {
|
|
257
|
+
it('handles clauses with malformed attribute references', async () => {
|
|
258
|
+
const clause = { attribute: '//region', op: 'in', values: ['north'], contextKind: 'park' };
|
|
259
|
+
|
|
260
|
+
const context = {
|
|
261
|
+
kind: 'multi',
|
|
262
|
+
park: {
|
|
263
|
+
key: 'park',
|
|
264
|
+
region: 'north'
|
|
265
|
+
},
|
|
266
|
+
party: {
|
|
267
|
+
key: 'party',
|
|
268
|
+
count: 5
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
const flag = makeBooleanFlagWithRules([{ clauses: [clause], variation: 1 }]);
|
|
273
|
+
const [err, detail, events] = await asyncEvaluate(Evaluator(), flag, context, eventFactory);
|
|
274
|
+
expect(detail.reason).toEqual({ kind: 'ERROR', errorKind: 'MALFORMED_FLAG' });
|
|
275
|
+
expect(detail.value).toBe(null);
|
|
276
|
+
});
|
|
277
|
+
});
|