Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e1a71fb
Initial plan for issue
Copilot May 20, 2025
d1ffffc
Fix Safari SecurityError when Block All Cookies is set
Copilot May 20, 2025
c13a592
Fix PR comments on StorageHelperFuncs.ts
Copilot May 20, 2025
16f3b92
Remove newline changes from interface files per PR feedback
Copilot May 21, 2025
a488d75
Refactor storage helper functions to use single return statements per…
Copilot May 21, 2025
fd68d94
Remove generated JS files from PR per feedback
Copilot May 21, 2025
831c9b4
Remove RequestResponseHeaders.ts from PR per reviewer feedback
Copilot May 21, 2025
d472d65
Pass resolved string to _canSafelyAccessStorage per PR feedback
Copilot May 21, 2025
d2cd04d
Merge _canSafelyAccessStorage function into _getVerifiedStorageObject
Copilot May 21, 2025
93c0f44
Simplify storage access code with default-false approach
Copilot May 22, 2025
d4677e0
Merge branch 'main' into copilot/fix-2494
MSNev May 22, 2025
cdf088a
Remove unnecessary nested try-catch for direct storage access
Copilot May 22, 2025
22169a2
Merge branch 'main' into copilot/fix-2494
MSNev May 23, 2025
cee30cd
Add caching to storage verification to reduce test item creation
Copilot May 23, 2025
9e5c985
Update storage caching to use createCachedValue instead of reset
Copilot May 23, 2025
d0ee829
Remove _canUseLocalStorage and _canUseSessionStorage flags, add stora…
Copilot May 23, 2025
2274771
Don't reset cached storage on getItem and read operations
Copilot May 24, 2025
59362d4
Simplify storage wrapper and remove redundant code
Copilot May 24, 2025
b9789af
Use existing helper functions in utlCanUseLocalStorage/SessionStorage
Copilot May 24, 2025
e775471
Refactor storage helper functions to reduce code duplication and fix …
Copilot May 24, 2025
d25a325
Merge branch 'main' into copilot/fix-2494
MSNev May 27, 2025
7e32aa3
Address PR comments for StorageHelperFuncs.ts
Copilot May 27, 2025
ec81543
Refactor storage functions per PR feedback
Copilot May 28, 2025
23f5e50
Refactor utlCanUseLocalStorage and utlCanUseSessionStorage to include…
Copilot May 28, 2025
98c0e2c
Revert utility functions to original form while keeping _throwInterna…
Copilot May 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions shared/AppInsightsCommon/src/ConnectionStringParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"use strict";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all of these new "generated" *.js files, the project uses TypeScript and we don't check in the *.js files except for specific tools

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed all the generated JavaScript files from the PR in commit fd68d94. The project will now only include the TypeScript source files as intended.

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConnectionStringParser = void 0;
exports.parseConnectionString = parseConnectionString;
var applicationinsights_core_js_1 = require("@microsoft/applicationinsights-core-js");
var Constants_1 = require("./Constants");
var _FIELDS_SEPARATOR = ";";
var _FIELD_KEY_VALUE_SEPARATOR = "=";
function parseConnectionString(connectionString) {
if (!connectionString) {
return {};
}
var kvPairs = connectionString.split(_FIELDS_SEPARATOR);
var result = (0, applicationinsights_core_js_1.arrReduce)(kvPairs, function (fields, kv) {
var kvParts = kv.split(_FIELD_KEY_VALUE_SEPARATOR);
if (kvParts.length === 2) { // only save fields with valid formats
var key = kvParts[0].toLowerCase();
var value = kvParts[1];
fields[key] = value;
}
return fields;
}, {});
if ((0, applicationinsights_core_js_1.objKeys)(result).length > 0) {
// this is a valid connection string, so parse the results
if (result.endpointsuffix) {
// apply the default endpoints
var locationPrefix = result.location ? result.location + "." : "";
result.ingestionendpoint = result.ingestionendpoint || ("https://" + locationPrefix + "dc." + result.endpointsuffix);
}
// apply user override endpoint or the default endpoints
result.ingestionendpoint = result.ingestionendpoint || Constants_1.DEFAULT_BREEZE_ENDPOINT;
if ((0, applicationinsights_core_js_1.strEndsWith)(result.ingestionendpoint, "/")) {
result.ingestionendpoint = result.ingestionendpoint.slice(0, -1);
}
}
return result;
}
exports.ConnectionStringParser = {
parse: parseConnectionString
};
20 changes: 20 additions & 0 deletions shared/AppInsightsCommon/src/Constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.strIkey = exports.strNotSpecified = exports.DEFAULT_BREEZE_PATH = exports.DEFAULT_BREEZE_ENDPOINT = exports.HttpMethod = exports.ProcessLegacy = exports.SampleRate = exports.DisabledPropertyName = void 0;
/**
* This is an internal property used to cause internal (reporting) requests to be ignored from reporting
* additional telemetry, to handle polyfil implementations ALL urls used with a disabled request will
* also be ignored for future requests even when this property is not provided.
* Tagging as Ignore as this is an internal value and is not expected to be used outside of the SDK
* @ignore
*/
exports.DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
exports.SampleRate = "sampleRate";
exports.ProcessLegacy = "ProcessLegacy";
exports.HttpMethod = "http.method";
exports.DEFAULT_BREEZE_ENDPOINT = "https://dc.services.visualstudio.com";
exports.DEFAULT_BREEZE_PATH = "/v2/track";
exports.strNotSpecified = "not_specified";
exports.strIkey = "iKey";
20 changes: 20 additions & 0 deletions shared/AppInsightsCommon/src/DomHelperFuncs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createDomEvent = createDomEvent;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
var applicationinsights_core_js_1 = require("@microsoft/applicationinsights-core-js");
function createDomEvent(eventName) {
var event = null;
if ((0, applicationinsights_core_js_1.isFunction)(Event)) { // Use Event constructor when available
event = new Event(eventName);
}
else { // Event has no constructor in IE
var doc = (0, applicationinsights_core_js_1.getDocument)();
if (doc && doc.createEvent) {
event = doc.createEvent("Event");
event.initEvent(eventName, true, true);
}
}
return event;
}
28 changes: 28 additions & 0 deletions shared/AppInsightsCommon/src/Enums.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventPersistence = exports.DistributedTracingModes = exports.StorageType = void 0;
var applicationinsights_core_js_1 = require("@microsoft/applicationinsights-core-js");
exports.StorageType = (0, applicationinsights_core_js_1.createEnumStyle)({
LocalStorage: 0 /* eStorageType.LocalStorage */,
SessionStorage: 1 /* eStorageType.SessionStorage */
});
exports.DistributedTracingModes = (0, applicationinsights_core_js_1.createEnumStyle)({
AI: 0 /* eDistributedTracingModes.AI */,
AI_AND_W3C: 1 /* eDistributedTracingModes.AI_AND_W3C */,
W3C: 2 /* eDistributedTracingModes.W3C */
});
/**
* The EventPersistence contains a set of values that specify the event's persistence.
*/
exports.EventPersistence = (0, applicationinsights_core_js_1.createEnumStyle)({
/**
* Normal persistence.
*/
Normal: 1 /* EventPersistenceValue.Normal */,
/**
* Critical persistence.
*/
Critical: 2 /* EventPersistenceValue.Critical */
});
50 changes: 50 additions & 0 deletions shared/AppInsightsCommon/src/HelperFuncs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringToBoolOrDefault = stringToBoolOrDefault;
exports.msToTimeSpan = msToTimeSpan;
exports.getExtensionByName = getExtensionByName;
exports.isCrossOriginError = isCrossOriginError;
var applicationinsights_core_js_1 = require("@microsoft/applicationinsights-core-js");
var ts_utils_1 = require("@nevware21/ts-utils");
var strEmpty = "";
function stringToBoolOrDefault(str, defaultValue) {
if (defaultValue === void 0) { defaultValue = false; }
if (str === undefined || str === null) {
return defaultValue;
}
return str.toString().toLowerCase() === "true";
}
/**
* Convert ms to c# time span format
*/
function msToTimeSpan(totalms) {
if (isNaN(totalms) || totalms < 0) {
totalms = 0;
}
totalms = (0, ts_utils_1.mathRound)(totalms);
var ms = strEmpty + totalms % 1000;
var sec = strEmpty + (0, ts_utils_1.mathFloor)(totalms / 1000) % 60;
var min = strEmpty + (0, ts_utils_1.mathFloor)(totalms / (1000 * 60)) % 60;
var hour = strEmpty + (0, ts_utils_1.mathFloor)(totalms / (1000 * 60 * 60)) % 24;
var days = (0, ts_utils_1.mathFloor)(totalms / (1000 * 60 * 60 * 24));
ms = ms.length === 1 ? "00" + ms : ms.length === 2 ? "0" + ms : ms;
sec = sec.length < 2 ? "0" + sec : sec;
min = min.length < 2 ? "0" + min : min;
hour = hour.length < 2 ? "0" + hour : hour;
return (days > 0 ? days + "." : strEmpty) + hour + ":" + min + ":" + sec + "." + ms;
}
function getExtensionByName(extensions, identifier) {
var extension = null;
(0, applicationinsights_core_js_1.arrForEach)(extensions, function (value) {
if (value.identifier === identifier) {
extension = value;
return -1;
}
});
return extension;
}
function isCrossOriginError(message, url, lineNumber, columnNumber, error) {
return !error && (0, applicationinsights_core_js_1.isString)(message) && (message === "Script error." || message === "Script error");
}
2 changes: 2 additions & 0 deletions shared/AppInsightsCommon/src/Interfaces/ConnectionString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
4 changes: 4 additions & 0 deletions shared/AppInsightsCommon/src/Interfaces/Context/IDevice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
4 changes: 4 additions & 0 deletions shared/AppInsightsCommon/src/Interfaces/Context/IInternal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
4 changes: 4 additions & 0 deletions shared/AppInsightsCommon/src/Interfaces/Context/ILocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
4 changes: 4 additions & 0 deletions shared/AppInsightsCommon/src/Interfaces/Context/ISample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
4 changes: 4 additions & 0 deletions shared/AppInsightsCommon/src/Interfaces/Context/ISession.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
4 changes: 4 additions & 0 deletions shared/AppInsightsCommon/src/Interfaces/Context/IUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
4 changes: 4 additions & 0 deletions shared/AppInsightsCommon/src/Interfaces/Context/IWeb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"use strict";
// // Copyright (c) Microsoft Corporation. All rights reserved.
// // Licensed under the MIT License.
// // THIS FILE WAS AUTOGENERATED
// import { Domain } from "./Domain";
// "use strict";
// /**
// * Instances of AvailabilityData represent the result of executing an availability test.
// */
// export class AvailabilityData implements Domain {
// /**
// * Schema version
// */
// public ver: number = 2;
// /**
// * Identifier of a test run. Use it to correlate steps of test run and telemetry generated by the service.
// */
// public id: string;
// /**
// * Name of the test that these availability results represent.
// */
// public name: string;
// /**
// * Duration in format: DD.HH:MM:SS.MMMMMM. Must be less than 1000 days.
// */
// public duration: string;
// /**
// * Success flag.
// */
// public success: boolean;
// /**
// * Name of the location where the test was run from.
// */
// public runLocation: string;
// /**
// * Diagnostic message for the result.
// */
// public message: string;
// /**
// * Collection of custom properties.
// */
// public properties: any = {};
// /**
// * Collection of custom measurements.
// */
// public measurements: any = {};
// }
101 changes: 101 additions & 0 deletions shared/AppInsightsCommon/src/Interfaces/Contracts/ContextTagKeys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContextTagKeys = void 0;
var applicationinsights_core_js_1 = require("@microsoft/applicationinsights-core-js");
function _aiNameFunc(baseName) {
var aiName = "ai." + baseName + ".";
return function (name) {
return aiName + name;
};
}
var _aiApplication = _aiNameFunc("application");
var _aiDevice = _aiNameFunc("device");
var _aiLocation = _aiNameFunc("location");
var _aiOperation = _aiNameFunc("operation");
var _aiSession = _aiNameFunc("session");
var _aiUser = _aiNameFunc("user");
var _aiCloud = _aiNameFunc("cloud");
var _aiInternal = _aiNameFunc("internal");
var ContextTagKeys = /** @class */ (function (_super) {
__extends(ContextTagKeys, _super);
function ContextTagKeys() {
return _super.call(this) || this;
}
return ContextTagKeys;
}((0, applicationinsights_core_js_1.createClassFromInterface)({
applicationVersion: _aiApplication("ver"),
applicationBuild: _aiApplication("build"),
applicationTypeId: _aiApplication("typeId"),
applicationId: _aiApplication("applicationId"),
applicationLayer: _aiApplication("layer"),
deviceId: _aiDevice("id"),
deviceIp: _aiDevice("ip"),
deviceLanguage: _aiDevice("language"),
deviceLocale: _aiDevice("locale"),
deviceModel: _aiDevice("model"),
deviceFriendlyName: _aiDevice("friendlyName"),
deviceNetwork: _aiDevice("network"),
deviceNetworkName: _aiDevice("networkName"),
deviceOEMName: _aiDevice("oemName"),
deviceOS: _aiDevice("os"),
deviceOSVersion: _aiDevice("osVersion"),
deviceRoleInstance: _aiDevice("roleInstance"),
deviceRoleName: _aiDevice("roleName"),
deviceScreenResolution: _aiDevice("screenResolution"),
deviceType: _aiDevice("type"),
deviceMachineName: _aiDevice("machineName"),
deviceVMName: _aiDevice("vmName"),
deviceBrowser: _aiDevice("browser"),
deviceBrowserVersion: _aiDevice("browserVersion"),
locationIp: _aiLocation("ip"),
locationCountry: _aiLocation("country"),
locationProvince: _aiLocation("province"),
locationCity: _aiLocation("city"),
operationId: _aiOperation("id"),
operationName: _aiOperation("name"),
operationParentId: _aiOperation("parentId"),
operationRootId: _aiOperation("rootId"),
operationSyntheticSource: _aiOperation("syntheticSource"),
operationCorrelationVector: _aiOperation("correlationVector"),
sessionId: _aiSession("id"),
sessionIsFirst: _aiSession("isFirst"),
sessionIsNew: _aiSession("isNew"),
userAccountAcquisitionDate: _aiUser("accountAcquisitionDate"),
userAccountId: _aiUser("accountId"),
userAgent: _aiUser("userAgent"),
userId: _aiUser("id"),
userStoreRegion: _aiUser("storeRegion"),
userAuthUserId: _aiUser("authUserId"),
userAnonymousUserAcquisitionDate: _aiUser("anonUserAcquisitionDate"),
userAuthenticatedUserAcquisitionDate: _aiUser("authUserAcquisitionDate"),
cloudName: _aiCloud("name"),
cloudRole: _aiCloud("role"),
cloudRoleVer: _aiCloud("roleVer"),
cloudRoleInstance: _aiCloud("roleInstance"),
cloudEnvironment: _aiCloud("environment"),
cloudLocation: _aiCloud("location"),
cloudDeploymentUnit: _aiCloud("deploymentUnit"),
internalNodeName: _aiInternal("nodeName"),
internalSdkVersion: _aiInternal("sdkVersion"),
internalAgentVersion: _aiInternal("agentVersion"),
internalSnippet: _aiInternal("snippet"),
internalSdkSrc: _aiInternal("sdkSrc")
})));
exports.ContextTagKeys = ContextTagKeys;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
4 changes: 4 additions & 0 deletions shared/AppInsightsCommon/src/Interfaces/Contracts/IBase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
4 changes: 4 additions & 0 deletions shared/AppInsightsCommon/src/Interfaces/Contracts/IData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
Loading