proximiio-js-library 1.7.0 → 1.7.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.
@@ -0,0 +1,8 @@
1
+ export default class BaseLogger {
2
+ id: string;
3
+ organization_id: string;
4
+ organization_name?: string;
5
+ visitor_id: string;
6
+ createdAt: Date;
7
+ constructor(data: any);
8
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var uuid_1 = require("uuid");
4
+ var BaseLogger = /** @class */ (function () {
5
+ function BaseLogger(data) {
6
+ this.id = data.id ? data.id : uuid_1.v4() + ":" + uuid_1.v4();
7
+ this.organization_id = data.organization_id;
8
+ this.organization_name = data.organization_name;
9
+ this.visitor_id = data.visitor_id ? data.visitor_id : uuid_1.v4();
10
+ this.createdAt = data.createdAt ? data.createdAt : new Date();
11
+ }
12
+ return BaseLogger;
13
+ }());
14
+ exports.default = BaseLogger;
@@ -0,0 +1,8 @@
1
+ export default class BaseLogger {
2
+ id: string;
3
+ organization_id: string;
4
+ organization_name?: string;
5
+ visitor_id: string;
6
+ createdAt: Date;
7
+ constructor(data: any);
8
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var common_1 = require("../../common");
4
+ var BaseLogger = /** @class */ (function () {
5
+ function BaseLogger(data) {
6
+ this.id = data.id ? data.id : common_1.uuidv4 + ":" + common_1.uuidv4;
7
+ this.organization_id = data.organization_id;
8
+ this.organization_name = data.organization_name;
9
+ this.visitor_id = data.visitor_id ? data.visitor_id : "" + common_1.uuidv4;
10
+ this.createdAt = data.createdAt ? data.createdAt : new Date();
11
+ }
12
+ return BaseLogger;
13
+ }());
14
+ exports.default = BaseLogger;
@@ -0,0 +1,25 @@
1
+ import BaseLogger from './base';
2
+ export default class WayfindingLogger extends BaseLogger {
3
+ startLngLat: [number, number];
4
+ startLevel: number;
5
+ startSegmentId?: string;
6
+ startSegmentName?: string;
7
+ startGeofenceId?: string;
8
+ startGeofenceName?: string;
9
+ destinationFeatureId?: string;
10
+ destinationName?: string;
11
+ destinationLngLat: [number, number];
12
+ destinationLevel: number;
13
+ foundPath: boolean;
14
+ optionAvoidBarrier: boolean;
15
+ optionAvoidElevators: boolean;
16
+ optionAvoidEscalators: boolean;
17
+ optionAvoidNarrowPaths: boolean;
18
+ optionAvoidRamps: boolean;
19
+ optionAvoidStaircases: boolean;
20
+ optionAvoidTicketGates: boolean;
21
+ route: [number, number, number][];
22
+ rerouted?: boolean;
23
+ constructor(data: any);
24
+ save(): Promise<void>;
25
+ }
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ var common_1 = require("../../common");
55
+ var base_1 = require("./base");
56
+ var WayfindingLogger = /** @class */ (function (_super) {
57
+ __extends(WayfindingLogger, _super);
58
+ function WayfindingLogger(data) {
59
+ var _this = _super.call(this, data) || this;
60
+ _this.startLngLat = data.startLngLat;
61
+ _this.startLevel = data.startLevel;
62
+ _this.startSegmentId = data.startSegmentId;
63
+ _this.startSegmentName = data.startSegmentName;
64
+ _this.startGeofenceId = data.startGeofenceId;
65
+ _this.startGeofenceName = data.startGeofenceName;
66
+ _this.destinationFeatureId = data.destinationFeatureId;
67
+ _this.destinationName = data.destinationName;
68
+ _this.destinationLngLat = data.destinationLngLat;
69
+ _this.destinationLevel = data.destinationLevel;
70
+ _this.foundPath = data.foundPath;
71
+ _this.optionAvoidBarrier = data.optionAvoidBarrier;
72
+ _this.optionAvoidElevators = data.optionAvoidElevators;
73
+ _this.optionAvoidEscalators = data.optionAvoidEscalators;
74
+ _this.optionAvoidNarrowPaths = data.optionAvoidNarrowPaths;
75
+ _this.optionAvoidRamps = data.optionAvoidRamps;
76
+ _this.optionAvoidStaircases = data.optionAvoidStaircases;
77
+ _this.optionAvoidTicketGates = data.optionAvoidTicketGates;
78
+ _this.route = data.route;
79
+ _this.rerouted = data.rerouted;
80
+ return _this;
81
+ }
82
+ WayfindingLogger.prototype.save = function () {
83
+ return __awaiter(this, void 0, void 0, function () {
84
+ var e_1;
85
+ return __generator(this, function (_a) {
86
+ switch (_a.label) {
87
+ case 0:
88
+ _a.trys.push([0, 2, , 3]);
89
+ return [4 /*yield*/, common_1.axios.post("v6/geo/wayfinding_logs", [this])];
90
+ case 1:
91
+ _a.sent();
92
+ return [3 /*break*/, 3];
93
+ case 2:
94
+ e_1 = _a.sent();
95
+ console.log("Log saving failed, " + e_1.message);
96
+ return [3 /*break*/, 3];
97
+ case 3: return [2 /*return*/];
98
+ }
99
+ });
100
+ });
101
+ };
102
+ return WayfindingLogger;
103
+ }(base_1.default));
104
+ exports.default = WayfindingLogger;
@@ -25,6 +25,7 @@ interface State {
25
25
  readonly noPlaces: boolean;
26
26
  readonly textNavigation: any;
27
27
  readonly persons: PersonModel[];
28
+ readonly user: any;
28
29
  }
29
30
  interface Options {
30
31
  selector?: string;
@@ -55,6 +55,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
55
55
  exports.Map = exports.globalState = void 0;
56
56
  var mapboxgl = require("mapbox-gl");
57
57
  var repository_1 = require("../../controllers/repository");
58
+ var auth_1 = require("../../controllers/auth");
58
59
  var place_1 = require("../../models/place");
59
60
  var floor_1 = require("../../models/floor");
60
61
  var style_1 = require("../../models/style");
@@ -78,6 +79,7 @@ var constants_1 = require("./constants");
78
79
  var custom_layers_1 = require("./custom-layers");
79
80
  var person_1 = require("../../models/person");
80
81
  var helpers_1 = require("@turf/helpers");
82
+ var wayfinding_1 = require("../logger/wayfinding");
81
83
  exports.globalState = {
82
84
  initializing: true,
83
85
  floor: new floor_1.FloorModel({}),
@@ -96,6 +98,7 @@ exports.globalState = {
96
98
  noPlaces: false,
97
99
  textNavigation: null,
98
100
  persons: [],
101
+ user: null,
99
102
  };
100
103
  var Map = /** @class */ (function () {
101
104
  function Map(options) {
@@ -192,13 +195,16 @@ var Map = /** @class */ (function () {
192
195
  Map.prototype.fetch = function () {
193
196
  var _a, _b, _c;
194
197
  return __awaiter(this, void 0, void 0, function () {
195
- var _d, places, style, styles, features, amenities, defaultPlace, place, center;
198
+ var _d, places, style, styles, features, amenities, user, defaultPlace, place, center;
196
199
  var _this = this;
197
200
  return __generator(this, function (_e) {
198
201
  switch (_e.label) {
199
202
  case 0: return [4 /*yield*/, repository_1.default.getPackage(this.defaultOptions.initPolygons)];
200
203
  case 1:
201
204
  _d = _e.sent(), places = _d.places, style = _d.style, styles = _d.styles, features = _d.features, amenities = _d.amenities;
205
+ return [4 /*yield*/, auth_1.default.getCurrentUser()];
206
+ case 2:
207
+ user = _e.sent();
202
208
  defaultPlace = places.find(function (p) { return p.id === _this.defaultOptions.defaultPlaceId; });
203
209
  place = places.length > 0 ? (defaultPlace ? defaultPlace : places[0]) : new place_1.PlaceModel({});
204
210
  center = ((_a = this.defaultOptions.mapboxOptions) === null || _a === void 0 ? void 0 : _a.center)
@@ -217,7 +223,7 @@ var Map = /** @class */ (function () {
217
223
  this.imageSourceManager.enabled = this.defaultOptions.showRasterFloorplans;
218
224
  this.imageSourceManager.belowLayer = style.usesPrefixes() ? 'proximiio-floors' : 'floors';
219
225
  this.imageSourceManager.initialize();
220
- this.state = __assign(__assign({}, this.state), { initializing: false, place: place, places: places, style: style, styles: styles, amenities: amenities, features: features, allFeatures: new feature_1.FeatureCollection(features), latitude: center[1], longitude: center[0], zoom: this.defaultOptions.zoomLevel ? this.defaultOptions.zoomLevel : (_c = this.defaultOptions.mapboxOptions) === null || _c === void 0 ? void 0 : _c.zoom, noPlaces: places.length === 0 });
226
+ this.state = __assign(__assign({}, this.state), { initializing: false, place: place, places: places, style: style, styles: styles, amenities: amenities, features: features, allFeatures: new feature_1.FeatureCollection(features), latitude: center[1], longitude: center[0], zoom: this.defaultOptions.zoomLevel ? this.defaultOptions.zoomLevel : (_c = this.defaultOptions.mapboxOptions) === null || _c === void 0 ? void 0 : _c.zoom, noPlaces: places.length === 0, user: user });
221
227
  style.on(this.onStyleChange);
222
228
  this.map = new mapboxgl.Map(__assign(__assign({}, this.defaultOptions.mapboxOptions), { container: this.defaultOptions.selector ? this.defaultOptions.selector : 'map' }));
223
229
  this.map.setStyle(this.state.style);
@@ -1077,41 +1083,79 @@ var Map = /** @class */ (function () {
1077
1083
  style.setLevel(0);
1078
1084
  };
1079
1085
  Map.prototype.onRouteChange = function (event) {
1080
- if (event === 'loading-start') {
1081
- this.state = __assign(__assign({}, this.state), { loadingRoute: true });
1082
- return;
1083
- }
1084
- if (event === 'loading-finished') {
1085
- if (this.routingSource.route) {
1086
- var routeStart = this.routingSource.lines[0];
1087
- var textNavigation = this.routeFactory.generateRoute(JSON.stringify(this.routingSource.points), JSON.stringify(this.endPoint));
1088
- this.state = __assign(__assign({}, this.state), { loadingRoute: false, textNavigation: textNavigation });
1089
- if (this.defaultOptions.showLevelDirectionIcon) {
1090
- this.addDirectionFeatures();
1091
- }
1092
- if (this.defaultOptions.animatedRoute) {
1093
- this.addAnimatedRouteFeatures();
1086
+ return __awaiter(this, void 0, void 0, function () {
1087
+ var routeStart, textNavigation, logger, style;
1088
+ return __generator(this, function (_a) {
1089
+ switch (_a.label) {
1090
+ case 0:
1091
+ if (event === 'loading-start') {
1092
+ this.state = __assign(__assign({}, this.state), { loadingRoute: true });
1093
+ return [2 /*return*/];
1094
+ }
1095
+ if (!(event === 'loading-finished')) return [3 /*break*/, 3];
1096
+ if (!this.routingSource.route) return [3 /*break*/, 2];
1097
+ routeStart = this.routingSource.lines[0];
1098
+ textNavigation = this.routeFactory.generateRoute(JSON.stringify(this.routingSource.points), JSON.stringify(this.endPoint));
1099
+ this.state = __assign(__assign({}, this.state), { loadingRoute: false, textNavigation: textNavigation });
1100
+ if (this.defaultOptions.showLevelDirectionIcon) {
1101
+ this.addDirectionFeatures();
1102
+ }
1103
+ if (this.defaultOptions.animatedRoute) {
1104
+ this.addAnimatedRouteFeatures();
1105
+ }
1106
+ this.centerOnRoute(routeStart);
1107
+ this.onRouteFoundListener.next({
1108
+ route: this.routingSource.route,
1109
+ TBTNav: this.defaultOptions.enableTBTNavigation ? textNavigation : null,
1110
+ start: this.startPoint,
1111
+ end: this.endPoint,
1112
+ });
1113
+ logger = new wayfinding_1.default({
1114
+ organization_id: this.state.user.organization.id,
1115
+ organization_name: this.state.user.organization.name,
1116
+ startLngLat: this.routingSource.start.geometry.coordinates,
1117
+ startLevel: this.routingSource.start.properties.level,
1118
+ startSegmentId: this.routingSource.start.id,
1119
+ startSegmentName: this.defaultOptions.isKiosk ? 'kioskPoint' : this.routingSource.start.properties.title,
1120
+ destinationFeatureId: this.routingSource.finish.id,
1121
+ destinationName: this.routingSource.finish.properties.title,
1122
+ destinationLngLat: this.routingSource.finish.geometry.coordinates,
1123
+ destinationLevel: this.routingSource.finish.properties.level,
1124
+ foundPath: this.routingSource.lines.length > 0,
1125
+ optionAvoidBarrier: this.routingSource.routing.wayfinding.configuration.avoidBarriers,
1126
+ optionAvoidElevators: this.routingSource.routing.wayfinding.configuration.avoidElevators,
1127
+ optionAvoidEscalators: this.routingSource.routing.wayfinding.configuration.avoidEscalators,
1128
+ optionAvoidNarrowPaths: this.routingSource.routing.wayfinding.configuration.avoidNarrowPaths,
1129
+ optionAvoidRamps: this.routingSource.routing.wayfinding.configuration.avoidRamps,
1130
+ optionAvoidStaircases: this.routingSource.routing.wayfinding.configuration.avoidStaircases,
1131
+ optionAvoidTicketGates: this.routingSource.routing.wayfinding.configuration.avoidTicketGates,
1132
+ route: this.routingSource.points.map(function (p) { return [
1133
+ p.geometry.coordinates[0],
1134
+ p.geometry.coordinates[1],
1135
+ p.properties.level,
1136
+ ]; }),
1137
+ rerouted: false,
1138
+ });
1139
+ return [4 /*yield*/, logger.save()];
1140
+ case 1:
1141
+ _a.sent();
1142
+ _a.label = 2;
1143
+ case 2: return [2 /*return*/];
1144
+ case 3:
1145
+ if (event === 'route-undefined') {
1146
+ console.log('route not found');
1147
+ this.state = __assign(__assign({}, this.state), { loadingRoute: false });
1148
+ this.onRouteFailedListener.next('route not found');
1149
+ return [2 /*return*/];
1150
+ }
1151
+ style = this.state.style;
1152
+ style.setSource('route', this.routingSource);
1153
+ this.state = __assign(__assign({}, this.state), { style: style });
1154
+ this.updateMapSource(this.routingSource);
1155
+ return [2 /*return*/];
1094
1156
  }
1095
- this.centerOnRoute(routeStart);
1096
- this.onRouteFoundListener.next({
1097
- route: this.routingSource.route,
1098
- TBTNav: this.defaultOptions.enableTBTNavigation ? textNavigation : null,
1099
- start: this.startPoint,
1100
- end: this.endPoint,
1101
- });
1102
- }
1103
- return;
1104
- }
1105
- if (event === 'route-undefined') {
1106
- console.log('route not found');
1107
- this.state = __assign(__assign({}, this.state), { loadingRoute: false });
1108
- this.onRouteFailedListener.next('route not found');
1109
- return;
1110
- }
1111
- var style = this.state.style;
1112
- style.setSource('route', this.routingSource);
1113
- this.state = __assign(__assign({}, this.state), { style: style });
1114
- this.updateMapSource(this.routingSource);
1157
+ });
1158
+ });
1115
1159
  };
1116
1160
  Map.prototype.onSourceChange = function () {
1117
1161
  this.state = __assign(__assign({}, this.state), { style: this.state.style });
@@ -40,9 +40,11 @@ export declare const loginWithToken: (token: string) => Promise<import("axios").
40
40
  * })
41
41
  */
42
42
  export declare const getUserConfig: () => Promise<any>;
43
+ export declare const getCurrentUser: () => Promise<any>;
43
44
  declare const _default: {
44
45
  login: (email: string, password: string) => Promise<import("axios").AxiosResponse<any>>;
45
46
  loginWithToken: (token: string) => Promise<import("axios").AxiosResponse<any>>;
46
47
  getUserConfig: () => Promise<any>;
48
+ getCurrentUser: () => Promise<any>;
47
49
  };
48
50
  export default _default;
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.getUserConfig = exports.loginWithToken = exports.login = void 0;
39
+ exports.getCurrentUser = exports.getUserConfig = exports.loginWithToken = exports.login = void 0;
40
40
  var common_1 = require("../common");
41
41
  /**
42
42
  * @memberof Auth
@@ -149,8 +149,27 @@ var getUserConfig = function () { return __awaiter(void 0, void 0, void 0, funct
149
149
  });
150
150
  }); };
151
151
  exports.getUserConfig = getUserConfig;
152
+ var getCurrentUser = function () { return __awaiter(void 0, void 0, void 0, function () {
153
+ var currentUser, e_4;
154
+ return __generator(this, function (_a) {
155
+ switch (_a.label) {
156
+ case 0:
157
+ _a.trys.push([0, 2, , 3]);
158
+ return [4 /*yield*/, common_1.axios.get("core/current_user")];
159
+ case 1:
160
+ currentUser = _a.sent();
161
+ return [2 /*return*/, currentUser.data];
162
+ case 2:
163
+ e_4 = _a.sent();
164
+ throw new Error("Fetching current user failed, " + e_4.message);
165
+ case 3: return [2 /*return*/];
166
+ }
167
+ });
168
+ }); };
169
+ exports.getCurrentUser = getCurrentUser;
152
170
  exports.default = {
153
171
  login: exports.login,
154
172
  loginWithToken: exports.loginWithToken,
155
173
  getUserConfig: exports.getUserConfig,
174
+ getCurrentUser: exports.getCurrentUser,
156
175
  };
package/lib/index.d.ts CHANGED
@@ -5,6 +5,7 @@ declare const _default: {
5
5
  login: (email: string, password: string) => Promise<import("axios").AxiosResponse<any>>;
6
6
  loginWithToken: (token: string) => Promise<import("axios").AxiosResponse<any>>;
7
7
  getUserConfig: () => Promise<any>;
8
+ getCurrentUser: () => Promise<any>;
8
9
  };
9
10
  Places: {
10
11
  getPlaces: (limit?: number, skip?: number, order?: string, dir?: string, filterByIndex?: string, q?: string, filter?: string) => Promise<{