@featurevisor/sdk 2.0.2 → 2.1.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/src/bucketer.ts CHANGED
@@ -1,9 +1,12 @@
1
- import type { BucketKey, Context, AttributeValue, FeatureKey, BucketBy } from "@featurevisor/types";
1
+ import type { Context, AttributeValue, FeatureKey, BucketBy } from "@featurevisor/types";
2
2
 
3
3
  import { Logger } from "./logger";
4
4
  import { getValueFromContext } from "./conditions";
5
5
  import { MurmurHashV3 } from "./murmurhash";
6
6
 
7
+ export type BucketKey = string;
8
+ export type BucketValue = number; // 0 to 100,000 (100% * 1000 to include three decimal places in same integer)
9
+
7
10
  /**
8
11
  * Generic hashing
9
12
  */
@@ -12,7 +15,7 @@ const MAX_HASH_VALUE = Math.pow(2, 32);
12
15
 
13
16
  export const MAX_BUCKETED_NUMBER = 100000; // 100% * 1000 to include three decimal places in the same integer value
14
17
 
15
- export function getBucketedNumber(bucketKey: string): number {
18
+ export function getBucketedNumber(bucketKey: string): BucketValue {
16
19
  const hashValue = MurmurHashV3(bucketKey, HASH_SEED);
17
20
  const ratio = hashValue / MAX_HASH_VALUE;
18
21
 
package/src/evaluate.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  import type {
2
2
  FeatureKey,
3
3
  Context,
4
- BucketKey,
5
- BucketValue,
6
4
  RuleKey,
7
5
  Traffic,
8
6
  Force,
@@ -20,7 +18,7 @@ import type {
20
18
  import { Logger } from "./logger";
21
19
  import { HooksManager } from "./hooks";
22
20
  import { DatafileReader } from "./datafileReader";
23
- import { getBucketKey, getBucketedNumber } from "./bucketer";
21
+ import { BucketKey, BucketValue, getBucketKey, getBucketedNumber } from "./bucketer";
24
22
 
25
23
  export enum EvaluationReason {
26
24
  // feature specific
package/src/hooks.ts CHANGED
@@ -1,7 +1,8 @@
1
- import type { BucketBy, BucketKey, BucketValue, Context, FeatureKey } from "@featurevisor/types";
1
+ import type { BucketBy, Context, FeatureKey } from "@featurevisor/types";
2
2
 
3
3
  import type { EvaluateOptions, Evaluation } from "./evaluate";
4
4
  import type { Logger } from "./logger";
5
+ import type { BucketKey, BucketValue } from "./bucketer";
5
6
 
6
7
  /**
7
8
  * bucketKey
package/src/instance.ts CHANGED
@@ -439,6 +439,6 @@ export class FeaturevisorInstance {
439
439
  }
440
440
  }
441
441
 
442
- export function createInstance(options: InstanceOptions): FeaturevisorInstance {
442
+ export function createInstance(options: InstanceOptions = {}): FeaturevisorInstance {
443
443
  return new FeaturevisorInstance(options);
444
444
  }