@featurevisor/sdk 0.47.1 → 0.47.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.
@@ -27,17 +27,17 @@ FN:93,(anonymous_4)
27
27
  FN:104,(anonymous_5)
28
28
  FNF:6
29
29
  FNH:6
30
- FNDA:135,conditionIsMatched
31
- FNDA:283,allConditionsAreMatched
30
+ FNDA:174,conditionIsMatched
31
+ FNDA:361,allConditionsAreMatched
32
32
  FNDA:37,(anonymous_2)
33
33
  FNDA:23,(anonymous_3)
34
34
  FNDA:9,(anonymous_4)
35
- FNDA:108,(anonymous_5)
35
+ FNDA:147,(anonymous_5)
36
36
  DA:1,3
37
37
  DA:5,3
38
- DA:6,135
39
- DA:8,135
40
- DA:9,80
38
+ DA:6,174
39
+ DA:8,174
40
+ DA:9,119
41
41
  DA:10,55
42
42
  DA:11,2
43
43
  DA:12,53
@@ -85,21 +85,21 @@ DA:67,4
85
85
  DA:68,4
86
86
  DA:72,0
87
87
  DA:75,3
88
- DA:79,283
89
- DA:80,135
90
- DA:83,148
88
+ DA:79,361
89
+ DA:80,174
90
+ DA:83,187
91
91
  DA:84,37
92
- DA:87,125
92
+ DA:87,164
93
93
  DA:88,23
94
- DA:91,111
94
+ DA:91,150
95
95
  DA:92,6
96
96
  DA:94,9
97
- DA:103,105
98
- DA:104,108
97
+ DA:103,144
98
+ DA:104,147
99
99
  DA:107,0
100
100
  LF:64
101
101
  LH:62
102
- BRDA:8,0,0,80
102
+ BRDA:8,0,0,119
103
103
  BRDA:8,0,1,55
104
104
  BRDA:10,1,0,2
105
105
  BRDA:10,1,1,53
@@ -153,17 +153,17 @@ BRDA:63,26,1,6
153
153
  BRDA:65,27,0,2
154
154
  BRDA:65,27,1,4
155
155
  BRDA:67,28,0,4
156
- BRDA:79,29,0,135
156
+ BRDA:79,29,0,174
157
157
  BRDA:83,30,0,23
158
- BRDA:83,31,0,148
158
+ BRDA:83,31,0,187
159
159
  BRDA:83,31,1,23
160
160
  BRDA:87,32,0,14
161
- BRDA:87,33,0,125
161
+ BRDA:87,33,0,164
162
162
  BRDA:87,33,1,14
163
163
  BRDA:91,34,0,6
164
- BRDA:91,35,0,111
164
+ BRDA:91,35,0,150
165
165
  BRDA:91,35,1,6
166
- BRDA:103,36,0,105
166
+ BRDA:103,36,0,144
167
167
  BRF:65
168
168
  BRH:64
169
169
  end_of_record
@@ -181,51 +181,51 @@ FN:55,(anonymous_8)
181
181
  FN:64,(anonymous_9)
182
182
  FN:65,(anonymous_10)
183
183
  FNF:11
184
- FNH:8
185
- FNDA:14,parseJsonConditionsIfStringified
186
- FNDA:22,(anonymous_1)
187
- FNDA:1,(anonymous_2)
188
- FNDA:0,(anonymous_3)
189
- FNDA:1,(anonymous_4)
190
- FNDA:0,(anonymous_5)
191
- FNDA:0,(anonymous_6)
192
- FNDA:14,(anonymous_7)
193
- FNDA:38,(anonymous_8)
194
- FNDA:62,(anonymous_9)
195
- FNDA:68,(anonymous_10)
196
- DA:11,2
197
- DA:12,14
198
- DA:13,0
199
- DA:14,0
184
+ FNH:11
185
+ FNDA:55,parseJsonConditionsIfStringified
186
+ FNDA:23,(anonymous_1)
187
+ FNDA:2,(anonymous_2)
188
+ FNDA:1,(anonymous_3)
189
+ FNDA:2,(anonymous_4)
190
+ FNDA:1,(anonymous_5)
191
+ FNDA:1,(anonymous_6)
192
+ FNDA:56,(anonymous_7)
193
+ FNDA:177,(anonymous_8)
194
+ FNDA:64,(anonymous_9)
195
+ FNDA:70,(anonymous_10)
196
+ DA:11,3
197
+ DA:12,55
198
+ DA:13,1
199
+ DA:14,1
200
200
  DA:16,0
201
- DA:20,14
202
- DA:23,2
203
- DA:31,22
204
- DA:32,22
205
- DA:33,22
206
- DA:34,22
207
- DA:35,22
208
- DA:39,1
209
- DA:43,0
210
- DA:47,1
211
- DA:51,0
212
- DA:55,38
213
- DA:57,14
214
- DA:58,0
215
- DA:61,14
216
- DA:65,68
217
- DA:67,62
218
- DA:68,0
219
- DA:71,62
201
+ DA:20,55
202
+ DA:23,3
203
+ DA:31,23
204
+ DA:32,23
205
+ DA:33,23
206
+ DA:34,23
207
+ DA:35,23
208
+ DA:39,2
209
+ DA:43,1
210
+ DA:47,2
211
+ DA:51,1
212
+ DA:55,177
213
+ DA:57,56
214
+ DA:58,1
215
+ DA:61,55
216
+ DA:65,70
217
+ DA:67,64
218
+ DA:68,1
219
+ DA:71,63
220
220
  LF:24
221
- LH:17
222
- BRDA:12,0,0,0
223
- BRDA:12,1,0,14
224
- BRDA:12,1,1,0
225
- BRDA:57,2,0,0
226
- BRDA:67,3,0,0
221
+ LH:23
222
+ BRDA:12,0,0,1
223
+ BRDA:12,1,0,55
224
+ BRDA:12,1,1,1
225
+ BRDA:57,2,0,1
226
+ BRDA:67,3,0,1
227
227
  BRF:5
228
- BRH:1
228
+ BRH:5
229
229
  end_of_record
230
230
  TN:
231
231
  SF:src/emitter.ts
@@ -1138,54 +1138,54 @@ FN:36,(anonymous_3)
1138
1138
  FN:43,(anonymous_4)
1139
1139
  FN:50,(anonymous_5)
1140
1140
  FNF:6
1141
- FNH:3
1142
- FNDA:14,segmentIsMatched
1143
- FNDA:85,allGroupSegmentsAreMatched
1144
- FNDA:0,(anonymous_2)
1145
- FNDA:0,(anonymous_3)
1146
- FNDA:0,(anonymous_4)
1147
- FNDA:14,(anonymous_5)
1141
+ FNH:6
1142
+ FNDA:53,segmentIsMatched
1143
+ FNDA:164,allGroupSegmentsAreMatched
1144
+ FNDA:24,(anonymous_2)
1145
+ FNDA:12,(anonymous_3)
1146
+ FNDA:2,(anonymous_4)
1147
+ FNDA:33,(anonymous_5)
1148
1148
  DA:2,2
1149
1149
  DA:5,2
1150
- DA:6,14
1150
+ DA:6,53
1151
1151
  DA:9,2
1152
- DA:14,85
1152
+ DA:14,164
1153
1153
  DA:15,63
1154
- DA:18,22
1155
- DA:19,14
1156
- DA:21,14
1157
- DA:22,14
1154
+ DA:18,101
1155
+ DA:19,53
1156
+ DA:21,53
1157
+ DA:22,53
1158
1158
  DA:25,0
1159
- DA:28,8
1160
- DA:29,8
1161
- DA:30,0
1162
- DA:31,0
1163
- DA:35,8
1164
- DA:36,0
1165
- DA:37,0
1166
- DA:41,8
1167
- DA:42,0
1168
- DA:44,0
1169
- DA:49,8
1170
- DA:50,8
1171
- DA:51,14
1159
+ DA:28,48
1160
+ DA:29,48
1161
+ DA:30,15
1162
+ DA:31,24
1163
+ DA:35,33
1164
+ DA:36,8
1165
+ DA:37,12
1166
+ DA:41,25
1167
+ DA:42,2
1168
+ DA:44,2
1169
+ DA:49,23
1170
+ DA:50,23
1171
+ DA:51,33
1172
1172
  DA:55,0
1173
1173
  LF:25
1174
- LH:17
1174
+ LH:23
1175
1175
  BRDA:14,0,0,63
1176
- BRDA:18,1,0,14
1177
- BRDA:21,2,0,14
1178
- BRDA:28,3,0,8
1179
- BRDA:29,4,0,0
1180
- BRDA:29,5,0,8
1181
- BRDA:29,5,1,0
1182
- BRDA:35,6,0,0
1183
- BRDA:35,7,0,8
1184
- BRDA:35,7,1,0
1185
- BRDA:41,8,0,0
1186
- BRDA:41,9,0,8
1187
- BRDA:41,9,1,0
1188
- BRDA:49,10,0,8
1176
+ BRDA:18,1,0,53
1177
+ BRDA:21,2,0,53
1178
+ BRDA:28,3,0,48
1179
+ BRDA:29,4,0,15
1180
+ BRDA:29,5,0,48
1181
+ BRDA:29,5,1,15
1182
+ BRDA:35,6,0,8
1183
+ BRDA:35,7,0,33
1184
+ BRDA:35,7,1,8
1185
+ BRDA:41,8,0,2
1186
+ BRDA:41,9,0,25
1187
+ BRDA:41,9,1,2
1188
+ BRDA:49,10,0,23
1189
1189
  BRF:14
1190
- BRH:8
1190
+ BRH:14
1191
1191
  end_of_record
package/dist/index.js.gz CHANGED
Binary file
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@featurevisor/sdk",
3
- "version": "0.47.1",
3
+ "version": "0.47.3",
4
4
  "description": "Featurevisor SDK for Node.js and the browser",
5
5
  "main": "dist/index.js",
6
6
  "module": "lib/index.js",
@@ -49,5 +49,5 @@
49
49
  "compare-versions": "^6.0.0-rc.1",
50
50
  "murmurhash": "^2.0.1"
51
51
  },
52
- "gitHead": "1f71f945cf6bbfe420d41ae03ac205cbf30aba83"
52
+ "gitHead": "8683c2e3569337c375800524996eb7048fac9254"
53
53
  }
@@ -0,0 +1,89 @@
1
+ import { DatafileContent } from "@featurevisor/types";
2
+ import { DatafileReader } from "./datafileReader";
3
+
4
+ describe("sdk: DatafileReader", function () {
5
+ it("should be a function", function () {
6
+ expect(typeof DatafileReader).toEqual("function");
7
+ });
8
+
9
+ it("should return requested entities", function () {
10
+ const datafileJson: DatafileContent = {
11
+ schemaVersion: "1",
12
+ revision: "1",
13
+ attributes: [
14
+ {
15
+ key: "userId",
16
+ type: "string",
17
+ capture: true,
18
+ },
19
+ {
20
+ key: "country",
21
+ type: "string",
22
+ },
23
+ ],
24
+ segments: [
25
+ {
26
+ key: "netherlands",
27
+ conditions: [
28
+ {
29
+ attribute: "country",
30
+ operator: "equals",
31
+ value: "nl",
32
+ },
33
+ ],
34
+ },
35
+ {
36
+ key: "germany",
37
+ conditions: JSON.stringify([
38
+ {
39
+ attribute: "country",
40
+ operator: "equals",
41
+ value: "de",
42
+ },
43
+ ]),
44
+ },
45
+ ],
46
+ features: [
47
+ {
48
+ key: "test",
49
+ bucketBy: "userId",
50
+ variations: [
51
+ { value: "control" },
52
+ {
53
+ value: "treatment",
54
+ variables: [
55
+ {
56
+ key: "showSidebar",
57
+ value: true,
58
+ },
59
+ ],
60
+ },
61
+ ],
62
+ traffic: [
63
+ {
64
+ key: "1",
65
+ segments: "*",
66
+ percentage: 100000,
67
+ allocation: [
68
+ { variation: "control", range: [0, 0] },
69
+ { variation: "treatment", range: [0, 100000] },
70
+ ],
71
+ },
72
+ ],
73
+ },
74
+ ],
75
+ };
76
+
77
+ const reader = new DatafileReader(datafileJson);
78
+
79
+ expect(reader.getRevision()).toEqual("1");
80
+ expect(reader.getSchemaVersion()).toEqual("1");
81
+ expect(reader.getAllAttributes()).toEqual(datafileJson.attributes);
82
+ expect(reader.getAttribute("userId")).toEqual(datafileJson.attributes[0]);
83
+ expect(reader.getSegment("netherlands")).toEqual(datafileJson.segments[0]);
84
+ expect((reader.getSegment("germany") as any).conditions[0].value).toEqual("de");
85
+ expect(reader.getSegment("belgium")).toEqual(undefined);
86
+ expect(reader.getFeature("test")).toEqual(datafileJson.features[0]);
87
+ expect(reader.getFeature("test2")).toEqual(undefined);
88
+ });
89
+ });
@@ -41,6 +41,29 @@ describe("sdk: Segments", function () {
41
41
  and: ["netherlands", { or: ["mobileUsers", "desktopUsers"] }],
42
42
  },
43
43
  },
44
+
45
+ // german
46
+ {
47
+ key: "germanMobileUsers",
48
+ segments: [
49
+ {
50
+ and: ["mobileUsers", "germany"],
51
+ },
52
+ ],
53
+ },
54
+ {
55
+ key: "germanNonMobileUsers",
56
+ segments: [
57
+ {
58
+ and: [
59
+ "germany",
60
+ {
61
+ not: ["mobileUsers"],
62
+ },
63
+ ],
64
+ },
65
+ ],
66
+ },
44
67
  ];
45
68
 
46
69
  const datafileContent: DatafileContent = {
@@ -192,5 +215,167 @@ describe("sdk: Segments", function () {
192
215
  ),
193
216
  ).toEqual(false);
194
217
  });
218
+
219
+ it("should match dutchMobileOrDesktopUsers", function () {
220
+ const group = groups.find((g) => g.key === "dutchMobileOrDesktopUsers") as Group;
221
+
222
+ // match
223
+ expect(
224
+ allGroupSegmentsAreMatched(
225
+ group.segments,
226
+ { country: "nl", deviceType: "mobile" },
227
+ datafileReader,
228
+ ),
229
+ ).toEqual(true);
230
+ expect(
231
+ allGroupSegmentsAreMatched(
232
+ group.segments,
233
+ { country: "nl", deviceType: "mobile", browser: "chrome" },
234
+ datafileReader,
235
+ ),
236
+ ).toEqual(true);
237
+ expect(
238
+ allGroupSegmentsAreMatched(
239
+ group.segments,
240
+ { country: "nl", deviceType: "desktop" },
241
+ datafileReader,
242
+ ),
243
+ ).toEqual(true);
244
+ expect(
245
+ allGroupSegmentsAreMatched(
246
+ group.segments,
247
+ { country: "nl", deviceType: "desktop", browser: "chrome" },
248
+ datafileReader,
249
+ ),
250
+ ).toEqual(true);
251
+
252
+ // not match
253
+ expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader)).toEqual(false);
254
+ expect(
255
+ allGroupSegmentsAreMatched(
256
+ group.segments,
257
+ { country: "de", deviceType: "mobile" },
258
+ datafileReader,
259
+ ),
260
+ ).toEqual(false);
261
+ expect(
262
+ allGroupSegmentsAreMatched(
263
+ group.segments,
264
+ { country: "de", deviceType: "desktop" },
265
+ datafileReader,
266
+ ),
267
+ ).toEqual(false);
268
+ });
269
+
270
+ it("should match dutchMobileOrDesktopUsers2", function () {
271
+ const group = groups.find((g) => g.key === "dutchMobileOrDesktopUsers2") as Group;
272
+
273
+ // match
274
+ expect(
275
+ allGroupSegmentsAreMatched(
276
+ group.segments,
277
+ { country: "nl", deviceType: "mobile" },
278
+ datafileReader,
279
+ ),
280
+ ).toEqual(true);
281
+ expect(
282
+ allGroupSegmentsAreMatched(
283
+ group.segments,
284
+ { country: "nl", deviceType: "mobile", browser: "chrome" },
285
+ datafileReader,
286
+ ),
287
+ ).toEqual(true);
288
+ expect(
289
+ allGroupSegmentsAreMatched(
290
+ group.segments,
291
+ { country: "nl", deviceType: "desktop" },
292
+ datafileReader,
293
+ ),
294
+ ).toEqual(true);
295
+ expect(
296
+ allGroupSegmentsAreMatched(
297
+ group.segments,
298
+ { country: "nl", deviceType: "desktop", browser: "chrome" },
299
+ datafileReader,
300
+ ),
301
+ ).toEqual(true);
302
+
303
+ // not match
304
+ expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader)).toEqual(false);
305
+ expect(
306
+ allGroupSegmentsAreMatched(
307
+ group.segments,
308
+ { country: "de", deviceType: "mobile" },
309
+ datafileReader,
310
+ ),
311
+ ).toEqual(false);
312
+ expect(
313
+ allGroupSegmentsAreMatched(
314
+ group.segments,
315
+ { country: "de", deviceType: "desktop" },
316
+ datafileReader,
317
+ ),
318
+ ).toEqual(false);
319
+ });
320
+
321
+ it("should match germanMobileUsers", function () {
322
+ const group = groups.find((g) => g.key === "germanMobileUsers") as Group;
323
+
324
+ // match
325
+ expect(
326
+ allGroupSegmentsAreMatched(
327
+ group.segments,
328
+ { country: "de", deviceType: "mobile" },
329
+ datafileReader,
330
+ ),
331
+ ).toEqual(true);
332
+ expect(
333
+ allGroupSegmentsAreMatched(
334
+ group.segments,
335
+ { country: "de", deviceType: "mobile", browser: "chrome" },
336
+ datafileReader,
337
+ ),
338
+ ).toEqual(true);
339
+
340
+ // not match
341
+ expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader)).toEqual(false);
342
+ expect(
343
+ allGroupSegmentsAreMatched(
344
+ group.segments,
345
+ { country: "nl", deviceType: "mobile" },
346
+ datafileReader,
347
+ ),
348
+ ).toEqual(false);
349
+ });
350
+
351
+ it("should match germanNonMobileUsers", function () {
352
+ const group = groups.find((g) => g.key === "germanNonMobileUsers") as Group;
353
+
354
+ // match
355
+ expect(
356
+ allGroupSegmentsAreMatched(
357
+ group.segments,
358
+ { country: "de", deviceType: "desktop" },
359
+ datafileReader,
360
+ ),
361
+ ).toEqual(true);
362
+ expect(
363
+ allGroupSegmentsAreMatched(
364
+ group.segments,
365
+ { country: "de", deviceType: "desktop", browser: "chrome" },
366
+ datafileReader,
367
+ ),
368
+ ).toEqual(true);
369
+
370
+ // not match
371
+ expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader)).toEqual(false);
372
+ expect(
373
+ allGroupSegmentsAreMatched(
374
+ group.segments,
375
+ { country: "nl", deviceType: "desktop" },
376
+ datafileReader,
377
+ ),
378
+ ).toEqual(false);
379
+ });
195
380
  });
196
381
  });