flagsmith-nodejs 2.0.3 → 2.1.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.
@@ -20,5 +20,8 @@
20
20
  "ssg-node-express": "4.16.4",
21
21
  "ssg-util": "0.0.3"
22
22
  },
23
- "keywords": []
23
+ "keywords": [],
24
+ "devDependencies": {
25
+ "nodemon": "^2.0.19"
26
+ }
24
27
  }
@@ -6,6 +6,14 @@ import { getIdentitySegments } from './segments/evaluators';
6
6
  import { SegmentModel } from './segments/models';
7
7
  import { FeatureStateNotFound } from './utils/errors';
8
8
 
9
+ export { EnvironmentModel } from './environments/models';
10
+ export { IntegrationModel } from './environments/integrations/models';
11
+ export { FeatureStateModel } from './features/models';
12
+ export { IdentityModel } from './identities/models';
13
+ export { TraitModel } from './identities/traits/models';
14
+ export { SegmentModel } from './segments/models';
15
+ export { OrganisationModel } from './organisations/models';
16
+
9
17
  function getIdentityFeatureStatesDict(
10
18
  environment: EnvironmentModel,
11
19
  identity: IdentityModel,
package/index.ts CHANGED
@@ -1,6 +1,23 @@
1
1
  import Flagsmith from './sdk';
2
2
 
3
- export { Flagsmith } from './sdk';
4
- // export default Flagsmith;
3
+ export {
4
+ AnalyticsProcessor,
5
+ FlagsmithAPIError,
6
+ FlagsmithClientError,
7
+ EnvironmentDataPollingManager,
8
+ FlagsmithCache,
9
+ DefaultFlag,
10
+ Flags
11
+ } from './sdk';
5
12
 
13
+ export {
14
+ EnvironmentModel,
15
+ IntegrationModel,
16
+ FeatureStateModel,
17
+ IdentityModel,
18
+ TraitModel,
19
+ SegmentModel,
20
+ OrganisationModel
21
+ } from './flagsmith-engine';
22
+ export default Flagsmith
6
23
  module.exports = Flagsmith;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flagsmith-nodejs",
3
- "version": "2.0.3",
3
+ "version": "2.1.1",
4
4
  "description": "Flagsmith lets you manage features flags and remote config across web, mobile and server side applications. Deliver true Continuous Integration. Get builds out faster. Control who has access to new features.",
5
5
  "main": "build/index.js",
6
6
  "repository": {
package/sdk/analytics.ts CHANGED
@@ -49,8 +49,8 @@ export class AnalyticsProcessor {
49
49
  this.lastFlushed = Date.now();
50
50
  }
51
51
 
52
- trackFeature(featureId: number) {
53
- this.analyticsData[featureId] = (this.analyticsData[featureId] || 0) + 1;
52
+ trackFeature(featureName: string) {
53
+ this.analyticsData[featureName] = (this.analyticsData[featureName] || 0) + 1;
54
54
  if (Date.now() - this.lastFlushed > ANALYTICS_TIMER * 1000) {
55
55
  this.flush();
56
56
  }
package/sdk/index.ts CHANGED
@@ -14,6 +14,13 @@ import { SegmentModel } from '../flagsmith-engine/segments/models';
14
14
  import { getIdentitySegments } from '../flagsmith-engine/segments/evaluators';
15
15
  import { FlagsmithCache } from './types';
16
16
 
17
+ export { AnalyticsProcessor } from './analytics';
18
+ export { FlagsmithAPIError, FlagsmithClientError } from './errors';
19
+
20
+ export { DefaultFlag, Flags } from './models';
21
+ export { EnvironmentDataPollingManager } from './polling_manager';
22
+ export { FlagsmithCache } from './types';
23
+
17
24
  const DEFAULT_API_URL = 'https://edge.api.flagsmith.com/api/v1/';
18
25
 
19
26
  export class Flagsmith {
@@ -387,3 +394,4 @@ export class Flagsmith {
387
394
  }
388
395
 
389
396
  export default Flagsmith;
397
+
package/sdk/models.ts CHANGED
@@ -129,7 +129,7 @@ export class Flags {
129
129
  }
130
130
 
131
131
  if (this.analyticsProcessor && flag.featureId) {
132
- this.analyticsProcessor.trackFeature(flag.featureId);
132
+ this.analyticsProcessor.trackFeature(flag.featureName);
133
133
  }
134
134
 
135
135
  return flag;
@@ -8,28 +8,28 @@ afterEach(() => {
8
8
 
9
9
  test('test_analytics_processor_track_feature_updates_analytics_data', () => {
10
10
  const aP = analyticsProcessor();
11
- aP.trackFeature(1);
12
- expect(aP.analyticsData[1]).toBe(1);
11
+ aP.trackFeature("myFeature");
12
+ expect(aP.analyticsData["myFeature"]).toBe(1);
13
13
 
14
- aP.trackFeature(1);
15
- expect(aP.analyticsData[1]).toBe(2);
14
+ aP.trackFeature("myFeature");
15
+ expect(aP.analyticsData["myFeature"]).toBe(2);
16
16
  });
17
17
 
18
18
  test('test_analytics_processor_flush_clears_analytics_data', async () => {
19
19
  const aP = analyticsProcessor();
20
- aP.trackFeature(1);
20
+ aP.trackFeature("myFeature");
21
21
  await aP.flush();
22
22
  expect(aP.analyticsData).toStrictEqual({});
23
23
  });
24
24
 
25
25
  test('test_analytics_processor_flush_post_request_data_match_ananlytics_data', async () => {
26
26
  const aP = analyticsProcessor();
27
- aP.trackFeature(1);
28
- aP.trackFeature(2);
27
+ aP.trackFeature("myFeature1");
28
+ aP.trackFeature("myFeature2");
29
29
  await aP.flush();
30
30
  expect(fetch).toHaveBeenCalledTimes(1);
31
31
  expect(fetch).toHaveBeenCalledWith('http://testUrlanalytics/flags/', {
32
- body: '{"1":1,"2":1}',
32
+ body: '{"myFeature1":1,"myFeature2":1}',
33
33
  headers: { 'Content-Type': 'application/json', 'X-Environment-Key': 'test-key' },
34
34
  method: 'POST',
35
35
  timeout: 3
@@ -39,9 +39,9 @@ test('test_analytics_processor_flush_post_request_data_match_ananlytics_data', a
39
39
  jest.useFakeTimers()
40
40
  test('test_analytics_processor_flush_post_request_data_match_ananlytics_data_test', async () => {
41
41
  const aP = analyticsProcessor();
42
- aP.trackFeature(1);
42
+ aP.trackFeature("myFeature1");
43
43
  setTimeout(() => {
44
- aP.trackFeature(2);
44
+ aP.trackFeature("myFeature2");
45
45
  expect(fetch).toHaveBeenCalledTimes(1);
46
46
  }, 15000);
47
47
  jest.runOnlyPendingTimers();