@autofleet/settings 1.2.1 → 1.2.2

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
@@ -7,11 +7,16 @@ interface SettingsClassOptions {
7
7
  disableTestEnvCheck?: boolean;
8
8
  }
9
9
  declare type SettingValue = string | boolean | number | any[] | never;
10
+ interface Location {
11
+ lat: number;
12
+ lng: number;
13
+ }
10
14
  interface Label {
11
15
  businessModelId?: string;
12
16
  demandSourceId?: string;
13
17
  fleetId?: string;
14
18
  time?: string | Date;
19
+ location?: Location;
15
20
  }
16
21
  declare type LabelsArray = Label[];
17
22
  interface GetSettingOption {
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ const node_cache_1 = __importDefault(require("node-cache"));
22
22
  const events_1 = __importDefault(require("events"));
23
23
  const util_1 = __importDefault(require("util"));
24
24
  const moment_1 = __importDefault(require("moment"));
25
+ const h3_js_1 = __importDefault(require("h3-js"));
25
26
  dotenv_1.default.config();
26
27
  const nextTick = util_1.default.promisify(process.nextTick);
27
28
  const logger = logger_1.default();
@@ -178,6 +179,10 @@ class SettingsManager {
178
179
  if (l.time) {
179
180
  return Object.assign(Object.assign({}, l), { time: moment_1.default(l.time).startOf('hour').format(), day: moment_1.default(l.time).day() });
180
181
  }
182
+ if (l.location && l.location.lat && l.location.lng) {
183
+ const h3Index = h3_js_1.default.geoToH3(l.location.lat, l.location.lng, 8);
184
+ return Object.assign(Object.assign({}, l), { location: h3Index });
185
+ }
181
186
  return l;
182
187
  });
183
188
  const cacheKey = `${key}_${JSON.stringify(newLabels)}`;
@@ -117,6 +117,31 @@ describe('Settings', () => {
117
117
  expect(value).toEqual('value1');
118
118
  expect(m.isDone()).toBeTruthy();
119
119
  }));
120
+ it('Finds with location label', () => __awaiter(void 0, void 0, void 0, function* () {
121
+ const location = { lat: 32.07917469952991, lng: 34.777393341064446 };
122
+ const labels = [{ fleetId: 'uuid', location }];
123
+ const m = mockSetting('key1', 'value1', labels);
124
+ const settings = new index_1.default({
125
+ serviceUrl: `http://${serviceUrl}/`,
126
+ });
127
+ const settingLabel = [{ fleetId: 'uuid', location }];
128
+ const value = yield settings.get('key1', 'dv', settingLabel);
129
+ expect(value).toEqual('value1');
130
+ expect(m.isDone()).toBeTruthy();
131
+ }));
132
+ it('Finds with location and time label', () => __awaiter(void 0, void 0, void 0, function* () {
133
+ const time = new Date();
134
+ const location = { lat: 32.07917469952991, lng: 34.777393341064446 };
135
+ const labels = [{ fleetId: 'uuid', location, time }];
136
+ const m = mockSetting('key1', 'value1', labels);
137
+ const settings = new index_1.default({
138
+ serviceUrl: `http://${serviceUrl}/`,
139
+ });
140
+ const settingLabel = [{ fleetId: 'uuid', location, time }];
141
+ const value = yield settings.get('key1', 'dv', settingLabel);
142
+ expect(value).toEqual('value1');
143
+ expect(m.isDone()).toBeTruthy();
144
+ }));
120
145
  it('Returns default value when network error', () => __awaiter(void 0, void 0, void 0, function* () {
121
146
  const settings = new index_1.default({
122
147
  serviceUrl: `http://${serviceUrl}/`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/settings",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -19,6 +19,7 @@
19
19
  "@types/jest": "^22.0.0",
20
20
  "bluebird": "^3.7.2",
21
21
  "dotenv": "^8.2.0",
22
+ "h3-js": "^3.7.2",
22
23
  "jest": "^22.4.4",
23
24
  "moment": "^2.29.1",
24
25
  "nock": "^10.0.2",
package/src/index.test.ts CHANGED
@@ -131,6 +131,35 @@ describe('Settings', () => {
131
131
  expect(m.isDone()).toBeTruthy();
132
132
  });
133
133
 
134
+ it('Finds with location label', async () => {
135
+ const location = { lat: 32.07917469952991, lng: 34.777393341064446 };
136
+ const labels = [{ fleetId: 'uuid', location }];
137
+ const m = mockSetting('key1', 'value1', labels);
138
+ const settings = new Settings({
139
+ serviceUrl: `http://${serviceUrl}/`,
140
+ });
141
+
142
+ const settingLabel = [{ fleetId: 'uuid', location }];
143
+ const value = await settings.get('key1', 'dv', settingLabel);
144
+ expect(value).toEqual('value1');
145
+ expect(m.isDone()).toBeTruthy();
146
+ });
147
+
148
+ it('Finds with location and time label', async () => {
149
+ const time = new Date();
150
+ const location = { lat: 32.07917469952991, lng: 34.777393341064446 };
151
+ const labels = [{ fleetId: 'uuid', location, time }];
152
+ const m = mockSetting('key1', 'value1', labels);
153
+ const settings = new Settings({
154
+ serviceUrl: `http://${serviceUrl}/`,
155
+ });
156
+
157
+ const settingLabel = [{ fleetId: 'uuid', location, time }];
158
+ const value = await settings.get('key1', 'dv', settingLabel);
159
+ expect(value).toEqual('value1');
160
+ expect(m.isDone()).toBeTruthy();
161
+ });
162
+
134
163
  it('Returns default value when network error', async () => {
135
164
  const settings = new Settings({
136
165
  serviceUrl: `http://${serviceUrl}/`,
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ import NodeCache from 'node-cache';
8
8
  import EventEmitter from 'events';
9
9
  import util from 'util';
10
10
  import moment from 'moment';
11
+ import h3 from 'h3-js';
11
12
 
12
13
  dotenv.config();
13
14
 
@@ -29,11 +30,16 @@ interface SettingsClassOptions {
29
30
 
30
31
  type SettingValue = string | boolean | number | any[] | never;
31
32
 
33
+ interface Location {
34
+ lat: number;
35
+ lng: number;
36
+ }
32
37
  interface Label {
33
38
  businessModelId?: string;
34
39
  demandSourceId?: string;
35
40
  fleetId?: string;
36
41
  time?: string | Date;
42
+ location?: Location;
37
43
  }
38
44
 
39
45
  type LabelsArray = Label[];
@@ -230,6 +236,15 @@ class SettingsManager {
230
236
  day: moment(l.time).day(),
231
237
  };
232
238
  }
239
+
240
+ if (l.location && l.location.lat && l.location.lng) {
241
+ const h3Index = h3.geoToH3(l.location.lat, l.location.lng, 8);
242
+ return {
243
+ ...l,
244
+ location: h3Index,
245
+ };
246
+ }
247
+
233
248
  return l;
234
249
  });
235
250