tabletcommand-incident 0.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/.buildkite/pipeline.yml +5 -0
- package/.eslintrc.js +41 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/build/index.js +49 -0
- package/build/index.js.map +1 -0
- package/build/location.js +138 -0
- package/build/location.js.map +1 -0
- package/build/set-incident-type.js +107 -0
- package/build/set-incident-type.js.map +1 -0
- package/build/store.js +116 -0
- package/build/store.js.map +1 -0
- package/build/test/set-incident-type.js +30 -0
- package/build/test/set-incident-type.js.map +1 -0
- package/build/types.js +3 -0
- package/build/types.js.map +1 -0
- package/cspell.json +57 -0
- package/definitions/index.d.ts +8 -0
- package/definitions/index.d.ts.map +1 -0
- package/definitions/location.d.ts +11 -0
- package/definitions/location.d.ts.map +1 -0
- package/definitions/set-incident-type.d.ts +20 -0
- package/definitions/set-incident-type.d.ts.map +1 -0
- package/definitions/store.d.ts +11 -0
- package/definitions/store.d.ts.map +1 -0
- package/definitions/test/set-incident-type.d.ts +2 -0
- package/definitions/test/set-incident-type.d.ts.map +1 -0
- package/definitions/types.d.ts +35 -0
- package/definitions/types.d.ts.map +1 -0
- package/gulpfile.js +19 -0
- package/package.json +54 -0
- package/src/index.ts +60 -0
- package/src/location.ts +167 -0
- package/src/set-incident-type.ts +135 -0
- package/src/store.ts +133 -0
- package/src/test/set-incident-type.ts +31 -0
- package/src/tsconfig.json +30 -0
- package/src/types.ts +39 -0
- package/test.sh +32 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
env: {
|
|
3
|
+
es6: true,
|
|
4
|
+
node: true,
|
|
5
|
+
mocha: true
|
|
6
|
+
},
|
|
7
|
+
extends: [
|
|
8
|
+
"eslint:recommended",
|
|
9
|
+
"plugin:@typescript-eslint/recommended",
|
|
10
|
+
"plugin:@typescript-eslint/recommended-requiring-type-checking"
|
|
11
|
+
],
|
|
12
|
+
ignorePatterns: [
|
|
13
|
+
".eslintrc.js",
|
|
14
|
+
"gulpfile.js",
|
|
15
|
+
],
|
|
16
|
+
plugins: [
|
|
17
|
+
"@typescript-eslint",
|
|
18
|
+
"promise",
|
|
19
|
+
"security"
|
|
20
|
+
],
|
|
21
|
+
parser: "@typescript-eslint/parser",
|
|
22
|
+
parserOptions: {
|
|
23
|
+
project: "./src/tsconfig.json",
|
|
24
|
+
tsconfigRootDir: __dirname,
|
|
25
|
+
},
|
|
26
|
+
rules: {
|
|
27
|
+
quotes: [2, "double"],
|
|
28
|
+
semi: [2, "always"],
|
|
29
|
+
"space-before-function-paren": [0],
|
|
30
|
+
"@typescript-eslint/explicit-module-boundary-types": 0,
|
|
31
|
+
"@typescript-eslint/no-empty-interface": 0,
|
|
32
|
+
"@typescript-eslint/require-await": 0,
|
|
33
|
+
"@typescript-eslint/restrict-template-expressions": 0,
|
|
34
|
+
"@typescript-eslint/no-misused-promises": [
|
|
35
|
+
"error",
|
|
36
|
+
{
|
|
37
|
+
"checksVoidReturn": false
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
};
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Tablet Command, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.indexFile = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const location_1 = __importDefault(require("./location"));
|
|
9
|
+
const store_1 = __importDefault(require("./store"));
|
|
10
|
+
function indexFile(departmentModel, locationModel, cadVehicleModel) {
|
|
11
|
+
const store = (0, store_1.default)(departmentModel, locationModel, cadVehicleModel);
|
|
12
|
+
const location = (0, location_1.default)(store);
|
|
13
|
+
// async function processVehicle(department: Partial<Department>, item: Partial<CADVehicle>) {
|
|
14
|
+
// // await location.processVehicle()
|
|
15
|
+
// }
|
|
16
|
+
async function processLocations(department, items) {
|
|
17
|
+
const atDate = new Date();
|
|
18
|
+
if (lodash_1.default.isUndefined(items) || lodash_1.default.isNull(items)) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
if (lodash_1.default.isObject(items) && !lodash_1.default.isArray(items)) {
|
|
22
|
+
items = [items];
|
|
23
|
+
}
|
|
24
|
+
const result = await location.processItems(department, items, atDate);
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
// async function processLocationsOnly(department: Partial<Department>, items: Partial<Location>[] | null | undefined, agency: Partial<Agency>) {
|
|
28
|
+
// try {
|
|
29
|
+
// if (_.isUndefined(items) || _.isNull(items)) {
|
|
30
|
+
// return [];
|
|
31
|
+
// }
|
|
32
|
+
// if (_.isObject(items) && !_.isArray(items)) {
|
|
33
|
+
// items = [items];
|
|
34
|
+
// }
|
|
35
|
+
// const result = await location.processItemsNoVehicle(department, items, agency);
|
|
36
|
+
// return result;
|
|
37
|
+
// } catch (err) {
|
|
38
|
+
// throw err;
|
|
39
|
+
// }
|
|
40
|
+
// }
|
|
41
|
+
return {
|
|
42
|
+
// processVehicle,
|
|
43
|
+
processLocations,
|
|
44
|
+
// processLocationsOnly,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
exports.indexFile = indexFile;
|
|
48
|
+
exports.default = indexFile;
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAMA,oDAAuB;AAEvB,0DAAwC;AACxC,oDAAkC;AAGlC,SAAgB,SAAS,CACvB,eAAgC,EAChC,aAA4B,EAC5B,eAAgC;IAEhC,MAAM,KAAK,GAAG,IAAA,eAAW,EAAC,eAAe,EAAE,aAAa,EAAE,eAAe,CAAC,CAAC;IAC3E,MAAM,QAAQ,GAAG,IAAA,kBAAc,EAAC,KAAK,CAAC,CAAC;IACvC,8FAA8F;IAC9F,uCAAuC;IACvC,IAAI;IAEJ,KAAK,UAAU,gBAAgB,CAAC,UAA+B,EAAE,KAA2C;QAC1G,MAAM,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QAE1B,IAAI,gBAAC,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,gBAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;YAC3C,OAAO,EAAE,CAAC;SACX;QACD,IAAI,gBAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YAC1C,KAAK,GAAG,CAAC,KAAK,CAAC,CAAC;SACjB;QACD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,YAAY,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QACtE,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,iJAAiJ;IACjJ,UAAU;IACV,qDAAqD;IACrD,mBAAmB;IACnB,QAAQ;IACR,oDAAoD;IACpD,yBAAyB;IACzB,QAAQ;IACR,sFAAsF;IACtF,qBAAqB;IACrB,oBAAoB;IACpB,iBAAiB;IACjB,MAAM;IACN,IAAI;IAEJ,OAAO;QACL,kBAAkB;QAClB,gBAAgB;QAChB,wBAAwB;KACzB,CAAC;AACJ,CAAC;AA5CD,8BA4CC;AAED,kBAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.location = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const debug_1 = __importDefault(require("debug"));
|
|
9
|
+
function location(store) {
|
|
10
|
+
const debug = (0, debug_1.default)("tabletcommand-location:location");
|
|
11
|
+
async function decodeCADVehicleStatusToLocation(item, department, atDate) {
|
|
12
|
+
let latitude = 0;
|
|
13
|
+
let longitude = 0;
|
|
14
|
+
if (lodash_1.default.isFinite(parseFloat(item.latitude.toString()))) {
|
|
15
|
+
latitude = parseFloat(item.latitude.toString());
|
|
16
|
+
}
|
|
17
|
+
if (lodash_1.default.isFinite(parseFloat(item.longitude.toString()))) {
|
|
18
|
+
longitude = parseFloat(item.longitude.toString());
|
|
19
|
+
}
|
|
20
|
+
if (!lodash_1.default.isString(item.radioName)) {
|
|
21
|
+
item.radioName = "";
|
|
22
|
+
}
|
|
23
|
+
if (!lodash_1.default.isString(item.vehicleId)) {
|
|
24
|
+
item.vehicleId = "";
|
|
25
|
+
}
|
|
26
|
+
const now = atDate.valueOf() / 1000.0;
|
|
27
|
+
// Don't save provided AVL time if it's more than 30s in the future
|
|
28
|
+
const futureTimeLimit = now + 30;
|
|
29
|
+
// If present, replace the modified unix date with the one provided by the CAD
|
|
30
|
+
let movedAtUnix = now;
|
|
31
|
+
if (lodash_1.default.isString(item.avlTime) && lodash_1.default.trim(item.avlTime) !== "") {
|
|
32
|
+
const checkISODate = (new Date(item.avlTime).valueOf()) / 1000.0;
|
|
33
|
+
const cadUnixTime = lodash_1.default.isNaN(checkISODate) && lodash_1.default.isString(item.avlTime) ? parseFloat(item.avlTime) : checkISODate;
|
|
34
|
+
if (lodash_1.default.isFinite(cadUnixTime) && cadUnixTime <= futureTimeLimit) {
|
|
35
|
+
movedAtUnix = cadUnixTime;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const userId = `${item.radioName}-${item.vehicleId}`; // Fake user id radioName - vehicleId
|
|
39
|
+
let sharingEnabled = false;
|
|
40
|
+
let opAreaName = "";
|
|
41
|
+
let opAreaCode = "";
|
|
42
|
+
let deptState = "";
|
|
43
|
+
let locationStaleMinutes = 31 * 24 * 60; // 31d
|
|
44
|
+
if (lodash_1.default.isObject(department) && lodash_1.default.isObject(department.shareAVL)) {
|
|
45
|
+
sharingEnabled = department.shareAVL.enabled && department.accountType === "production";
|
|
46
|
+
opAreaName = department.shareAVL.opAreaName || "";
|
|
47
|
+
opAreaCode = department.shareAVL.opAreaCode || "";
|
|
48
|
+
}
|
|
49
|
+
if (lodash_1.default.isObject(department)) {
|
|
50
|
+
if (lodash_1.default.isObject(department.addressDetails) && lodash_1.default.isString(department.addressDetails.state)) {
|
|
51
|
+
deptState = department.addressDetails.state || "";
|
|
52
|
+
}
|
|
53
|
+
if (lodash_1.default.isNumber(department.locationStaleMinutes) && lodash_1.default.isFinite(department.locationStaleMinutes) && department.locationStaleMinutes > 0) {
|
|
54
|
+
locationStaleMinutes = department.locationStaleMinutes;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const deleteAfterDate = new Date(atDate.valueOf() + 1000 * 60 * locationStaleMinutes).toISOString();
|
|
58
|
+
const cadAVL = {
|
|
59
|
+
device_type: "cad",
|
|
60
|
+
locationGeoJSON: {
|
|
61
|
+
type: "Point",
|
|
62
|
+
coordinates: [longitude, latitude]
|
|
63
|
+
},
|
|
64
|
+
deleteAfterDate,
|
|
65
|
+
modified: atDate.toISOString(),
|
|
66
|
+
movedAt: new Date(movedAtUnix * 1000).toISOString(),
|
|
67
|
+
active: true,
|
|
68
|
+
username: item.radioName,
|
|
69
|
+
userId,
|
|
70
|
+
departmentId: department._id.toString(),
|
|
71
|
+
session: userId,
|
|
72
|
+
version: 2,
|
|
73
|
+
shared: sharingEnabled,
|
|
74
|
+
opAreaName,
|
|
75
|
+
opAreaCode,
|
|
76
|
+
state: deptState,
|
|
77
|
+
};
|
|
78
|
+
if (lodash_1.default.isNumber(item.speed)) {
|
|
79
|
+
const speed = item.speed;
|
|
80
|
+
cadAVL.speed = speed;
|
|
81
|
+
}
|
|
82
|
+
const hasCoordinate = Math.abs(latitude) > 0.01 || Math.abs(longitude) > 0.01;
|
|
83
|
+
const validCoordinate = Math.abs(latitude) < 90 && Math.abs(longitude) < 180;
|
|
84
|
+
const hasVehicle = lodash_1.default.isString(item.vehicleId) && lodash_1.default.trim(item.vehicleId).length > 0;
|
|
85
|
+
const hasRadioName = lodash_1.default.isString(item.radioName) && lodash_1.default.trim(item.radioName).length > 0;
|
|
86
|
+
const isValid = hasCoordinate && validCoordinate && (hasVehicle || hasRadioName);
|
|
87
|
+
return {
|
|
88
|
+
cadAVL,
|
|
89
|
+
isValid,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async function processVehicle(departmentExceptions, item, department, atDate) {
|
|
93
|
+
const departmentId = department._id.toString();
|
|
94
|
+
// need function to validate the item (As concerns vehicleId and radioName)
|
|
95
|
+
const isBidirectionalException = departmentExceptions.indexOf(departmentId) !== -1;
|
|
96
|
+
// Determine if vehicle is active or not
|
|
97
|
+
const cadItem = await store.getVehicle(item, departmentId);
|
|
98
|
+
if (!lodash_1.default.isObject(cadItem) &&
|
|
99
|
+
department.cadOneWayVehiclesEnabled &&
|
|
100
|
+
(department.cadBidirectionalEnabled !== true || isBidirectionalException)) {
|
|
101
|
+
const vehicleItem = {
|
|
102
|
+
departmentId: departmentId,
|
|
103
|
+
modifiedDate: atDate.valueOf() / 1000.0,
|
|
104
|
+
modified: atDate.toISOString(),
|
|
105
|
+
radioName: item.radioName,
|
|
106
|
+
vehicleId: item.vehicleId,
|
|
107
|
+
};
|
|
108
|
+
await store.updateVehicle(vehicleItem, departmentId);
|
|
109
|
+
}
|
|
110
|
+
return cadItem;
|
|
111
|
+
}
|
|
112
|
+
async function processItems(department, items, atDate) {
|
|
113
|
+
for (const item of items) {
|
|
114
|
+
const decoded = await decodeCADVehicleStatusToLocation(item, department, atDate);
|
|
115
|
+
debug(`processCADVehicleLocation item: ${JSON.stringify(item)} d:${JSON.stringify(department)} at: ${atDate.toISOString()}.`);
|
|
116
|
+
if (!decoded.isValid) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
let active = true;
|
|
120
|
+
const cadBidirectionalExceptions = [
|
|
121
|
+
"627d718b8d6145748b30282b" // HMT (2 way comments, 1 way vehicles)
|
|
122
|
+
];
|
|
123
|
+
const cadItem = await processVehicle(cadBidirectionalExceptions, item, department, atDate);
|
|
124
|
+
if (lodash_1.default.isObject(cadItem) && lodash_1.default.isBoolean(cadItem.mapHidden)) {
|
|
125
|
+
active = !cadItem.mapHidden;
|
|
126
|
+
}
|
|
127
|
+
decoded.cadAVL.active = active;
|
|
128
|
+
await store.updateLocation(decoded.cadAVL, atDate);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
processVehicle,
|
|
133
|
+
processItems,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
exports.location = location;
|
|
137
|
+
exports.default = location;
|
|
138
|
+
//# sourceMappingURL=location.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location.js","sourceRoot":"","sources":["../src/location.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,kDAAgC;AAahC,SAAgB,QAAQ,CAAC,KAAkB;IACzC,MAAM,KAAK,GAAG,IAAA,eAAW,EAAC,iCAAiC,CAAC,CAAC;IAE7D,KAAK,UAAU,gCAAgC,CAAC,IAAqB,EAAE,UAA+B,EAAE,MAAY;QAClH,IAAI,QAAQ,GAAG,CAAC,CAAC;QACjB,IAAI,SAAS,GAAG,CAAC,CAAC;QAElB,IAAI,gBAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE;YACpD,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;SACjD;QAED,IAAI,gBAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE;YACrD,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;SACnD;QAED,IAAI,CAAC,gBAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YAC/B,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;SACrB;QAED,IAAI,CAAC,gBAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YAC/B,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;SACrB;QAED,MAAM,GAAG,GAAG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3F,IAAI,gBAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,gBAAC,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;gBACzD,MAAM,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC;aAC7B;YAED,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;YAC/B,MAAM,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;SACpD;IACH,CAAC;IAED,OAAO;QACL,cAAc;QACd,YAAY;KACb,CAAC;AACJ,CAAC;AArJD,4BAqJC;AAED,kBAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
7
|
+
// Change incident by reference
|
|
8
|
+
function setIncidentTypeAny(incident) {
|
|
9
|
+
if (!lodash_1.default.isArray(incident.notificationType)) {
|
|
10
|
+
incident.notificationType = [];
|
|
11
|
+
}
|
|
12
|
+
let foundTypeAny = false;
|
|
13
|
+
lodash_1.default.map(incident.notificationType, function (t) {
|
|
14
|
+
if (lodash_1.default.isString(t.value) && t.value === "any") {
|
|
15
|
+
foundTypeAny = true;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
});
|
|
19
|
+
if (!foundTypeAny) {
|
|
20
|
+
incident.notificationType.push({
|
|
21
|
+
name: "Any",
|
|
22
|
+
value: "any"
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function matchCurrentAgainstTypes(value, types, allowPartialMatch, resolveTo) {
|
|
27
|
+
let found = null;
|
|
28
|
+
if (value === "") {
|
|
29
|
+
return found;
|
|
30
|
+
}
|
|
31
|
+
if (!lodash_1.default.isArray(types)) {
|
|
32
|
+
return found;
|
|
33
|
+
}
|
|
34
|
+
types.forEach((callTypeItem) => {
|
|
35
|
+
// If incident contains that call type, consider it a match
|
|
36
|
+
// This will address the situations when callTypeDescription has a
|
|
37
|
+
// dynamic prefix not defined in the call type array
|
|
38
|
+
const lowerCasedCallTypeItem = callTypeItem.toLowerCase();
|
|
39
|
+
const containsMatch = value.includes(lowerCasedCallTypeItem);
|
|
40
|
+
const exactMatch = value === lowerCasedCallTypeItem;
|
|
41
|
+
const isMatch = exactMatch || (containsMatch && allowPartialMatch === true);
|
|
42
|
+
if (isMatch) {
|
|
43
|
+
found = resolveTo;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return found;
|
|
47
|
+
}
|
|
48
|
+
function setIncidentTypeUsingConfiguration(incident, incidentTypes) {
|
|
49
|
+
let matched = false;
|
|
50
|
+
if (!lodash_1.default.isArray(incidentTypes) || lodash_1.default.size(incidentTypes) === 0) {
|
|
51
|
+
return matched;
|
|
52
|
+
}
|
|
53
|
+
let incidentCallTypeDescription = "";
|
|
54
|
+
if (lodash_1.default.isString(incident.AgencyIncidentCallTypeDescription) && incident.AgencyIncidentCallTypeDescription !== "") {
|
|
55
|
+
incidentCallTypeDescription = incident.AgencyIncidentCallTypeDescription.toLowerCase();
|
|
56
|
+
}
|
|
57
|
+
let incidentCallType = "";
|
|
58
|
+
if (lodash_1.default.isString(incident.AgencyIncidentCallType) && incident.AgencyIncidentCallType !== "") {
|
|
59
|
+
incidentCallType = incident.AgencyIncidentCallType.toLowerCase();
|
|
60
|
+
}
|
|
61
|
+
lodash_1.default.each(incidentTypes, function (item) {
|
|
62
|
+
if (incidentCallType !== "") {
|
|
63
|
+
const foundType = matchCurrentAgainstTypes(incidentCallType, item.callType, item.allowPartialMatch, {
|
|
64
|
+
name: item.name,
|
|
65
|
+
value: item.value,
|
|
66
|
+
});
|
|
67
|
+
matched = appendNotification(incident, foundType);
|
|
68
|
+
}
|
|
69
|
+
if (incidentCallTypeDescription !== "") {
|
|
70
|
+
const foundTypeDescription = matchCurrentAgainstTypes(incidentCallTypeDescription, item.callTypeDescription, item.allowPartialMatch, {
|
|
71
|
+
name: item.name,
|
|
72
|
+
value: item.value,
|
|
73
|
+
});
|
|
74
|
+
matched = appendNotification(incident, foundTypeDescription);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return matched;
|
|
78
|
+
}
|
|
79
|
+
function appendNotification(incident, foundType) {
|
|
80
|
+
if (foundType === null) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
if (!lodash_1.default.isArray(incident.notificationType)) {
|
|
84
|
+
incident.notificationType = [];
|
|
85
|
+
}
|
|
86
|
+
const existingMatches = incident.notificationType.filter((n) => n.value === foundType.value);
|
|
87
|
+
// This item was already added
|
|
88
|
+
if (existingMatches.length > 0) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
incident.notificationType.push(foundType);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
function setIncidentType(incident, incidentTypes) {
|
|
95
|
+
setIncidentTypeAny(incident);
|
|
96
|
+
const hasDatabaseConfiguration = lodash_1.default.isArray(incidentTypes) && incidentTypes.length > 0;
|
|
97
|
+
if (hasDatabaseConfiguration) {
|
|
98
|
+
setIncidentTypeUsingConfiguration(incident, incidentTypes);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const setIncidentTypeModule = {
|
|
102
|
+
setIncidentTypeAny,
|
|
103
|
+
setIncidentTypeUsingConfiguration,
|
|
104
|
+
setIncidentType
|
|
105
|
+
};
|
|
106
|
+
exports.default = setIncidentTypeModule;
|
|
107
|
+
//# sourceMappingURL=set-incident-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-incident-type.js","sourceRoot":"","sources":["../src/set-incident-type.ts"],"names":[],"mappings":";;;;;AAAA,oDAAuB;AAavB,+BAA+B;AAC/B,SAAS,kBAAkB,CA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AAe,qBAAqB,CAAC"}
|
package/build/store.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.store = void 0;
|
|
7
|
+
const debug_1 = __importDefault(require("debug"));
|
|
8
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
+
function store(departmentModel, locationModel, cadVehicleModel) {
|
|
10
|
+
const debug = (0, debug_1.default)("tabletcommand-location:location:store");
|
|
11
|
+
async function getVehicle(item, departmentId) {
|
|
12
|
+
const query = {
|
|
13
|
+
vehicleId: item.vehicleId,
|
|
14
|
+
departmentId,
|
|
15
|
+
};
|
|
16
|
+
return cadVehicleModel.findOne(query).lean();
|
|
17
|
+
}
|
|
18
|
+
async function updateVehicle(item, departmentId) {
|
|
19
|
+
const query = {
|
|
20
|
+
departmentId,
|
|
21
|
+
vehicleId: item.vehicleId,
|
|
22
|
+
};
|
|
23
|
+
const options = {
|
|
24
|
+
upsert: true,
|
|
25
|
+
setDefaultsOnInsert: true,
|
|
26
|
+
new: true
|
|
27
|
+
};
|
|
28
|
+
return await cadVehicleModel.findOneAndUpdate(query, item, options);
|
|
29
|
+
}
|
|
30
|
+
async function updateLocation(item, atDate) {
|
|
31
|
+
const modelItem = new locationModel(item);
|
|
32
|
+
const query = {
|
|
33
|
+
device_type: modelItem.device_type,
|
|
34
|
+
departmentId: modelItem.departmentId,
|
|
35
|
+
username: modelItem.username
|
|
36
|
+
};
|
|
37
|
+
debug(`Location.findOne: ${JSON.stringify(query)}`);
|
|
38
|
+
const dbItem = await locationModel.findOne(query).lean().exec();
|
|
39
|
+
const cloneItem = Object.assign({}, dbItem);
|
|
40
|
+
let updatedItem = propagateLocation(modelItem, dbItem);
|
|
41
|
+
debug(`Location.save: ${JSON.stringify(updatedItem)}`);
|
|
42
|
+
if (cloneItem._id) {
|
|
43
|
+
const locationDelta = generateLocationDelta(cloneItem, updatedItem, atDate);
|
|
44
|
+
updatedItem = locationDelta;
|
|
45
|
+
debug(`Location.delta: ${JSON.stringify(locationDelta)}`);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// if new location record - Attempt to reconcile agency name and code to resources
|
|
49
|
+
// this is going to be resolved by the bin/cron-cleanup-minute cron
|
|
50
|
+
}
|
|
51
|
+
await locationModel.updateOne(query, {
|
|
52
|
+
$set: updatedItem,
|
|
53
|
+
}, {
|
|
54
|
+
upsert: true,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function propagateLocation(modelItem, dbItem) {
|
|
58
|
+
if (!lodash_1.default.isObject(dbItem)) {
|
|
59
|
+
return modelItem;
|
|
60
|
+
}
|
|
61
|
+
// We keep the same value for _id, uuid, departmentId
|
|
62
|
+
dbItem.active = modelItem.active;
|
|
63
|
+
dbItem.altitude = modelItem.altitude;
|
|
64
|
+
dbItem.device_type = modelItem.device_type;
|
|
65
|
+
dbItem.heading = modelItem.heading;
|
|
66
|
+
dbItem.modified = modelItem.modified;
|
|
67
|
+
dbItem.movedAt = modelItem.movedAt;
|
|
68
|
+
dbItem.session = modelItem.session;
|
|
69
|
+
dbItem.speed = modelItem.speed;
|
|
70
|
+
dbItem.userId = modelItem.userId;
|
|
71
|
+
dbItem.username = modelItem.username;
|
|
72
|
+
dbItem.version = modelItem.version;
|
|
73
|
+
dbItem.locationGeoJSON = modelItem.locationGeoJSON;
|
|
74
|
+
// Propagate sharedAVL items
|
|
75
|
+
dbItem.opAreaCode = modelItem.opAreaCode;
|
|
76
|
+
dbItem.opAreaName = modelItem.opAreaName;
|
|
77
|
+
dbItem.shared = modelItem.shared;
|
|
78
|
+
dbItem.state = modelItem.state;
|
|
79
|
+
return dbItem;
|
|
80
|
+
}
|
|
81
|
+
function generateLocationDelta(locationRecord, updateObject, atDate) {
|
|
82
|
+
if (!lodash_1.default.isObject(locationRecord)) {
|
|
83
|
+
return updateObject;
|
|
84
|
+
}
|
|
85
|
+
const locationDelta = {};
|
|
86
|
+
for (const [key, value] of Object.entries(updateObject)) {
|
|
87
|
+
if (JSON.stringify(value) !== JSON.stringify(locationRecord[key])) {
|
|
88
|
+
locationDelta[key] = value;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const updatedKeys = Object.keys(locationDelta);
|
|
92
|
+
const propsKeys = [
|
|
93
|
+
"active",
|
|
94
|
+
"agencyCode",
|
|
95
|
+
"agencyName",
|
|
96
|
+
"device_type",
|
|
97
|
+
"opAreaCode",
|
|
98
|
+
"opAreaName",
|
|
99
|
+
"shared",
|
|
100
|
+
"state",
|
|
101
|
+
"username",
|
|
102
|
+
];
|
|
103
|
+
if (lodash_1.default.intersection(updatedKeys, propsKeys).length > 0) {
|
|
104
|
+
locationDelta.propsChangedAt = atDate.toISOString();
|
|
105
|
+
}
|
|
106
|
+
return locationDelta;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
getVehicle,
|
|
110
|
+
updateVehicle,
|
|
111
|
+
updateLocation,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
exports.store = store;
|
|
115
|
+
exports.default = store;
|
|
116
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAgC;AAQhC,oDAAuB;AAIvB,SAAgB,KAAK,CACnB,eAAgC,EAChC,aAA4B,EAC5B,eAAgC;IAEhC,MAAM,KAAK,GAAG,IAAA,eAAW,EAAC,uCAAuC,CAAC,CAAC;IAEnE,KAAK,UAAU,UAAU,CAAC,IAAqB,EAAE,YAAoB;QACnE,MAAM,KAAK,GAAG;YACZ,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,YAAY;SACb,CAAC;QACF,OAAO,eAAe,CAAC,OAAO,CAAC,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AAS,CAAC,KAAK,CAAC;QAE/B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,SAAS,qBAAqB,CAAC,cAAuC,EAAE,YAAqC,EAAE,MAAY;QACzH,IAAI,CAAC,gBAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE;YAC/B,OAAO,YAAY,CAAC;SACrB;QACD,MAAM,aAAa,GAA4B,EAAE,CAAC;QAClD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;YACvD,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,EAAE;gBACjE,aAAa,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;aAC5B;SACF;QAED,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC/C,MAAM,SAAS,GAAG;YAChB,QAAQ;YACR,YAAY;YACZ,YAAY;YACZ,aAAa;YACb,YAAY;YACZ,YAAY;YACZ,QAAQ;YACR,OAAO;YACP,UAAU;SACX,CAAC;QACF,IAAI,gBAAC,CAAC,YAAY,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACrD,aAAa,CAAC,cAAc,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;SACrD;QAED,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,OAAO;QACH,UAAU;QACV,aAAa;QACb,cAAc;KACjB,CAAC;AACJ,CAAC;AAtHD,sBAsHC;AACD,kBAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const chai_1 = __importDefault(require("chai"));
|
|
7
|
+
require("mocha");
|
|
8
|
+
const assert = chai_1.default.assert;
|
|
9
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
+
const set_incident_type_1 = __importDefault(require("../set-incident-type"));
|
|
11
|
+
const testMatchCombineCrossStreet = {
|
|
12
|
+
departmentId: "515",
|
|
13
|
+
IncidentNumber: "i1238",
|
|
14
|
+
CrossStreet1: "Cedar Rd",
|
|
15
|
+
CrossStreet2: "Thunder Dr",
|
|
16
|
+
LocationComment: "1700 Bart Dr"
|
|
17
|
+
};
|
|
18
|
+
describe("incident type", function () {
|
|
19
|
+
it("should set incident type any", function () {
|
|
20
|
+
var _a;
|
|
21
|
+
const testMatchIncident = lodash_1.default.clone(testMatchCombineCrossStreet);
|
|
22
|
+
set_incident_type_1.default.setIncidentType(testMatchIncident, []);
|
|
23
|
+
assert.ok(lodash_1.default.has(testMatchIncident, "notificationType"), "Should have notificationType");
|
|
24
|
+
assert.strictEqual(lodash_1.default.size(testMatchIncident.notificationType), 1);
|
|
25
|
+
const a = (_a = testMatchIncident.notificationType) === null || _a === void 0 ? void 0 : _a[0];
|
|
26
|
+
assert.strictEqual(a === null || a === void 0 ? void 0 : a.name, "Any");
|
|
27
|
+
assert.strictEqual(a === null || a === void 0 ? void 0 : a.value, "any");
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=set-incident-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-incident-type.js","sourceRoot":"","sources":["../../src/test/set-incident-type.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,iBAAe;AAEf,MAAM,MAAM,GAAG,cAAI,CAAC,MAAM,CAAC;AAE3B,oDAAuB;AAGvB,6EAAmD;AAEnD,MAAM,2BAA2B,GAAyB;IACxD,YAAY,EAAE,KAAK;IACnB,cAAc,EAAE,OAAO;IACvB,YAAY,EAAE,UAAU;IACxB,YAAY,EAAE,YAAY;IAC1B,eAAe,EAAE,cAAc;CAChC,CAAC;AAEF,QAAQ,CAAC,eAAe,EAAE;IACxB,EAAE,CAAC,8BAA8B,EAAE;;QACjC,MAAM,iBAAiB,GAAG,gBAAC,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/D,2BAAe,CAAC,eAAe,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;QAEvD,MAAM,CAAC,EAAE,CAAC,gBAAC,CAAC,GAAG,CAAC,iBAAiB,EAAE,kBAAkB,CAAC,EAAE,8BAA8B,CAAC,CAAC;QACxF,MAAM,CAAC,WAAW,CAAC,gBAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC;QAElE,MAAM,CAAC,GAAG,MAAA,iBAAiB,CAAC,gBAAgB,0CAAG,CAAC,CAAC,CAAC;QAClD,MAAM,CAAC,WAAW,CAAC,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QACnC,MAAM,CAAC,WAAW,CAAC,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/build/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/cspell.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// cSpell Settings
|
|
2
|
+
{
|
|
3
|
+
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
|
|
4
|
+
"version": "0.2",
|
|
5
|
+
// language - current active spelling language
|
|
6
|
+
"language": "en-US",
|
|
7
|
+
// words - list of words to be always considered correct
|
|
8
|
+
"words": [
|
|
9
|
+
"backend",
|
|
10
|
+
"bamse",
|
|
11
|
+
"devops",
|
|
12
|
+
"dmon",
|
|
13
|
+
"helloworld",
|
|
14
|
+
"mget",
|
|
15
|
+
"mockgoose",
|
|
16
|
+
"signup",
|
|
17
|
+
"stacktraces",
|
|
18
|
+
"tabletcommand",
|
|
19
|
+
"tyrion",
|
|
20
|
+
"unixtime",
|
|
21
|
+
"Ursache",
|
|
22
|
+
"personnelapi",
|
|
23
|
+
"agencypersonnelapi",
|
|
24
|
+
"expireat",
|
|
25
|
+
"agencyapi",
|
|
26
|
+
"accesslog",
|
|
27
|
+
"hincrby",
|
|
28
|
+
"hgetall",
|
|
29
|
+
"myhash",
|
|
30
|
+
"virtuals",
|
|
31
|
+
"apikey",
|
|
32
|
+
"personnelapikey",
|
|
33
|
+
"signupkey",
|
|
34
|
+
"fdid",
|
|
35
|
+
"flushall",
|
|
36
|
+
"zonehaven"
|
|
37
|
+
],
|
|
38
|
+
// flagWords - list of words to be always considered incorrect
|
|
39
|
+
// This is useful for offensive words and common spelling errors.
|
|
40
|
+
// For example "hte" should be "the"
|
|
41
|
+
"flagWords": [
|
|
42
|
+
"hte"
|
|
43
|
+
],
|
|
44
|
+
"ignoreWords": [],
|
|
45
|
+
"languageSettings": [{
|
|
46
|
+
"languageId": "*",
|
|
47
|
+
"dictionaries": []
|
|
48
|
+
}],
|
|
49
|
+
"ignorePaths": [
|
|
50
|
+
"node_modules",
|
|
51
|
+
"src/**/*.svg",
|
|
52
|
+
"/project-words.txt"
|
|
53
|
+
],
|
|
54
|
+
"files": [
|
|
55
|
+
"src/**"
|
|
56
|
+
]
|
|
57
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DepartmentModel, LocationModel, CADVehicleModel, Department } from "tabletcommand-backend-models";
|
|
2
|
+
import { LocationPayload } from "./types";
|
|
3
|
+
export declare function indexFile(departmentModel: DepartmentModel, locationModel: LocationModel, cadVehicleModel: CADVehicleModel): {
|
|
4
|
+
processLocations: (department: Partial<Department>, items: LocationPayload[] | null | undefined) => Promise<void | never[]>;
|
|
5
|
+
};
|
|
6
|
+
export default indexFile;
|
|
7
|
+
export declare type IncidentModule = ReturnType<typeof indexFile>;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,aAAa,EACb,eAAe,EACf,UAAU,EACX,MAAM,8BAA8B,CAAC;AAKtC,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,wBAAgB,SAAS,CACvB,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,aAAa,EAC5B,eAAe,EAAE,eAAe;mCAQY,QAAQ,UAAU,CAAC,SAAS,eAAe,EAAE,GAAG,IAAI,GAAG,SAAS;EAiC7G;AAED,eAAe,SAAS,CAAC;AACzB,oBAAY,cAAc,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
import { Department, CADVehicle } from "tabletcommand-backend-models";
|
|
3
|
+
import { LocationPayload } from "./types";
|
|
4
|
+
import { StoreModule } from "./store";
|
|
5
|
+
export declare function location(store: StoreModule): {
|
|
6
|
+
processVehicle: (departmentExceptions: string[], item: LocationPayload, department: Partial<Department>, atDate: Date) => Promise<mongoose.DocumentDefinition<CADVehicle> | null>;
|
|
7
|
+
processItems: (department: Partial<Department>, items: LocationPayload[], atDate: Date) => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
export default location;
|
|
10
|
+
export declare type LocationModule = ReturnType<typeof location>;
|
|
11
|
+
//# sourceMappingURL=location.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location.d.ts","sourceRoot":"","sources":["../src/location.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,OAAO,EACL,UAAU,EAEV,UAAU,EACX,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,eAAe,EAChB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,wBAAgB,QAAQ,CAAC,KAAK,EAAE,WAAW;2CAmGW,MAAM,EAAE,QAAQ,eAAe,cAAc,QAAQ,UAAU,CAAC,UAAU,IAAI;+BAsB1F,QAAQ,UAAU,CAAC,SAAS,eAAe,EAAE,UAAU,IAAI;EA4BpG;AAED,eAAe,QAAQ,CAAC;AACxB,oBAAY,cAAc,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC"}
|