@featurevisor/sdk 0.36.0 → 0.38.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/CHANGELOG.md +22 -0
- package/README.md +14 -14
- package/coverage/clover.xml +378 -315
- package/coverage/coverage-final.json +7 -7
- package/coverage/lcov-report/bucket.ts.html +4 -4
- package/coverage/lcov-report/conditions.ts.html +38 -38
- package/coverage/lcov-report/datafileReader.ts.html +4 -4
- package/coverage/lcov-report/emitter.ts.html +1 -1
- package/coverage/lcov-report/feature.ts.html +80 -20
- package/coverage/lcov-report/index.html +28 -28
- package/coverage/lcov-report/instance.ts.html +754 -220
- package/coverage/lcov-report/logger.ts.html +3 -3
- package/coverage/lcov-report/segments.ts.html +12 -12
- package/coverage/lcov.info +661 -559
- package/dist/index.js +1 -1
- package/dist/index.js.gz +0 -0
- package/dist/index.js.map +1 -1
- package/lib/conditions.d.ts +3 -3
- package/lib/conditions.js +35 -35
- package/lib/conditions.js.map +1 -1
- package/lib/feature.d.ts +4 -3
- package/lib/feature.js +13 -5
- package/lib/feature.js.map +1 -1
- package/lib/instance.d.ts +36 -27
- package/lib/instance.js +289 -148
- package/lib/instance.js.map +1 -1
- package/lib/segments.d.ts +3 -3
- package/lib/segments.js +8 -8
- package/lib/segments.js.map +1 -1
- package/package.json +3 -3
- package/src/conditions.ts +37 -37
- package/src/feature.ts +26 -6
- package/src/instance.spec.ts +64 -61
- package/src/instance.ts +325 -147
- package/src/segments.ts +9 -9
package/src/instance.spec.ts
CHANGED
|
@@ -54,17 +54,16 @@ describe("sdk: instance", function () {
|
|
|
54
54
|
features: [
|
|
55
55
|
{
|
|
56
56
|
key: "test",
|
|
57
|
-
defaultVariation: false,
|
|
58
57
|
bucketBy: "userId",
|
|
59
|
-
variations: [{ value:
|
|
58
|
+
variations: [{ value: "control" }, { value: "treatment" }],
|
|
60
59
|
traffic: [
|
|
61
60
|
{
|
|
62
61
|
key: "1",
|
|
63
62
|
segments: "*",
|
|
64
63
|
percentage: 100000,
|
|
65
64
|
allocation: [
|
|
66
|
-
{ variation:
|
|
67
|
-
{ variation:
|
|
65
|
+
{ variation: "control", range: [0, 100000] },
|
|
66
|
+
{ variation: "treatment", range: [0, 0] },
|
|
68
67
|
],
|
|
69
68
|
},
|
|
70
69
|
],
|
|
@@ -73,18 +72,20 @@ describe("sdk: instance", function () {
|
|
|
73
72
|
attributes: [],
|
|
74
73
|
segments: [],
|
|
75
74
|
},
|
|
76
|
-
configureBucketKey: function (feature,
|
|
75
|
+
configureBucketKey: function (feature, context, bucketKey) {
|
|
77
76
|
capturedBucketKey = bucketKey;
|
|
78
77
|
|
|
79
78
|
return bucketKey;
|
|
80
79
|
},
|
|
81
80
|
});
|
|
82
81
|
|
|
83
|
-
const
|
|
82
|
+
const featureKey = "test";
|
|
83
|
+
const context = {
|
|
84
84
|
userId: "123",
|
|
85
|
-
}
|
|
85
|
+
};
|
|
86
86
|
|
|
87
|
-
expect(
|
|
87
|
+
expect(sdk.isEnabled(featureKey, context)).toEqual(true);
|
|
88
|
+
expect(sdk.getVariation(featureKey, context)).toEqual("control");
|
|
88
89
|
expect(capturedBucketKey).toEqual("123.test");
|
|
89
90
|
});
|
|
90
91
|
|
|
@@ -98,17 +99,16 @@ describe("sdk: instance", function () {
|
|
|
98
99
|
features: [
|
|
99
100
|
{
|
|
100
101
|
key: "test",
|
|
101
|
-
defaultVariation: false,
|
|
102
102
|
bucketBy: ["userId", "organizationId"],
|
|
103
|
-
variations: [{ value:
|
|
103
|
+
variations: [{ value: "control" }, { value: "treatment" }],
|
|
104
104
|
traffic: [
|
|
105
105
|
{
|
|
106
106
|
key: "1",
|
|
107
107
|
segments: "*",
|
|
108
108
|
percentage: 100000,
|
|
109
109
|
allocation: [
|
|
110
|
-
{ variation:
|
|
111
|
-
{ variation:
|
|
110
|
+
{ variation: "control", range: [0, 100000] },
|
|
111
|
+
{ variation: "treatment", range: [0, 0] },
|
|
112
112
|
],
|
|
113
113
|
},
|
|
114
114
|
],
|
|
@@ -117,19 +117,20 @@ describe("sdk: instance", function () {
|
|
|
117
117
|
attributes: [],
|
|
118
118
|
segments: [],
|
|
119
119
|
},
|
|
120
|
-
configureBucketKey: function (feature,
|
|
120
|
+
configureBucketKey: function (feature, context, bucketKey) {
|
|
121
121
|
capturedBucketKey = bucketKey;
|
|
122
122
|
|
|
123
123
|
return bucketKey;
|
|
124
124
|
},
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
-
const
|
|
127
|
+
const featureKey = "test";
|
|
128
|
+
const context = {
|
|
128
129
|
userId: "123",
|
|
129
130
|
organizationId: "456",
|
|
130
|
-
}
|
|
131
|
+
};
|
|
131
132
|
|
|
132
|
-
expect(
|
|
133
|
+
expect(sdk.getVariation(featureKey, context)).toEqual("control");
|
|
133
134
|
expect(capturedBucketKey).toEqual("123.456.test");
|
|
134
135
|
});
|
|
135
136
|
|
|
@@ -143,17 +144,16 @@ describe("sdk: instance", function () {
|
|
|
143
144
|
features: [
|
|
144
145
|
{
|
|
145
146
|
key: "test",
|
|
146
|
-
defaultVariation: false,
|
|
147
147
|
bucketBy: { or: ["userId", "deviceId"] },
|
|
148
|
-
variations: [{ value:
|
|
148
|
+
variations: [{ value: "control" }, { value: "treatment" }],
|
|
149
149
|
traffic: [
|
|
150
150
|
{
|
|
151
151
|
key: "1",
|
|
152
152
|
segments: "*",
|
|
153
153
|
percentage: 100000,
|
|
154
154
|
allocation: [
|
|
155
|
-
{ variation:
|
|
156
|
-
{ variation:
|
|
155
|
+
{ variation: "control", range: [0, 100000] },
|
|
156
|
+
{ variation: "treatment", range: [0, 0] },
|
|
157
157
|
],
|
|
158
158
|
},
|
|
159
159
|
],
|
|
@@ -162,7 +162,7 @@ describe("sdk: instance", function () {
|
|
|
162
162
|
attributes: [],
|
|
163
163
|
segments: [],
|
|
164
164
|
},
|
|
165
|
-
configureBucketKey: function (feature,
|
|
165
|
+
configureBucketKey: function (feature, context, bucketKey) {
|
|
166
166
|
capturedBucketKey = bucketKey;
|
|
167
167
|
|
|
168
168
|
return bucketKey;
|
|
@@ -170,22 +170,28 @@ describe("sdk: instance", function () {
|
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
expect(
|
|
173
|
-
sdk.
|
|
173
|
+
sdk.isEnabled("test", {
|
|
174
174
|
userId: "123",
|
|
175
175
|
deviceId: "456",
|
|
176
176
|
}),
|
|
177
177
|
).toEqual(true);
|
|
178
|
+
expect(
|
|
179
|
+
sdk.getVariation("test", {
|
|
180
|
+
userId: "123",
|
|
181
|
+
deviceId: "456",
|
|
182
|
+
}),
|
|
183
|
+
).toEqual("control");
|
|
178
184
|
expect(capturedBucketKey).toEqual("123.test");
|
|
179
185
|
|
|
180
186
|
expect(
|
|
181
187
|
sdk.getVariation("test", {
|
|
182
188
|
deviceId: "456",
|
|
183
189
|
}),
|
|
184
|
-
).toEqual(
|
|
190
|
+
).toEqual("control");
|
|
185
191
|
expect(capturedBucketKey).toEqual("456.test");
|
|
186
192
|
});
|
|
187
193
|
|
|
188
|
-
it("should intercept
|
|
194
|
+
it("should intercept context", function () {
|
|
189
195
|
let intercepted = false;
|
|
190
196
|
|
|
191
197
|
const sdk = createInstance({
|
|
@@ -195,17 +201,16 @@ describe("sdk: instance", function () {
|
|
|
195
201
|
features: [
|
|
196
202
|
{
|
|
197
203
|
key: "test",
|
|
198
|
-
defaultVariation: false,
|
|
199
204
|
bucketBy: "userId",
|
|
200
|
-
variations: [{ value:
|
|
205
|
+
variations: [{ value: "control" }, { value: "treatment" }],
|
|
201
206
|
traffic: [
|
|
202
207
|
{
|
|
203
208
|
key: "1",
|
|
204
209
|
segments: "*",
|
|
205
210
|
percentage: 100000,
|
|
206
211
|
allocation: [
|
|
207
|
-
{ variation:
|
|
208
|
-
{ variation:
|
|
212
|
+
{ variation: "control", range: [0, 100000] },
|
|
213
|
+
{ variation: "treatment", range: [0, 0] },
|
|
209
214
|
],
|
|
210
215
|
},
|
|
211
216
|
],
|
|
@@ -214,11 +219,11 @@ describe("sdk: instance", function () {
|
|
|
214
219
|
attributes: [],
|
|
215
220
|
segments: [],
|
|
216
221
|
},
|
|
217
|
-
|
|
222
|
+
interceptContext: function (context) {
|
|
218
223
|
intercepted = true;
|
|
219
224
|
|
|
220
225
|
return {
|
|
221
|
-
...
|
|
226
|
+
...context,
|
|
222
227
|
};
|
|
223
228
|
},
|
|
224
229
|
});
|
|
@@ -227,7 +232,7 @@ describe("sdk: instance", function () {
|
|
|
227
232
|
userId: "123",
|
|
228
233
|
});
|
|
229
234
|
|
|
230
|
-
expect(variation).toEqual(
|
|
235
|
+
expect(variation).toEqual("control");
|
|
231
236
|
expect(intercepted).toEqual(true);
|
|
232
237
|
});
|
|
233
238
|
|
|
@@ -241,17 +246,16 @@ describe("sdk: instance", function () {
|
|
|
241
246
|
features: [
|
|
242
247
|
{
|
|
243
248
|
key: "test",
|
|
244
|
-
defaultVariation: false,
|
|
245
249
|
bucketBy: "userId",
|
|
246
|
-
variations: [{ value:
|
|
250
|
+
variations: [{ value: "control" }, { value: "treatment" }],
|
|
247
251
|
traffic: [
|
|
248
252
|
{
|
|
249
253
|
key: "1",
|
|
250
254
|
segments: "*",
|
|
251
255
|
percentage: 100000,
|
|
252
256
|
allocation: [
|
|
253
|
-
{ variation:
|
|
254
|
-
{ variation:
|
|
257
|
+
{ variation: "control", range: [0, 100000] },
|
|
258
|
+
{ variation: "treatment", range: [0, 0] },
|
|
255
259
|
],
|
|
256
260
|
},
|
|
257
261
|
],
|
|
@@ -270,14 +274,14 @@ describe("sdk: instance", function () {
|
|
|
270
274
|
});
|
|
271
275
|
|
|
272
276
|
expect(activated).toEqual(false);
|
|
273
|
-
expect(variation).toEqual(
|
|
277
|
+
expect(variation).toEqual("control");
|
|
274
278
|
|
|
275
279
|
const activatedVariation = sdk.activate("test", {
|
|
276
280
|
userId: "123",
|
|
277
281
|
});
|
|
278
282
|
|
|
279
283
|
expect(activated).toEqual(true);
|
|
280
|
-
expect(activatedVariation).toEqual(
|
|
284
|
+
expect(activatedVariation).toEqual("control");
|
|
281
285
|
});
|
|
282
286
|
|
|
283
287
|
it("should refresh datafile", function (done) {
|
|
@@ -292,17 +296,16 @@ describe("sdk: instance", function () {
|
|
|
292
296
|
features: [
|
|
293
297
|
{
|
|
294
298
|
key: "test",
|
|
295
|
-
defaultVariation: false,
|
|
296
299
|
bucketBy: "userId",
|
|
297
|
-
variations: [{ value:
|
|
300
|
+
variations: [{ value: "control" }, { value: "treatment" }],
|
|
298
301
|
traffic: [
|
|
299
302
|
{
|
|
300
303
|
key: "1",
|
|
301
304
|
segments: "*",
|
|
302
305
|
percentage: 100000,
|
|
303
306
|
allocation: [
|
|
304
|
-
{ variation:
|
|
305
|
-
{ variation:
|
|
307
|
+
{ variation: "control", range: [0, 100000] },
|
|
308
|
+
{ variation: "treatment", range: [0, 0] },
|
|
306
309
|
],
|
|
307
310
|
},
|
|
308
311
|
],
|
|
@@ -351,7 +354,8 @@ describe("sdk: instance", function () {
|
|
|
351
354
|
const sdk = createInstance({
|
|
352
355
|
stickyFeatures: {
|
|
353
356
|
test: {
|
|
354
|
-
|
|
357
|
+
enabled: true,
|
|
358
|
+
variation: "control",
|
|
355
359
|
},
|
|
356
360
|
},
|
|
357
361
|
datafileUrl: "http://localhost:3000/datafile.json",
|
|
@@ -362,17 +366,16 @@ describe("sdk: instance", function () {
|
|
|
362
366
|
features: [
|
|
363
367
|
{
|
|
364
368
|
key: "test",
|
|
365
|
-
defaultVariation: false,
|
|
366
369
|
bucketBy: "userId",
|
|
367
|
-
variations: [{ value:
|
|
370
|
+
variations: [{ value: "control" }, { value: "treatment" }],
|
|
368
371
|
traffic: [
|
|
369
372
|
{
|
|
370
373
|
key: "1",
|
|
371
374
|
segments: "*",
|
|
372
375
|
percentage: 100000,
|
|
373
376
|
allocation: [
|
|
374
|
-
{ variation:
|
|
375
|
-
{ variation:
|
|
377
|
+
{ variation: "control", range: [0, 0] },
|
|
378
|
+
{ variation: "treatment", range: [0, 100000] },
|
|
376
379
|
],
|
|
377
380
|
},
|
|
378
381
|
],
|
|
@@ -390,28 +393,28 @@ describe("sdk: instance", function () {
|
|
|
390
393
|
},
|
|
391
394
|
});
|
|
392
395
|
|
|
393
|
-
// initially
|
|
396
|
+
// initially control
|
|
394
397
|
expect(
|
|
395
398
|
sdk.getVariation("test", {
|
|
396
399
|
userId: "123",
|
|
397
400
|
}),
|
|
398
|
-
).toEqual(
|
|
401
|
+
).toEqual("control");
|
|
399
402
|
|
|
400
403
|
setTimeout(function () {
|
|
401
|
-
// still
|
|
404
|
+
// still control after fetching datafile
|
|
402
405
|
expect(
|
|
403
406
|
sdk.getVariation("test", {
|
|
404
407
|
userId: "123",
|
|
405
408
|
}),
|
|
406
|
-
).toEqual(
|
|
409
|
+
).toEqual("control");
|
|
407
410
|
|
|
408
|
-
// unsetting sticky features will make it
|
|
411
|
+
// unsetting sticky features will make it treatment
|
|
409
412
|
sdk.setStickyFeatures({});
|
|
410
413
|
expect(
|
|
411
414
|
sdk.getVariation("test", {
|
|
412
415
|
userId: "123",
|
|
413
416
|
}),
|
|
414
|
-
).toEqual(
|
|
417
|
+
).toEqual("treatment");
|
|
415
418
|
|
|
416
419
|
done();
|
|
417
420
|
}, 75);
|
|
@@ -421,7 +424,8 @@ describe("sdk: instance", function () {
|
|
|
421
424
|
const sdk = createInstance({
|
|
422
425
|
initialFeatures: {
|
|
423
426
|
test: {
|
|
424
|
-
|
|
427
|
+
enabled: true,
|
|
428
|
+
variation: "control",
|
|
425
429
|
},
|
|
426
430
|
},
|
|
427
431
|
datafileUrl: "http://localhost:3000/datafile.json",
|
|
@@ -432,17 +436,16 @@ describe("sdk: instance", function () {
|
|
|
432
436
|
features: [
|
|
433
437
|
{
|
|
434
438
|
key: "test",
|
|
435
|
-
defaultVariation: false,
|
|
436
439
|
bucketBy: "userId",
|
|
437
|
-
variations: [{ value:
|
|
440
|
+
variations: [{ value: "control" }, { value: "treatment" }],
|
|
438
441
|
traffic: [
|
|
439
442
|
{
|
|
440
443
|
key: "1",
|
|
441
444
|
segments: "*",
|
|
442
445
|
percentage: 100000,
|
|
443
446
|
allocation: [
|
|
444
|
-
{ variation:
|
|
445
|
-
{ variation:
|
|
447
|
+
{ variation: "control", range: [0, 0] },
|
|
448
|
+
{ variation: "treatment", range: [0, 100000] },
|
|
446
449
|
],
|
|
447
450
|
},
|
|
448
451
|
],
|
|
@@ -460,20 +463,20 @@ describe("sdk: instance", function () {
|
|
|
460
463
|
},
|
|
461
464
|
});
|
|
462
465
|
|
|
463
|
-
// initially
|
|
466
|
+
// initially control
|
|
464
467
|
expect(
|
|
465
468
|
sdk.getVariation("test", {
|
|
466
469
|
userId: "123",
|
|
467
470
|
}),
|
|
468
|
-
).toEqual(
|
|
471
|
+
).toEqual("control");
|
|
469
472
|
|
|
470
473
|
setTimeout(function () {
|
|
471
|
-
//
|
|
474
|
+
// treatment after fetching datafile
|
|
472
475
|
expect(
|
|
473
476
|
sdk.getVariation("test", {
|
|
474
477
|
userId: "123",
|
|
475
478
|
}),
|
|
476
|
-
).toEqual(
|
|
479
|
+
).toEqual("treatment");
|
|
477
480
|
|
|
478
481
|
done();
|
|
479
482
|
}, 75);
|