@featurevisor/sdk 1.35.3 → 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.
Files changed (86) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +2 -381
  3. package/coverage/clover.xml +707 -645
  4. package/coverage/coverage-final.json +11 -9
  5. package/coverage/lcov-report/{segments.ts.html → bucketer.ts.html} +155 -77
  6. package/coverage/lcov-report/child.ts.html +940 -0
  7. package/coverage/lcov-report/conditions.ts.html +107 -158
  8. package/coverage/lcov-report/datafileReader.ts.html +763 -103
  9. package/coverage/lcov-report/emitter.ts.html +77 -59
  10. package/coverage/lcov-report/evaluate.ts.html +689 -416
  11. package/coverage/lcov-report/events.ts.html +334 -0
  12. package/coverage/lcov-report/helpers.ts.html +184 -0
  13. package/coverage/lcov-report/{bucket.ts.html → hooks.ts.html} +86 -239
  14. package/coverage/lcov-report/index.html +119 -89
  15. package/coverage/lcov-report/instance.ts.html +341 -773
  16. package/coverage/lcov-report/logger.ts.html +64 -64
  17. package/coverage/lcov.info +1433 -1226
  18. package/dist/bucketer.d.ts +11 -0
  19. package/dist/child.d.ts +26 -0
  20. package/dist/compareVersions.d.ts +4 -0
  21. package/dist/conditions.d.ts +4 -4
  22. package/dist/datafileReader.d.ts +26 -6
  23. package/dist/emitter.d.ts +8 -9
  24. package/dist/evaluate.d.ts +31 -29
  25. package/dist/events.d.ts +5 -0
  26. package/dist/helpers.d.ts +5 -0
  27. package/dist/hooks.d.ts +45 -0
  28. package/dist/index.d.ts +3 -2
  29. package/dist/index.js +1 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.mjs +1 -1
  32. package/dist/index.mjs.gz +0 -0
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/instance.d.ts +40 -72
  35. package/dist/logger.d.ts +6 -5
  36. package/dist/murmurhash.d.ts +1 -0
  37. package/jest.config.js +2 -0
  38. package/lib/bucketer.d.ts +11 -0
  39. package/lib/child.d.ts +26 -0
  40. package/lib/compareVersions.d.ts +4 -0
  41. package/lib/conditions.d.ts +4 -4
  42. package/lib/datafileReader.d.ts +26 -6
  43. package/lib/emitter.d.ts +8 -9
  44. package/lib/evaluate.d.ts +31 -29
  45. package/lib/events.d.ts +5 -0
  46. package/lib/helpers.d.ts +5 -0
  47. package/lib/hooks.d.ts +45 -0
  48. package/lib/index.d.ts +3 -2
  49. package/lib/instance.d.ts +40 -72
  50. package/lib/logger.d.ts +6 -5
  51. package/lib/murmurhash.d.ts +1 -0
  52. package/package.json +3 -5
  53. package/src/bucketer.spec.ts +165 -0
  54. package/src/bucketer.ts +84 -0
  55. package/src/child.spec.ts +267 -0
  56. package/src/child.ts +285 -0
  57. package/src/compareVersions.ts +93 -0
  58. package/src/conditions.spec.ts +563 -353
  59. package/src/conditions.ts +46 -63
  60. package/src/datafileReader.spec.ts +396 -84
  61. package/src/datafileReader.ts +280 -60
  62. package/src/emitter.spec.ts +27 -86
  63. package/src/emitter.ts +38 -32
  64. package/src/evaluate.ts +349 -258
  65. package/src/events.spec.ts +154 -0
  66. package/src/events.ts +83 -0
  67. package/src/helpers.ts +33 -0
  68. package/src/hooks.ts +88 -0
  69. package/src/index.ts +3 -2
  70. package/src/instance.spec.ts +305 -489
  71. package/src/instance.ts +247 -391
  72. package/src/logger.spec.ts +212 -134
  73. package/src/logger.ts +36 -36
  74. package/src/murmurhash.ts +71 -0
  75. package/coverage/lcov-report/feature.ts.html +0 -508
  76. package/dist/bucket.d.ts +0 -30
  77. package/dist/feature.d.ts +0 -16
  78. package/dist/segments.d.ts +0 -5
  79. package/lib/bucket.d.ts +0 -30
  80. package/lib/feature.d.ts +0 -16
  81. package/lib/segments.d.ts +0 -5
  82. package/src/bucket.spec.ts +0 -37
  83. package/src/bucket.ts +0 -139
  84. package/src/feature.ts +0 -141
  85. package/src/segments.spec.ts +0 -468
  86. package/src/segments.ts +0 -58
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.0.1](https://github.com/featurevisor/featurevisor/compare/v2.0.0...v2.0.1) (2025-07-19)
7
+
8
+ **Note:** Version bump only for package @featurevisor/sdk
9
+
10
+
11
+
12
+
13
+
6
14
  ## [1.35.3](https://github.com/featurevisor/featurevisor/compare/v1.35.2...v1.35.3) (2025-04-12)
7
15
 
8
16
  **Note:** Version bump only for package @featurevisor/sdk
package/README.md CHANGED
@@ -1,387 +1,8 @@
1
1
  # @featurevisor/sdk <!-- omit in toc -->
2
2
 
3
- Universal JavaScript SDK for both Node.js and the browser.
3
+ Universal Featurevisor JavaScript SDK for both Node.js and the browser.
4
4
 
5
- Visit [https://featurevisor.com/docs/sdks/](https://featurevisor.com/docs/sdks/) for more information.
6
-
7
- - [Installation](#installation)
8
- - [Usage](#usage)
9
- - [Options](#options)
10
- - [`bucketKeySeparator`](#bucketkeyseparator)
11
- - [`configureBucketKey`](#configurebucketkey)
12
- - [`configureBucketValue`](#configurebucketvalue)
13
- - [`datafile`](#datafile)
14
- - [`datafileUrl`](#datafileurl)
15
- - [`handleDatafileFetch`](#handledatafilefetch)
16
- - [`initialFeatures`](#initialfeatures)
17
- - [`interceptContext`](#interceptcontext)
18
- - [`logger`](#logger)
19
- - [`onActivation`](#onactivation)
20
- - [`onReady`](#onready)
21
- - [`onRefresh`](#onrefresh)
22
- - [`onUpdate`](#onupdate)
23
- - [`refreshInterval`](#refreshinterval)
24
- - [`stickyFeatures`](#stickyfeatures)
25
- - [API](#api)
26
- - [`isEnabled`](#isenabled)
27
- - [`getVariation`](#getvariation)
28
- - [`getVariable`](#getvariable)
29
- - [`activate`](#activate)
30
- - [`isReady`](#isready)
31
- - [`refresh`](#refresh)
32
- - [`setLogLevels`](#setloglevels)
33
- - [`on`](#on)
34
- - [`addListener`](#addlistener)
35
- - [`off`](#off)
36
- - [`removeListener`](#removelistener)
37
- - [`removeAllListeners`](#removealllisteners)
38
- - [`onReady`](#onready-1)
39
-
40
- ## Installation
41
-
42
- ```
43
- $ npm install --save @featurevisor/sdk
44
- ```
45
-
46
- ## Usage
47
-
48
- Initialize the SDK:
49
-
50
- ```js
51
- import { createInstance } from "@featurevisor/sdk";
52
-
53
- const sdk = createInstance(options);
54
- ```
55
-
56
- ## Options
57
-
58
- Options you can pass when creating Featurevisor SDK instance:
59
-
60
- ### `bucketKeySeparator`
61
-
62
- - Type: `string`
63
- - Required: no
64
- - Defaults to: `.`
65
-
66
- ### `configureBucketKey`
67
-
68
- - Type: `function`
69
- - Required: no
70
-
71
- Use it to take over bucketing key generation process.
72
-
73
- ```js
74
- const sdk = createInstance({
75
- configureBucketKey: (feature, context, bucketKey) => {
76
- return bucketKey;
77
- }
78
- });
79
- ```
80
-
81
- ### `configureBucketValue`
82
-
83
- - Type: `function`
84
- - Required: no
85
-
86
- Use it to take over bucketing process.
87
-
88
- ```js
89
- const sdk = createInstance({
90
- configureBucketValue: (feature, context, bucketValue) => {
91
- return bucketValue; // 0 to 100,000
92
- }
93
- });
94
- ```
95
-
96
- ### `datafile`
97
-
98
- - Type: `object`
99
- - Required: either `datafile` or `datafileUrl` is required
100
-
101
- Use it to pass the datafile object directly.
102
-
103
- ### `datafileUrl`
104
-
105
- - Type: `string`
106
- - Required: either `datafile` or `datafileUrl` is required
107
-
108
- Use it to pass the URL to fetch the datafile from.
109
-
110
- ### `handleDatafileFetch`
111
-
112
- - Type: `function`
113
- - Required: no
114
-
115
- Pass this function if you need to take over the datafile fetching and parsing process:
116
-
117
- ```js
118
- const sdk = createInstance({
119
- handleDatafileFetch: async (datafileUrl) => {
120
- const response = await fetch(datafileUrl);
121
- const datafile = await response.json();
122
-
123
- return datafile;
124
- }
125
- });
126
- ```
127
-
128
- ### `initialFeatures`
129
-
130
- - Type: `object`
131
- - Required: no
132
-
133
- Pass set of initial features with their variation and (optional) variables that you want the SDK to return until the datafile is fetched and parsed:
134
-
135
- ```js
136
- const sdk = createInstance({
137
- initialFeatures: {
138
- myFeatureKey: {
139
- enabled: true,
140
-
141
- // optional
142
- variation: "treatment",
143
- variables: {
144
- myVariableKey: "my-variable-value"
145
- }
146
- }
147
- }
148
- });
149
- ```
150
-
151
- ### `interceptContext`
152
-
153
- - Type: `function`
154
- - Required: no
155
-
156
- Intercept given context before they are used to bucket the user:
157
-
158
- ```js
159
- const defaultContext = {
160
- platform: "web",
161
- locale: "en-US",
162
- country: "US",
163
- timezone: "America/New_York",
164
- userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko)",
165
- };
166
-
167
- const sdk = createInstance({
168
- interceptContext: (context) => {
169
- return {
170
- ...defaultContext,
171
- ...context,
172
- };
173
- }
174
- });
175
- ```
176
-
177
- ### `logger`
178
-
179
- - Type: `object`
180
- - Required: no
181
-
182
- Pass a custom logger with custom levels, otherwise it the SDK will print logs to the console for `error` and `warn` levels.
183
-
184
- ```js
185
- import { createInstance, createLogger } from "@featurevisor/sdk";
186
-
187
- const sdk = createInstance({
188
- logger: createLogger({
189
- levels: ["debug", "info", "warn", "error"],
190
- handler: (level, message, details) => {
191
- // do something with the log
192
- },
193
- }),
194
- });
195
- ```
196
-
197
- ### `onActivation`
198
-
199
- - Type: `function`
200
- - Required: no
201
-
202
- Capture activated features along with their evaluated variation:
203
-
204
- ```js
205
- const sdk = createInstance({
206
- onActivation: (featureKey, variation, context, captureContext) => {
207
- // do something with the activated feature
208
- }
209
- });
210
- ```
211
-
212
- `captureContext` will only contain attributes that are marked as `capture: true` in the Attributes' YAML files.
213
-
214
- ### `onReady`
215
-
216
- - Type: `function`
217
- - Required: no
218
-
219
- Triggered maximum once when the SDK is ready to be used.
220
-
221
- ```js
222
- const sdk = createInstance({
223
- onReady: () => {
224
- // do something when the SDK is ready
225
- }
226
- });
227
- ```
228
-
229
- ### `onRefresh`
230
-
231
- - Type: `function`
232
- - Required: no
233
-
234
- Triggered every time the datafile is refreshed.
235
-
236
- Works only when `datafileUrl` and `refreshInterval` are set.
237
-
238
- ```js
239
- const sdk = createInstance({
240
- onRefresh: () => {
241
- // do something when the datafile is refreshed
242
- }
243
- });
244
- ```
245
-
246
- ### `onUpdate`
247
-
248
- - Type: `function`
249
- - Required: no
250
-
251
- Triggered every time the datafile is refreshed, and the newly fetched datafile is detected to have different content than last fetched one.
252
-
253
- Works only when `datafileUrl` and `refreshInterval` are set.
254
-
255
- ```js
256
- const sdk = createInstance({
257
- onUpdate: () => {
258
- // do something when the datafile is updated
259
- }
260
- });
261
- ```
262
-
263
- ### `refreshInterval`
264
-
265
- - Type: `number` (in seconds)
266
- - Required: no
267
-
268
- Set the interval to refresh the datafile.
269
-
270
- ```js
271
- const sdk = createInstance({
272
- refreshInterval: 60 * 5, // every 5 minutes
273
- });
274
- ```
275
-
276
- ### `stickyFeatures`
277
-
278
- - Type: `object`
279
- - Required: no
280
-
281
- If set, the SDK will skip evaluating the datafile and return variation and variable results from this object instead.
282
-
283
- If a feature key is not present in this object, the SDK will continue to evaluate the datafile.
284
-
285
- ```js
286
- const sdk = createInstance({
287
- stickyFeatures: {
288
- myFeatureKey: {
289
- enabled: true,
290
-
291
- // optional
292
- variation: "treatment",
293
- variables: {
294
- myVariableKey: "my-variable-value"
295
- }
296
- }
297
- }
298
- });
299
- ```
300
-
301
- ## API
302
-
303
- These methods are available once the SDK instance is created:
304
-
305
- ### `isEnabled`
306
-
307
- > `isEnabled(featureKey: string, context: Context): boolean`
308
-
309
- ### `getVariation`
310
-
311
- > `getVariation(featureKey: string, context: Context): VariationValue`
312
-
313
- ### `getVariable`
314
-
315
- > `getVariable(featureKey: string, variableKey: string, context: Context): VariableValue`
316
-
317
- Also supports additional type specific methods:
318
-
319
- - `getVariableBoolean`
320
- - `getVariableString`
321
- - `getVariableInteger`
322
- - `getVariableDouble`
323
- - `getVariableArray`
324
- - `getVariableObject`
325
- - `getVariableJSON`
326
-
327
- ### `activate`
328
-
329
- > `activate(featureKey: string, context: Context): VariationValue`
330
-
331
- Same as `getVariation`, but also calls the `onActivation` callback.
332
-
333
- This is a convenience method meant to be called when you know the User has been exposed to your Feature, and you also want to track the activation.
334
-
335
- ### `isReady`
336
-
337
- > `isReady(): boolean`
338
-
339
- Synchonously check if the SDK is ready to be used.
340
-
341
- ### `refresh`
342
-
343
- > `refresh(): void`
344
-
345
- Manually refresh datafile.
346
-
347
- ### `setLogLevels`
348
-
349
- > `setLogLevels(levels: LogLevel[]): void`
350
-
351
- Accepted values for `levels`: `["debug", "info", "warn", "error"]`.
352
-
353
- ### `on`
354
-
355
- > `on(event: string, callback: function): void`
356
-
357
- Listen to SDK events, like:
358
-
359
- - `ready`
360
- - `activation`
361
- - `refresh`
362
- - `update`
363
-
364
- ### `addListener`
365
-
366
- Alias for `on` method.
367
-
368
- ### `off`
369
-
370
- > `off(event: string, callback: function): void`
371
-
372
- ### `removeListener`
373
-
374
- Alias for `off` method.
375
-
376
- ### `removeAllListeners`
377
-
378
- > `removeAllListeners(event?: string): void`
379
-
380
- ### `onReady`
381
-
382
- Resolves the SDK instance with a promise for convenience when it's ready:
383
-
384
- > onReady(): Promise<FeaturevisorInstance>
5
+ Visit [https://featurevisor.com/docs/sdks/javascript/](https://featurevisor.com/docs/sdks/javascript/) for more information.
385
6
 
386
7
  ## License <!-- omit in toc -->
387
8