visitor-segments
Version:
Hellobar Segments.
94 lines (93 loc) • 6.36 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _GeoLocation_city, _GeoLocation_region, _GeoLocation_country, _GeoLocation_adapter, _GeoLocation_countryName, _GeoLocation_mobileCell, _GeoLocation_regionName, _GeoLocation_timezone;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GeoLocation = void 0;
const segmentMaps_1 = require("./segmentMaps");
const interfaces_1 = require("./lib/interfaces");
class GeoLocation {
constructor(segments, adapter) {
_GeoLocation_city.set(this, void 0);
_GeoLocation_region.set(this, void 0);
_GeoLocation_country.set(this, void 0);
_GeoLocation_adapter.set(this, void 0);
_GeoLocation_countryName.set(this, void 0);
_GeoLocation_mobileCell.set(this, void 0);
_GeoLocation_regionName.set(this, void 0);
_GeoLocation_timezone.set(this, void 0);
__classPrivateFieldSet(this, _GeoLocation_city, segments.getSegmentByKey(segmentMaps_1.SEGMENT_KEYS.CITY), "f");
__classPrivateFieldSet(this, _GeoLocation_region, segments.getSegmentByKey(segmentMaps_1.SEGMENT_KEYS.REGION), "f");
__classPrivateFieldSet(this, _GeoLocation_country, segments.getSegmentByKey(segmentMaps_1.SEGMENT_KEYS.COUNTRY), "f");
__classPrivateFieldSet(this, _GeoLocation_countryName, segments.getSegmentByKey(segmentMaps_1.SEGMENT_KEYS.COUNTRY_NAME), "f");
__classPrivateFieldSet(this, _GeoLocation_mobileCell, segments.getSegmentByKey(segmentMaps_1.SEGMENT_KEYS.MOBILE_CELL), "f");
__classPrivateFieldSet(this, _GeoLocation_regionName, segments.getSegmentByKey(segmentMaps_1.SEGMENT_KEYS.REGION_NAME), "f");
__classPrivateFieldSet(this, _GeoLocation_timezone, segments.getSegmentByKey(segmentMaps_1.SEGMENT_KEYS.TIMEZONE), "f");
__classPrivateFieldSet(this, _GeoLocation_adapter, adapter, "f");
}
get city() {
return __classPrivateFieldGet(this, _GeoLocation_city, "f").value;
}
get region() {
return __classPrivateFieldGet(this, _GeoLocation_region, "f").value;
}
get country() {
return __classPrivateFieldGet(this, _GeoLocation_country, "f").value;
}
get countryName() {
return __classPrivateFieldGet(this, _GeoLocation_countryName, "f").value;
}
get regionName() {
return __classPrivateFieldGet(this, _GeoLocation_regionName, "f").value;
}
get timezone() {
return __classPrivateFieldGet(this, _GeoLocation_timezone, "f").value;
}
get mobileCell() {
return __classPrivateFieldGet(this, _GeoLocation_mobileCell, "f").value;
}
update(override) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const info = override || (yield __classPrivateFieldGet(this, _GeoLocation_adapter, "f").getLocationInfo());
if (info.status === interfaces_1.GEO_INFO_STATUSES.success) {
__classPrivateFieldGet(this, _GeoLocation_city, "f").setValue((_a = info.city) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase());
__classPrivateFieldGet(this, _GeoLocation_region, "f").setValue(info.region);
__classPrivateFieldGet(this, _GeoLocation_regionName, "f").setValue((_b = info.regionName) === null || _b === void 0 ? void 0 : _b.toLocaleLowerCase());
__classPrivateFieldGet(this, _GeoLocation_country, "f").setValue(info.countryCode);
__classPrivateFieldGet(this, _GeoLocation_countryName, "f").setValue(info.country);
__classPrivateFieldGet(this, _GeoLocation_timezone, "f").setValue(info.timezone);
__classPrivateFieldGet(this, _GeoLocation_mobileCell, "f").setValue(info.mobile);
}
});
}
reset() {
__classPrivateFieldGet(this, _GeoLocation_city, "f").reset();
__classPrivateFieldGet(this, _GeoLocation_region, "f").reset();
__classPrivateFieldGet(this, _GeoLocation_regionName, "f").reset();
__classPrivateFieldGet(this, _GeoLocation_country, "f").reset();
__classPrivateFieldGet(this, _GeoLocation_countryName, "f").reset();
__classPrivateFieldGet(this, _GeoLocation_mobileCell, "f").reset();
__classPrivateFieldGet(this, _GeoLocation_timezone, "f").reset();
}
}
exports.GeoLocation = GeoLocation;
_GeoLocation_city = new WeakMap(), _GeoLocation_region = new WeakMap(), _GeoLocation_country = new WeakMap(), _GeoLocation_adapter = new WeakMap(), _GeoLocation_countryName = new WeakMap(), _GeoLocation_mobileCell = new WeakMap(), _GeoLocation_regionName = new WeakMap(), _GeoLocation_timezone = new WeakMap();