flagsmith-nodejs 6.0.0 → 6.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.
Files changed (70) hide show
  1. package/.github/workflows/publish.yml +17 -17
  2. package/.github/workflows/pull_request.yaml +33 -33
  3. package/.husky/pre-commit +0 -0
  4. package/.prettierignore +2 -1
  5. package/README.md +2 -1
  6. package/build/cjs/flagsmith-engine/features/util.js +3 -3
  7. package/build/cjs/flagsmith-engine/index.d.ts +1 -1
  8. package/build/cjs/flagsmith-engine/index.js +2 -1
  9. package/build/cjs/flagsmith-engine/segments/models.js +7 -7
  10. package/build/cjs/flagsmith-engine/utils/hashing/index.js +1 -1
  11. package/build/cjs/index.d.ts +4 -4
  12. package/build/cjs/index.js +3 -1
  13. package/build/cjs/sdk/analytics.d.ts +1 -1
  14. package/build/cjs/sdk/index.d.ts +5 -5
  15. package/build/cjs/sdk/index.js +7 -5
  16. package/build/cjs/sdk/models.d.ts +32 -5
  17. package/build/cjs/sdk/models.js +25 -0
  18. package/build/cjs/sdk/types.d.ts +14 -4
  19. package/build/cjs/sdk/utils.d.ts +4 -4
  20. package/build/cjs/sdk/utils.js +2 -2
  21. package/build/esm/flagsmith-engine/features/models.js +1 -1
  22. package/build/esm/flagsmith-engine/features/util.js +3 -3
  23. package/build/esm/flagsmith-engine/index.d.ts +1 -1
  24. package/build/esm/flagsmith-engine/index.js +1 -1
  25. package/build/esm/flagsmith-engine/segments/models.js +7 -7
  26. package/build/esm/flagsmith-engine/utils/hashing/index.js +2 -2
  27. package/build/esm/flagsmith-engine/utils/index.js +1 -1
  28. package/build/esm/index.d.ts +4 -4
  29. package/build/esm/index.js +3 -3
  30. package/build/esm/sdk/analytics.d.ts +1 -1
  31. package/build/esm/sdk/index.d.ts +5 -5
  32. package/build/esm/sdk/index.js +6 -5
  33. package/build/esm/sdk/models.d.ts +32 -5
  34. package/build/esm/sdk/models.js +25 -0
  35. package/build/esm/sdk/types.d.ts +14 -4
  36. package/build/esm/sdk/utils.d.ts +4 -4
  37. package/build/esm/sdk/utils.js +2 -2
  38. package/flagsmith-engine/environments/util.ts +2 -2
  39. package/flagsmith-engine/features/models.ts +1 -1
  40. package/flagsmith-engine/features/util.ts +14 -14
  41. package/flagsmith-engine/identities/models.ts +1 -1
  42. package/flagsmith-engine/index.ts +1 -1
  43. package/flagsmith-engine/segments/evaluators.ts +2 -3
  44. package/flagsmith-engine/segments/models.ts +25 -15
  45. package/flagsmith-engine/utils/hashing/index.ts +3 -3
  46. package/flagsmith-engine/utils/index.ts +4 -2
  47. package/index.ts +19 -22
  48. package/package.json +2 -2
  49. package/sdk/analytics.ts +7 -5
  50. package/sdk/index.ts +38 -21
  51. package/sdk/models.ts +34 -12
  52. package/sdk/offline_handlers.ts +1 -1
  53. package/sdk/types.ts +17 -8
  54. package/sdk/utils.ts +8 -8
  55. package/tests/engine/e2e/engine.test.ts +2 -4
  56. package/tests/engine/unit/engine.test.ts +1 -5
  57. package/tests/engine/unit/features/models.test.ts +2 -2
  58. package/tests/engine/unit/identities/identities_builders.test.ts +1 -1
  59. package/tests/engine/unit/segments/segment_evaluators.test.ts +52 -23
  60. package/tests/engine/unit/segments/segments_model.test.ts +35 -37
  61. package/tests/engine/unit/utils/utils.test.ts +28 -30
  62. package/tests/sdk/analytics.test.ts +25 -26
  63. package/tests/sdk/flagsmith-cache.test.ts +84 -76
  64. package/tests/sdk/flagsmith-environment-flags.test.ts +93 -93
  65. package/tests/sdk/flagsmith-identity-flags.test.ts +146 -149
  66. package/tests/sdk/flagsmith.test.ts +40 -42
  67. package/tests/sdk/offline-handlers.test.ts +32 -32
  68. package/tests/sdk/polling.test.ts +0 -1
  69. package/tests/sdk/utils.ts +26 -18
  70. package/vitest.config.ts +10 -15
@@ -1,25 +1,25 @@
1
1
  name: Publish NPM Package
2
2
 
3
3
  on:
4
- push:
5
- tags:
6
- - '*'
4
+ push:
5
+ tags:
6
+ - '*'
7
7
 
8
8
  jobs:
9
- package:
10
- runs-on: ubuntu-latest
11
- name: Publish NPM Package
9
+ package:
10
+ runs-on: ubuntu-latest
11
+ name: Publish NPM Package
12
12
 
13
- steps:
14
- - name: Cloning repo
15
- uses: actions/checkout@v3
13
+ steps:
14
+ - name: Cloning repo
15
+ uses: actions/checkout@v3
16
16
 
17
- - uses: actions/setup-node@v4
18
- with:
19
- node-version: '18.x'
20
- registry-url: 'https://registry.npmjs.org'
17
+ - uses: actions/setup-node@v4
18
+ with:
19
+ node-version: '18.x'
20
+ registry-url: 'https://registry.npmjs.org'
21
21
 
22
- - run: npm ci
23
- - run: npm run deploy
24
- env:
25
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
22
+ - run: npm ci
23
+ - run: npm run deploy
24
+ env:
25
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -1,37 +1,37 @@
1
1
  name: Unit/Integration Tests
2
2
 
3
3
  on:
4
- pull_request:
5
- types:
6
- - opened
7
- - synchronize
8
- - reopened
9
- - ready_for_review
10
- push:
11
- branches:
12
- - main
4
+ pull_request:
5
+ types:
6
+ - opened
7
+ - synchronize
8
+ - reopened
9
+ - ready_for_review
10
+ push:
11
+ branches:
12
+ - main
13
13
  jobs:
14
- build-and-test:
15
- strategy:
16
- matrix:
17
- node-version: [18.x, 20.x, 22.x]
18
- runs-on: ubuntu-latest
19
- steps:
20
- - uses: actions/checkout@v4
21
- with:
22
- submodules: true
23
- - uses: actions/setup-node@v4
24
- with:
25
- node-version: "${{ matrix.node-version }}"
26
- - name: cache node modules
27
- uses: actions/cache@v4
28
- with:
29
- path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
30
- key: npm-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}
31
- restore-keys: |
32
- npm-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}
33
- npm-
34
- - run: npm ci
35
- - run: npm test
36
- env:
37
- CI: true
14
+ build-and-test:
15
+ strategy:
16
+ matrix:
17
+ node-version: [18.x, 20.x, 22.x]
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ with:
22
+ submodules: true
23
+ - uses: actions/setup-node@v4
24
+ with:
25
+ node-version: '${{ matrix.node-version }}'
26
+ - name: cache node modules
27
+ uses: actions/cache@v4
28
+ with:
29
+ path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
30
+ key: npm-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}
31
+ restore-keys: |
32
+ npm-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}
33
+ npm-
34
+ - run: npm ci
35
+ - run: npm test
36
+ env:
37
+ CI: true
package/.husky/pre-commit CHANGED
File without changes
package/.prettierignore CHANGED
@@ -1 +1,2 @@
1
- *.json
1
+ *.json
2
+ tests/engine/engine-tests/engine-test-data
package/README.md CHANGED
@@ -21,10 +21,11 @@ If you encounter a bug or feature request we would like to hear about it. Before
21
21
 
22
22
  ## Testing
23
23
 
24
- To run the local tests you need to run following command beforehand:
24
+ To run the local tests you need to run following commands beforehand:
25
25
 
26
26
  ```bash
27
27
  git submodule add git@github.com:Flagsmith/engine-test-data.git tests/engine/engine-tests/engine-test-data/
28
+ git submodule update --init --recursive
28
29
  ```
29
30
 
30
31
  ## Get in touch
@@ -8,9 +8,9 @@ function buildFeatureModel(featuresModelJSON) {
8
8
  exports.buildFeatureModel = buildFeatureModel;
9
9
  function buildFeatureStateModel(featuresStateModelJSON) {
10
10
  const featureStateModel = new models_js_1.FeatureStateModel(buildFeatureModel(featuresStateModelJSON.feature), featuresStateModelJSON.enabled, featuresStateModelJSON.django_id, featuresStateModelJSON.feature_state_value, featuresStateModelJSON.featurestate_uuid);
11
- featureStateModel.featureSegment = featuresStateModelJSON.feature_segment ?
12
- buildFeatureSegment(featuresStateModelJSON.feature_segment) :
13
- undefined;
11
+ featureStateModel.featureSegment = featuresStateModelJSON.feature_segment
12
+ ? buildFeatureSegment(featuresStateModelJSON.feature_segment)
13
+ : undefined;
14
14
  const multivariateFeatureStateValues = featuresStateModelJSON.multivariate_feature_state_values
15
15
  ? featuresStateModelJSON.multivariate_feature_state_values.map((fsv) => {
16
16
  const featureOption = new models_js_1.MultivariateFeatureOptionModel(fsv.multivariate_feature_option.value, fsv.multivariate_feature_option.id);
@@ -3,7 +3,7 @@ import { FeatureStateModel } from './features/models.js';
3
3
  import { IdentityModel } from './identities/models.js';
4
4
  import { TraitModel } from './identities/traits/models.js';
5
5
  export { EnvironmentModel } from './environments/models.js';
6
- export { FeatureStateModel } from './features/models.js';
6
+ export { FeatureModel, FeatureStateModel } from './features/models.js';
7
7
  export { IdentityModel } from './identities/models.js';
8
8
  export { TraitModel } from './identities/traits/models.js';
9
9
  export { SegmentModel } from './segments/models.js';
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEnvironmentFeatureStates = exports.getEnvironmentFeatureState = exports.getIdentityFeatureStates = exports.getIdentityFeatureState = exports.OrganisationModel = exports.SegmentModel = exports.TraitModel = exports.IdentityModel = exports.FeatureStateModel = exports.EnvironmentModel = void 0;
3
+ exports.getEnvironmentFeatureStates = exports.getEnvironmentFeatureState = exports.getIdentityFeatureStates = exports.getIdentityFeatureState = exports.OrganisationModel = exports.SegmentModel = exports.TraitModel = exports.IdentityModel = exports.FeatureStateModel = exports.FeatureModel = exports.EnvironmentModel = void 0;
4
4
  const evaluators_js_1 = require("./segments/evaluators.js");
5
5
  const errors_js_1 = require("./utils/errors.js");
6
6
  var models_js_1 = require("./environments/models.js");
7
7
  Object.defineProperty(exports, "EnvironmentModel", { enumerable: true, get: function () { return models_js_1.EnvironmentModel; } });
8
8
  var models_js_2 = require("./features/models.js");
9
+ Object.defineProperty(exports, "FeatureModel", { enumerable: true, get: function () { return models_js_2.FeatureModel; } });
9
10
  Object.defineProperty(exports, "FeatureStateModel", { enumerable: true, get: function () { return models_js_2.FeatureStateModel; } });
10
11
  var models_js_3 = require("./identities/models.js");
11
12
  Object.defineProperty(exports, "IdentityModel", { enumerable: true, get: function () { return models_js_3.IdentityModel; } });
@@ -16,7 +16,7 @@ exports.matchingFunctions = {
16
16
  [constants_js_1.CONDITION_OPERATORS.LESS_THAN]: (thisValue, otherValue) => thisValue > otherValue,
17
17
  [constants_js_1.CONDITION_OPERATORS.LESS_THAN_INCLUSIVE]: (thisValue, otherValue) => thisValue >= otherValue,
18
18
  [constants_js_1.CONDITION_OPERATORS.NOT_EQUAL]: (thisValue, otherValue) => thisValue != otherValue,
19
- [constants_js_1.CONDITION_OPERATORS.CONTAINS]: (thisValue, otherValue) => !!otherValue && otherValue.includes(thisValue),
19
+ [constants_js_1.CONDITION_OPERATORS.CONTAINS]: (thisValue, otherValue) => !!otherValue && otherValue.includes(thisValue)
20
20
  };
21
21
  exports.semverMatchingFunction = {
22
22
  ...exports.matchingFunctions,
@@ -24,9 +24,9 @@ exports.semverMatchingFunction = {
24
24
  [constants_js_1.CONDITION_OPERATORS.GREATER_THAN]: (thisValue, otherValue) => semver.gt(otherValue, thisValue),
25
25
  [constants_js_1.CONDITION_OPERATORS.GREATER_THAN_INCLUSIVE]: (thisValue, otherValue) => semver.gte(otherValue, thisValue),
26
26
  [constants_js_1.CONDITION_OPERATORS.LESS_THAN]: (thisValue, otherValue) => semver.gt(thisValue, otherValue),
27
- [constants_js_1.CONDITION_OPERATORS.LESS_THAN_INCLUSIVE]: (thisValue, otherValue) => semver.gte(thisValue, otherValue),
27
+ [constants_js_1.CONDITION_OPERATORS.LESS_THAN_INCLUSIVE]: (thisValue, otherValue) => semver.gte(thisValue, otherValue)
28
28
  };
29
- const getMatchingFunctions = (semver) => (semver ? exports.semverMatchingFunction : exports.matchingFunctions);
29
+ const getMatchingFunctions = (semver) => semver ? exports.semverMatchingFunction : exports.matchingFunctions;
30
30
  exports.getMatchingFunctions = getMatchingFunctions;
31
31
  class SegmentConditionModel {
32
32
  EXCEPTION_OPERATOR_METHODS = {
@@ -46,9 +46,9 @@ class SegmentConditionModel {
46
46
  matchesTraitValue(traitValue) {
47
47
  const evaluators = {
48
48
  evaluateNotContains: (traitValue) => {
49
- return typeof traitValue == "string" &&
49
+ return (typeof traitValue == 'string' &&
50
50
  !!this.value &&
51
- !traitValue.includes(this.value?.toString());
51
+ !traitValue.includes(this.value?.toString()));
52
52
  },
53
53
  evaluateRegex: (traitValue) => {
54
54
  return !!this.value && !!traitValue?.toString().match(new RegExp(this.value));
@@ -57,13 +57,13 @@ class SegmentConditionModel {
57
57
  if (isNaN(parseFloat(traitValue)) || !this.value) {
58
58
  return false;
59
59
  }
60
- const parts = (this.value).split("|");
60
+ const parts = this.value.split('|');
61
61
  const [divisor, reminder] = [parseFloat(parts[0]), parseFloat(parts[1])];
62
62
  return traitValue % divisor === reminder;
63
63
  },
64
64
  evaluateIn: (traitValue) => {
65
65
  return this.value?.split(',').includes(traitValue.toString());
66
- },
66
+ }
67
67
  };
68
68
  // TODO: move this logic to the evaluator module
69
69
  if (this.EXCEPTION_OPERATOR_METHODS[this.operator]) {
@@ -17,7 +17,7 @@ function getHashedPercentateForObjIds(objectIds, iterations = 1) {
17
17
  let toHash = makeRepeated(objectIds, iterations).join(',');
18
18
  const hashedValue = md5(toHash);
19
19
  const hashedInt = BigInt('0x' + hashedValue);
20
- const value = (Number((hashedInt % 9999n)) / 9998.0) * 100;
20
+ const value = (Number(hashedInt % 9999n) / 9998.0) * 100;
21
21
  // we ignore this for it's nearly impossible use case to catch
22
22
  /* istanbul ignore next */
23
23
  if (value === 100) {
@@ -1,4 +1,4 @@
1
- export { AnalyticsProcessor, AnalyticsProcessorOptions, FlagsmithAPIError, FlagsmithClientError, EnvironmentDataPollingManager, FlagsmithCache, DefaultFlag, Flags, Flagsmith, } from './sdk/index.js';
2
- export { BaseOfflineHandler, LocalFileHandler, } from './sdk/offline_handlers.js';
3
- export { FlagsmithConfig } from './sdk/types.js';
4
- export { EnvironmentModel, FeatureStateModel, IdentityModel, TraitModel, SegmentModel, OrganisationModel } from './flagsmith-engine/index.js';
1
+ export { AnalyticsProcessor, AnalyticsProcessorOptions, FlagsmithAPIError, FlagsmithClientError, EnvironmentDataPollingManager, FlagsmithCache, BaseFlag, DefaultFlag, Flags, Flagsmith } from './sdk/index.js';
2
+ export { BaseOfflineHandler, LocalFileHandler } from './sdk/offline_handlers.js';
3
+ export { FlagsmithConfig, FlagsmithValue, TraitConfig } from './sdk/types.js';
4
+ export { EnvironmentModel, FeatureModel, FeatureStateModel, IdentityModel, TraitModel, SegmentModel, OrganisationModel } from './flagsmith-engine/index.js';
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OrganisationModel = exports.SegmentModel = exports.TraitModel = exports.IdentityModel = exports.FeatureStateModel = exports.EnvironmentModel = exports.LocalFileHandler = exports.BaseOfflineHandler = exports.Flagsmith = exports.Flags = exports.DefaultFlag = exports.EnvironmentDataPollingManager = exports.FlagsmithClientError = exports.FlagsmithAPIError = exports.AnalyticsProcessor = void 0;
3
+ exports.OrganisationModel = exports.SegmentModel = exports.TraitModel = exports.IdentityModel = exports.FeatureStateModel = exports.FeatureModel = exports.EnvironmentModel = exports.LocalFileHandler = exports.BaseOfflineHandler = exports.Flagsmith = exports.Flags = exports.DefaultFlag = exports.BaseFlag = exports.EnvironmentDataPollingManager = exports.FlagsmithClientError = exports.FlagsmithAPIError = exports.AnalyticsProcessor = void 0;
4
4
  var index_js_1 = require("./sdk/index.js");
5
5
  Object.defineProperty(exports, "AnalyticsProcessor", { enumerable: true, get: function () { return index_js_1.AnalyticsProcessor; } });
6
6
  Object.defineProperty(exports, "FlagsmithAPIError", { enumerable: true, get: function () { return index_js_1.FlagsmithAPIError; } });
7
7
  Object.defineProperty(exports, "FlagsmithClientError", { enumerable: true, get: function () { return index_js_1.FlagsmithClientError; } });
8
8
  Object.defineProperty(exports, "EnvironmentDataPollingManager", { enumerable: true, get: function () { return index_js_1.EnvironmentDataPollingManager; } });
9
+ Object.defineProperty(exports, "BaseFlag", { enumerable: true, get: function () { return index_js_1.BaseFlag; } });
9
10
  Object.defineProperty(exports, "DefaultFlag", { enumerable: true, get: function () { return index_js_1.DefaultFlag; } });
10
11
  Object.defineProperty(exports, "Flags", { enumerable: true, get: function () { return index_js_1.Flags; } });
11
12
  Object.defineProperty(exports, "Flagsmith", { enumerable: true, get: function () { return index_js_1.Flagsmith; } });
@@ -14,6 +15,7 @@ Object.defineProperty(exports, "BaseOfflineHandler", { enumerable: true, get: fu
14
15
  Object.defineProperty(exports, "LocalFileHandler", { enumerable: true, get: function () { return offline_handlers_js_1.LocalFileHandler; } });
15
16
  var index_js_2 = require("./flagsmith-engine/index.js");
16
17
  Object.defineProperty(exports, "EnvironmentModel", { enumerable: true, get: function () { return index_js_2.EnvironmentModel; } });
18
+ Object.defineProperty(exports, "FeatureModel", { enumerable: true, get: function () { return index_js_2.FeatureModel; } });
17
19
  Object.defineProperty(exports, "FeatureStateModel", { enumerable: true, get: function () { return index_js_2.FeatureStateModel; } });
18
20
  Object.defineProperty(exports, "IdentityModel", { enumerable: true, get: function () { return index_js_2.IdentityModel; } });
19
21
  Object.defineProperty(exports, "TraitModel", { enumerable: true, get: function () { return index_js_2.TraitModel; } });
@@ -1,5 +1,5 @@
1
1
  import { Logger } from 'pino';
2
- import { Fetch } from "./types.js";
2
+ import { Fetch } from './types.js';
3
3
  export declare const ANALYTICS_ENDPOINT = "./analytics/flags/";
4
4
  export interface AnalyticsProcessorOptions {
5
5
  /** URL of the Flagsmith analytics events API endpoint
@@ -5,10 +5,10 @@ import { BaseOfflineHandler } from './offline_handlers.js';
5
5
  import { DefaultFlag, Flags } from './models.js';
6
6
  import { EnvironmentDataPollingManager } from './polling_manager.js';
7
7
  import { SegmentModel } from '../flagsmith-engine/index.js';
8
- import { FlagsmithConfig, FlagsmithTraitValue, ITraitConfig } from './types.js';
8
+ import { FlagsmithConfig, FlagsmithTraitValue, TraitConfig } from './types.js';
9
9
  export { AnalyticsProcessor, AnalyticsProcessorOptions } from './analytics.js';
10
10
  export { FlagsmithAPIError, FlagsmithClientError } from './errors.js';
11
- export { DefaultFlag, Flags } from './models.js';
11
+ export { BaseFlag, DefaultFlag, Flags } from './models.js';
12
12
  export { EnvironmentDataPollingManager } from './polling_manager.js';
13
13
  export { FlagsmithCache, FlagsmithConfig } from './types.js';
14
14
  /**
@@ -34,7 +34,7 @@ export { FlagsmithCache, FlagsmithConfig } from './types.js';
34
34
  * const bannerVariation: string = identityFlags.getFeatureValue('banner_flag')
35
35
  *
36
36
  * @see FlagsmithConfig
37
- */
37
+ */
38
38
  export declare class Flagsmith {
39
39
  environmentKey?: string;
40
40
  apiUrl?: string;
@@ -84,12 +84,12 @@ export declare class Flagsmith {
84
84
  *
85
85
  * @param {string} identifier a unique identifier for the identity in the current
86
86
  environment, e.g. email address, username, uuid
87
- * @param {{[key:string]:any | ITraitConfig}} traits? a dictionary of traits to add / update on the identity in
87
+ * @param {{[key:string]:any | TraitConfig}} traits? a dictionary of traits to add / update on the identity in
88
88
  Flagsmith, e.g. {"num_orders": 10} or {age: {value: 30, transient: true}}
89
89
  * @returns Flags object holding all the flags for the given identity.
90
90
  */
91
91
  getIdentityFlags(identifier: string, traits?: {
92
- [key: string]: FlagsmithTraitValue | ITraitConfig;
92
+ [key: string]: FlagsmithTraitValue | TraitConfig;
93
93
  }, transient?: boolean): Promise<Flags>;
94
94
  /**
95
95
  * Get the segments for the current environment for a given identity. Will also
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Flagsmith = exports.EnvironmentDataPollingManager = exports.Flags = exports.DefaultFlag = exports.FlagsmithClientError = exports.FlagsmithAPIError = exports.AnalyticsProcessor = void 0;
3
+ exports.Flagsmith = exports.EnvironmentDataPollingManager = exports.Flags = exports.DefaultFlag = exports.BaseFlag = exports.FlagsmithClientError = exports.FlagsmithAPIError = exports.AnalyticsProcessor = void 0;
4
4
  const index_js_1 = require("../flagsmith-engine/index.js");
5
5
  const util_js_1 = require("../flagsmith-engine/environments/util.js");
6
6
  const index_js_2 = require("../flagsmith-engine/index.js");
@@ -18,6 +18,7 @@ var errors_js_2 = require("./errors.js");
18
18
  Object.defineProperty(exports, "FlagsmithAPIError", { enumerable: true, get: function () { return errors_js_2.FlagsmithAPIError; } });
19
19
  Object.defineProperty(exports, "FlagsmithClientError", { enumerable: true, get: function () { return errors_js_2.FlagsmithClientError; } });
20
20
  var models_js_2 = require("./models.js");
21
+ Object.defineProperty(exports, "BaseFlag", { enumerable: true, get: function () { return models_js_2.BaseFlag; } });
21
22
  Object.defineProperty(exports, "DefaultFlag", { enumerable: true, get: function () { return models_js_2.DefaultFlag; } });
22
23
  Object.defineProperty(exports, "Flags", { enumerable: true, get: function () { return models_js_2.Flags; } });
23
24
  var polling_manager_js_2 = require("./polling_manager.js");
@@ -47,7 +48,7 @@ const DEFAULT_REQUEST_TIMEOUT_SECONDS = 10;
47
48
  * const bannerVariation: string = identityFlags.getFeatureValue('banner_flag')
48
49
  *
49
50
  * @see FlagsmithConfig
50
- */
51
+ */
51
52
  class Flagsmith {
52
53
  environmentKey = undefined;
53
54
  apiUrl = undefined;
@@ -116,7 +117,8 @@ class Flagsmith {
116
117
  }
117
118
  const apiUrl = data.apiUrl || DEFAULT_API_URL;
118
119
  this.apiUrl = apiUrl.endsWith('/') ? apiUrl : `${apiUrl}/`;
119
- this.analyticsUrl = this.analyticsUrl || new URL(analytics_js_1.ANALYTICS_ENDPOINT, new Request(this.apiUrl).url).href;
120
+ this.analyticsUrl =
121
+ this.analyticsUrl || new URL(analytics_js_1.ANALYTICS_ENDPOINT, new Request(this.apiUrl).url).href;
120
122
  this.environmentFlagsUrl = `${this.apiUrl}flags/`;
121
123
  this.identitiesUrl = `${this.apiUrl}identities/`;
122
124
  this.environmentUrl = `${this.apiUrl}environment-document/`;
@@ -134,7 +136,7 @@ class Flagsmith {
134
136
  environmentKey: this.environmentKey,
135
137
  analyticsUrl: this.analyticsUrl,
136
138
  requestTimeoutMs: this.requestTimeoutMs,
137
- logger: this.logger,
139
+ logger: this.logger
138
140
  });
139
141
  }
140
142
  }
@@ -173,7 +175,7 @@ class Flagsmith {
173
175
  *
174
176
  * @param {string} identifier a unique identifier for the identity in the current
175
177
  environment, e.g. email address, username, uuid
176
- * @param {{[key:string]:any | ITraitConfig}} traits? a dictionary of traits to add / update on the identity in
178
+ * @param {{[key:string]:any | TraitConfig}} traits? a dictionary of traits to add / update on the identity in
177
179
  Flagsmith, e.g. {"num_orders": 10} or {age: {value: 30, transient: true}}
178
180
  * @returns Flags object holding all the flags for the given identity.
179
181
  */
@@ -1,19 +1,45 @@
1
1
  import { FeatureStateModel } from '../flagsmith-engine/features/models.js';
2
2
  import { AnalyticsProcessor } from './analytics.js';
3
+ type FlagValue = string | number | boolean | undefined;
4
+ /**
5
+ * A Flagsmith feature. It has an enabled/disabled state, and an optional {@link FlagValue}.
6
+ */
3
7
  export declare class BaseFlag {
8
+ /**
9
+ * Indicates whether this feature is enabled.
10
+ */
4
11
  enabled: boolean;
5
- value: string | number | boolean | undefined;
12
+ /**
13
+ * An optional {@link FlagValue} for this feature.
14
+ */
15
+ value: FlagValue;
16
+ /**
17
+ * If true, the state for this feature was determined by a default flag handler. See {@link DefaultFlag}.
18
+ */
6
19
  isDefault: boolean;
7
- constructor(value: string | number | boolean | undefined, enabled: boolean, isDefault: boolean);
20
+ constructor(value: FlagValue, enabled: boolean, isDefault: boolean);
8
21
  }
22
+ /**
23
+ * A {@link BaseFlag} returned by a default flag handler when flag evaluation fails.
24
+ * @see FlagsmithConfig#defaultFlagHandler
25
+ */
9
26
  export declare class DefaultFlag extends BaseFlag {
10
- constructor(value: string | number | boolean | undefined, enabled: boolean);
27
+ constructor(value: FlagValue, enabled: boolean);
11
28
  }
29
+ /**
30
+ * A Flagsmith feature retrieved from a successful flag evaluation.
31
+ */
12
32
  export declare class Flag extends BaseFlag {
33
+ /**
34
+ * An identifier for this feature, unique in a single Flagsmith installation.
35
+ */
13
36
  featureId: number;
37
+ /**
38
+ * The programmatic name for this feature, unique per Flagsmith project.
39
+ */
14
40
  featureName: string;
15
41
  constructor(params: {
16
- value: string | number | boolean | undefined;
42
+ value: FlagValue;
17
43
  enabled: boolean;
18
44
  isDefault?: boolean;
19
45
  featureId: number;
@@ -50,6 +76,7 @@ export declare class Flags {
50
76
  }): Flags;
51
77
  allFlags(): Flag[];
52
78
  getFlag(featureName: string): BaseFlag;
53
- getFeatureValue(featureName: string): any;
79
+ getFeatureValue(featureName: string): FlagValue;
54
80
  isFeatureEnabled(featureName: string): boolean;
55
81
  }
82
+ export {};
@@ -1,9 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Flags = exports.Flag = exports.DefaultFlag = exports.BaseFlag = void 0;
4
+ /**
5
+ * A Flagsmith feature. It has an enabled/disabled state, and an optional {@link FlagValue}.
6
+ */
4
7
  class BaseFlag {
8
+ /**
9
+ * Indicates whether this feature is enabled.
10
+ */
5
11
  enabled;
12
+ /**
13
+ * An optional {@link FlagValue} for this feature.
14
+ */
6
15
  value;
16
+ /**
17
+ * If true, the state for this feature was determined by a default flag handler. See {@link DefaultFlag}.
18
+ */
7
19
  isDefault;
8
20
  constructor(value, enabled, isDefault) {
9
21
  this.value = value;
@@ -12,14 +24,27 @@ class BaseFlag {
12
24
  }
13
25
  }
14
26
  exports.BaseFlag = BaseFlag;
27
+ /**
28
+ * A {@link BaseFlag} returned by a default flag handler when flag evaluation fails.
29
+ * @see FlagsmithConfig#defaultFlagHandler
30
+ */
15
31
  class DefaultFlag extends BaseFlag {
16
32
  constructor(value, enabled) {
17
33
  super(value, enabled, true);
18
34
  }
19
35
  }
20
36
  exports.DefaultFlag = DefaultFlag;
37
+ /**
38
+ * A Flagsmith feature retrieved from a successful flag evaluation.
39
+ */
21
40
  class Flag extends BaseFlag {
41
+ /**
42
+ * An identifier for this feature, unique in a single Flagsmith installation.
43
+ */
22
44
  featureId;
45
+ /**
46
+ * The programmatic name for this feature, unique per Flagsmith project.
47
+ */
23
48
  featureName;
24
49
  constructor(params) {
25
50
  super(params.value, params.enabled, !!params.isDefault);
@@ -3,7 +3,10 @@ import { EnvironmentModel } from '../flagsmith-engine/index.js';
3
3
  import { Dispatcher } from 'undici-types';
4
4
  import { Logger } from 'pino';
5
5
  import { BaseOfflineHandler } from './offline_handlers.js';
6
- export type IFlagsmithValue<T = string | number | boolean | null> = T;
6
+ /**
7
+ * A concrete type for the possible values of a feature.
8
+ */
9
+ export type FlagsmithValue<T = string | number | boolean | null> = T;
7
10
  /**
8
11
  * Stores and retrieves {@link Flags} from a cache.
9
12
  */
@@ -89,7 +92,7 @@ export interface FlagsmithConfig {
89
92
  * const defaultHandler = () => new DefaultFlag(undefined, false)
90
93
  *
91
94
  * // Enable only VIP flags by default
92
- * const vipDefaultHandler = (key: string) => new Default(undefined, key.startsWith('vip_'))
95
+ * const vipDefaultHandler = (key: string) => new DefaultFlag(undefined, key.startsWith('vip_'))
93
96
  */
94
97
  defaultFlagHandler?: (flagKey: string) => DefaultFlag;
95
98
  cache?: FlagsmithCache;
@@ -109,8 +112,15 @@ export interface FlagsmithConfig {
109
112
  */
110
113
  offlineHandler?: BaseOfflineHandler;
111
114
  }
112
- export interface ITraitConfig {
115
+ /**
116
+ * Represents the configuration for a trait in Flagsmith.
117
+ *
118
+ * @property value The {@link FlagsmithTraitValue} for this trait.
119
+ * @property [transient] Indicates whether the trait should be persisted when used in a remote flag evaluation context.
120
+ * Defaults to false.
121
+ */
122
+ export interface TraitConfig {
113
123
  value: FlagsmithTraitValue;
114
124
  transient?: boolean;
115
125
  }
116
- export declare type FlagsmithTraitValue = IFlagsmithValue;
126
+ export declare type FlagsmithTraitValue = FlagsmithValue;
@@ -1,9 +1,9 @@
1
- import { Fetch, FlagsmithTraitValue, ITraitConfig } from './types.js';
2
- import { Dispatcher } from "undici-types";
1
+ import { Fetch, FlagsmithTraitValue, TraitConfig } from './types.js';
2
+ import { Dispatcher } from 'undici-types';
3
3
  type Traits = {
4
- [key: string]: ITraitConfig | FlagsmithTraitValue;
4
+ [key: string]: TraitConfig | FlagsmithTraitValue;
5
5
  };
6
- export declare function isTraitConfig(traitValue: ITraitConfig | FlagsmithTraitValue): traitValue is ITraitConfig;
6
+ export declare function isTraitConfig(traitValue: TraitConfig | FlagsmithTraitValue): traitValue is TraitConfig;
7
7
  export declare function generateIdentitiesData(identifier: string, traits: Traits, transient: boolean): {
8
8
  identifier: string;
9
9
  traits: ({
@@ -11,13 +11,13 @@ function generateIdentitiesData(identifier, traits, transient) {
11
11
  return {
12
12
  trait_key: key,
13
13
  trait_value: value?.value,
14
- transient: value?.transient,
14
+ transient: value?.transient
15
15
  };
16
16
  }
17
17
  else {
18
18
  return {
19
19
  trait_key: key,
20
- trait_value: value,
20
+ trait_value: value
21
21
  };
22
22
  }
23
23
  });
@@ -1,4 +1,4 @@
1
- import { randomUUID as uuidv4 } from "node:crypto";
1
+ import { randomUUID as uuidv4 } from 'node:crypto';
2
2
  import { getHashedPercentateForObjIds } from '../utils/hashing/index.js';
3
3
  export class FeatureModel {
4
4
  id;
@@ -4,9 +4,9 @@ export function buildFeatureModel(featuresModelJSON) {
4
4
  }
5
5
  export function buildFeatureStateModel(featuresStateModelJSON) {
6
6
  const featureStateModel = new FeatureStateModel(buildFeatureModel(featuresStateModelJSON.feature), featuresStateModelJSON.enabled, featuresStateModelJSON.django_id, featuresStateModelJSON.feature_state_value, featuresStateModelJSON.featurestate_uuid);
7
- featureStateModel.featureSegment = featuresStateModelJSON.feature_segment ?
8
- buildFeatureSegment(featuresStateModelJSON.feature_segment) :
9
- undefined;
7
+ featureStateModel.featureSegment = featuresStateModelJSON.feature_segment
8
+ ? buildFeatureSegment(featuresStateModelJSON.feature_segment)
9
+ : undefined;
10
10
  const multivariateFeatureStateValues = featuresStateModelJSON.multivariate_feature_state_values
11
11
  ? featuresStateModelJSON.multivariate_feature_state_values.map((fsv) => {
12
12
  const featureOption = new MultivariateFeatureOptionModel(fsv.multivariate_feature_option.value, fsv.multivariate_feature_option.id);
@@ -3,7 +3,7 @@ import { FeatureStateModel } from './features/models.js';
3
3
  import { IdentityModel } from './identities/models.js';
4
4
  import { TraitModel } from './identities/traits/models.js';
5
5
  export { EnvironmentModel } from './environments/models.js';
6
- export { FeatureStateModel } from './features/models.js';
6
+ export { FeatureModel, FeatureStateModel } from './features/models.js';
7
7
  export { IdentityModel } from './identities/models.js';
8
8
  export { TraitModel } from './identities/traits/models.js';
9
9
  export { SegmentModel } from './segments/models.js';
@@ -1,7 +1,7 @@
1
1
  import { getIdentitySegments } from './segments/evaluators.js';
2
2
  import { FeatureStateNotFound } from './utils/errors.js';
3
3
  export { EnvironmentModel } from './environments/models.js';
4
- export { FeatureStateModel } from './features/models.js';
4
+ export { FeatureModel, FeatureStateModel } from './features/models.js';
5
5
  export { IdentityModel } from './identities/models.js';
6
6
  export { TraitModel } from './identities/traits/models.js';
7
7
  export { SegmentModel } from './segments/models.js';