UNPKG

2.75 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright (c) Microsoft Corporation. All rights reserved.
4 * Licensed under the MIT License.
5 */
6Object.defineProperty(exports, "__esModule", { value: true });
7exports.startBrowserPerformanceMeasurement = exports.endBrowserPerformanceMeasurement = exports.supportsBrowserPerformance = exports.prependEventNamePrefix = exports.hashPersonalIdentifier = exports.scrubTenantFromUri = void 0;
8var TelemetryConstants_1 = require("./TelemetryConstants");
9var CryptoUtils_1 = require("../utils/CryptoUtils");
10var UrlUtils_1 = require("../utils/UrlUtils");
11var Authority_1 = require("../authority/Authority");
12exports.scrubTenantFromUri = function (uri) {
13 var url = UrlUtils_1.UrlUtils.GetUrlComponents(uri);
14 // validate trusted host
15 if (Authority_1.Authority.isAdfs(uri)) {
16 /**
17 * returning what was passed because the library needs to work with uris that are non
18 * AAD trusted but passed by users such as B2C or others.
19 * HTTP Events for instance can take a url to the open id config endpoint
20 */
21 return uri;
22 }
23 var pathParams = url.PathSegments;
24 if (pathParams && pathParams.length >= 2) {
25 var tenantPosition = pathParams[1] === "tfp" ? 2 : 1;
26 if (tenantPosition < pathParams.length) {
27 pathParams[tenantPosition] = TelemetryConstants_1.TENANT_PLACEHOLDER;
28 }
29 }
30 return url.Protocol + "//" + url.HostNameAndPort + "/" + pathParams.join("/");
31};
32exports.hashPersonalIdentifier = function (valueToHash) {
33 /*
34 * TODO sha256 this
35 * Current test runner is being funny with node libs that are webpacked anyway
36 * need a different solution
37 */
38 return CryptoUtils_1.CryptoUtils.base64Encode(valueToHash);
39};
40exports.prependEventNamePrefix = function (suffix) { return "" + TelemetryConstants_1.EVENT_NAME_PREFIX + (suffix || ""); };
41exports.supportsBrowserPerformance = function () { return !!(typeof window !== "undefined" &&
42 "performance" in window &&
43 window.performance.mark &&
44 window.performance.measure); };
45exports.endBrowserPerformanceMeasurement = function (measureName, startMark, endMark) {
46 if (exports.supportsBrowserPerformance()) {
47 window.performance.mark(endMark);
48 window.performance.measure(measureName, startMark, endMark);
49 window.performance.clearMeasures(measureName);
50 window.performance.clearMarks(startMark);
51 window.performance.clearMarks(endMark);
52 }
53};
54exports.startBrowserPerformanceMeasurement = function (startMark) {
55 if (exports.supportsBrowserPerformance()) {
56 window.performance.mark(startMark);
57 }
58};
59//# sourceMappingURL=TelemetryUtils.js.map
\No newline at end of file