@autofleet/settings 1.2.0 → 1.2.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.
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import EventEmitter from 'events';
4
4
  interface SettingsClassOptions {
5
5
  serviceUrl?: string;
6
6
  ttl?: number;
7
+ disableTestEnvCheck?: boolean;
7
8
  }
8
9
  declare type SettingValue = string | boolean | number | any[] | never;
9
10
  interface Label {
@@ -23,9 +24,10 @@ declare class SettingsManager {
23
24
  networkEvents: EventEmitter;
24
25
  network: any;
25
26
  NEVER_DEFAULT_VALUE: string;
27
+ disableTestEnvCheck: boolean;
26
28
  static get NEVER_DEFAULT_VALUE(): string;
27
29
  static readNetworkValue(networkValue: SettingValue, defaultValue: SettingValue): SettingValue;
28
- constructor({ serviceUrl, ttl }?: SettingsClassOptions);
30
+ constructor({ serviceUrl, ttl, disableTestEnvCheck }?: SettingsClassOptions);
29
31
  get(key: SettingValue, defaultValue?: any, labels?: LabelsArray, { timeout, rejectOnFail }?: GetSettingOption): Promise<any>;
30
32
  getMultiple(settingsToGet: {
31
33
  key: SettingValue;
package/dist/index.js CHANGED
@@ -33,10 +33,11 @@ const findUrl = (serviceUrl) => serviceUrl
33
33
  class CannotGetNetworkValueError extends Error {
34
34
  }
35
35
  class SettingsManager {
36
- constructor({ serviceUrl, ttl = fiveMinutes } = {}) {
36
+ constructor({ serviceUrl, ttl = fiveMinutes, disableTestEnvCheck = false } = {}) {
37
37
  const localServiceUrl = findUrl(serviceUrl);
38
38
  this.NEVER_DEFAULT_VALUE = SettingsManager.NEVER_DEFAULT_VALUE;
39
39
  this.ttl = ttl;
40
+ this.disableTestEnvCheck = disableTestEnvCheck;
40
41
  this.settingsCache = new node_cache_1.default();
41
42
  this.networkEvents = new events_1.default();
42
43
  this.network = new network_1.default({
@@ -74,7 +75,7 @@ class SettingsManager {
74
75
  }
75
76
  return cacheValue;
76
77
  }
77
- if (process.env.NODE_ENV === 'test') {
78
+ if (!this.disableTestEnvCheck && process.env.NODE_ENV === 'test') {
78
79
  return defaultValue;
79
80
  }
80
81
  let networkValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/settings",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -24,6 +24,7 @@ const findUrl = (serviceUrl?: string) => serviceUrl
24
24
  interface SettingsClassOptions {
25
25
  serviceUrl?: string;
26
26
  ttl?: number;
27
+ disableTestEnvCheck?: boolean;
27
28
  }
28
29
 
29
30
  type SettingValue = string | boolean | number | any[] | never;
@@ -56,6 +57,8 @@ class SettingsManager {
56
57
 
57
58
  NEVER_DEFAULT_VALUE: string;
58
59
 
60
+ disableTestEnvCheck: boolean;
61
+
59
62
  static get NEVER_DEFAULT_VALUE() {
60
63
  return 'NEVER_DEFAULT_VALUE';
61
64
  }
@@ -70,11 +73,12 @@ class SettingsManager {
70
73
  return returnValue;
71
74
  }
72
75
 
73
- constructor({ serviceUrl, ttl = fiveMinutes }:SettingsClassOptions = {}) {
76
+ constructor({ serviceUrl, ttl = fiveMinutes, disableTestEnvCheck = false }:SettingsClassOptions = {}) {
74
77
  const localServiceUrl = findUrl(serviceUrl);
75
78
 
76
79
  this.NEVER_DEFAULT_VALUE = SettingsManager.NEVER_DEFAULT_VALUE;
77
80
  this.ttl = ttl;
81
+ this.disableTestEnvCheck = disableTestEnvCheck;
78
82
  this.settingsCache = new NodeCache();
79
83
  this.networkEvents = new EventEmitter();
80
84
  this.network = new Network({
@@ -109,7 +113,7 @@ class SettingsManager {
109
113
  return cacheValue;
110
114
  }
111
115
 
112
- if (process.env.NODE_ENV === 'test') {
116
+ if (!this.disableTestEnvCheck && process.env.NODE_ENV === 'test') {
113
117
  return defaultValue;
114
118
  }
115
119