@microsoft/1ds-core-js 3.2.11 → 4.0.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/README.md +1 -1
- package/bundle/es5/ms.core-4.0.0.gbl.js +6221 -0
- package/bundle/es5/ms.core-4.0.0.gbl.js.map +1 -0
- package/bundle/es5/ms.core-4.0.0.gbl.min.js +7 -0
- package/bundle/es5/ms.core-4.0.0.gbl.min.js.map +1 -0
- package/bundle/es5/ms.core-4.0.0.integrity.json +46 -0
- package/bundle/es5/ms.core-4.0.0.js +6225 -0
- package/bundle/es5/ms.core-4.0.0.js.map +1 -0
- package/bundle/es5/ms.core-4.0.0.min.js +7 -0
- package/bundle/es5/ms.core-4.0.0.min.js.map +1 -0
- package/bundle/es5/ms.core.gbl.js +6221 -0
- package/bundle/es5/ms.core.gbl.js.map +1 -0
- package/bundle/es5/ms.core.gbl.min.js +7 -0
- package/bundle/es5/ms.core.gbl.min.js.map +1 -0
- package/bundle/es5/ms.core.integrity.json +46 -0
- package/bundle/es5/ms.core.js +6225 -0
- package/bundle/es5/ms.core.js.map +1 -0
- package/bundle/es5/ms.core.min.js +7 -0
- package/bundle/es5/ms.core.min.js.map +1 -0
- package/{bundle → dist/es5}/ms.core.js +3790 -2967
- package/dist/es5/ms.core.js.map +1 -0
- package/dist/es5/ms.core.min.js +7 -0
- package/dist/es5/ms.core.min.js.map +1 -0
- package/dist-es5/AppInsightsCore.js +91 -0
- package/dist-es5/AppInsightsCore.js.map +1 -0
- package/{dist-esm/src → dist-es5}/BaseCore.js +18 -11
- package/dist-es5/BaseCore.js.map +1 -0
- package/{dist-esm/src → dist-es5}/DataModels.js +1 -1
- package/{dist-esm/src → dist-es5}/Enums.js +3 -26
- package/dist-es5/Enums.js.map +1 -0
- package/{dist-esm/src → dist-es5}/Index.js +9 -14
- package/dist-es5/Index.js.map +1 -0
- package/{dist-esm/src → dist-es5}/InternalConstants.js +1 -3
- package/{dist-esm/src → dist-es5}/InternalConstants.js.map +1 -1
- package/{dist-esm/src → dist-es5}/Utils.js +19 -144
- package/dist-es5/Utils.js.map +1 -0
- package/{dist-esm/src → dist-es5}/ValueSanitizer.js +39 -3
- package/dist-es5/ValueSanitizer.js.map +1 -0
- package/package.json +16 -9
- package/tsconfig.json +5 -3
- package/types/1ds-core-js.d.ts +1106 -0
- package/types/1ds-core-js.namespaced.d.ts +1102 -0
- package/bundle/ms.core-3.2.11.gbl.js +0 -5378
- package/bundle/ms.core-3.2.11.gbl.js.map +0 -1
- package/bundle/ms.core-3.2.11.gbl.min.js +0 -7
- package/bundle/ms.core-3.2.11.gbl.min.js.map +0 -1
- package/bundle/ms.core-3.2.11.integrity.json +0 -46
- package/bundle/ms.core-3.2.11.js +0 -5381
- package/bundle/ms.core-3.2.11.js.map +0 -1
- package/bundle/ms.core-3.2.11.min.js +0 -7
- package/bundle/ms.core-3.2.11.min.js.map +0 -1
- package/bundle/ms.core.gbl.js +0 -5378
- package/bundle/ms.core.gbl.js.map +0 -1
- package/bundle/ms.core.gbl.min.js +0 -7
- package/bundle/ms.core.gbl.min.js.map +0 -1
- package/bundle/ms.core.integrity.json +0 -46
- package/bundle/ms.core.js.map +0 -1
- package/bundle/ms.core.min.js +0 -7
- package/bundle/ms.core.min.js.map +0 -1
- package/dist/ms.core.js +0 -1305
- package/dist/ms.core.js.map +0 -1
- package/dist/ms.core.min.js +0 -7
- package/dist/ms.core.min.js.map +0 -1
- package/dist-esm/src/AppInsightsCore.d.ts +0 -15
- package/dist-esm/src/AppInsightsCore.js +0 -114
- package/dist-esm/src/AppInsightsCore.js.map +0 -1
- package/dist-esm/src/BaseCore.d.ts +0 -13
- package/dist-esm/src/BaseCore.js.map +0 -1
- package/dist-esm/src/DataModels.d.ts +0 -273
- package/dist-esm/src/ESPromise.d.ts +0 -110
- package/dist-esm/src/ESPromise.js +0 -286
- package/dist-esm/src/ESPromise.js.map +0 -1
- package/dist-esm/src/ESPromiseScheduler.d.ts +0 -36
- package/dist-esm/src/ESPromiseScheduler.js +0 -274
- package/dist-esm/src/ESPromiseScheduler.js.map +0 -1
- package/dist-esm/src/Enums.d.ts +0 -356
- package/dist-esm/src/Enums.js.map +0 -1
- package/dist-esm/src/Index.d.ts +0 -19
- package/dist-esm/src/Index.js.map +0 -1
- package/dist-esm/src/InternalConstants.d.ts +0 -6
- package/dist-esm/src/Utils.d.ts +0 -190
- package/dist-esm/src/Utils.js.map +0 -1
- package/dist-esm/src/ValueSanitizer.d.ts +0 -40
- package/dist-esm/src/ValueSanitizer.js.map +0 -1
- package/src/AppInsightsCore.ts +0 -135
- package/src/BaseCore.ts +0 -72
- package/src/DataModels.ts +0 -297
- package/src/ESPromise.ts +0 -365
- package/src/ESPromiseScheduler.ts +0 -328
- package/src/Enums.ts +0 -386
- package/src/Index.ts +0 -81
- package/src/InternalConstants.ts +0 -16
- package/src/Utils.ts +0 -565
- package/src/ValueSanitizer.ts +0 -285
- /package/{dist-esm/src → dist-es5}/DataModels.js.map +0 -0
package/src/Utils.ts
DELETED
|
@@ -1,565 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utils.ts
|
|
3
|
-
* @author Abhilash Panwar (abpanwar) Hector Hernandez (hectorh)
|
|
4
|
-
* @copyright Microsoft 2018
|
|
5
|
-
* File containing utility functions.
|
|
6
|
-
*/
|
|
7
|
-
import {
|
|
8
|
-
ICookieMgr, ICoreUtils, ITelemetryItem, addEventHandler, addPageUnloadEventListener, areCookiesSupported, arrForEach, arrIndexOf, arrMap,
|
|
9
|
-
arrReduce, dateNow, generateW3CId, getDocument, getGlobalInst, getNavigator, getWindow, hasOwnProperty, isArray, isBeaconsSupported,
|
|
10
|
-
isBoolean, isDate, isError, isFunction, isIE, isNullOrUndefined, isNumber, isObject, isReactNative, isString, isTypeof, isUndefined,
|
|
11
|
-
mwcRandom32, mwcRandomSeed, newGuid, newId, objDefineAccessors, objForEachKey, objKeys, perfNow, random32, randomValue, safeGetCookieMgr,
|
|
12
|
-
strEndsWith, strObject, strTrim, strUndefined, toISOString, uaDisallowsSameSiteNone, useXDomainRequest
|
|
13
|
-
} from "@microsoft/applicationinsights-core-js";
|
|
14
|
-
import { ObjHasOwnProperty, objCreateFn, strShimObject, strShimPrototype } from "@microsoft/applicationinsights-shims";
|
|
15
|
-
import { IEventProperty, IExtendedTelemetryItem } from "./DataModels";
|
|
16
|
-
import { EventLatency, EventLatencyValue, FieldValueSanitizerType, GuidStyle, eEventPropertyType, eValueKind } from "./Enums";
|
|
17
|
-
import { STR_EMPTY } from "./InternalConstants";
|
|
18
|
-
|
|
19
|
-
export const Version = "#version#";
|
|
20
|
-
export const FullVersionString = "1DS-Web-JS-" + Version;
|
|
21
|
-
|
|
22
|
-
// Defining here so we don't need to take (import) the ApplicationInsights Common module
|
|
23
|
-
const strDisabledPropertyName: string = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
|
|
24
|
-
const strWithCredentials: string = "withCredentials";
|
|
25
|
-
const strTimeout: string = "timeout";
|
|
26
|
-
|
|
27
|
-
// If value is array just get the type for the first element
|
|
28
|
-
const _fieldTypeEventPropMap = {
|
|
29
|
-
[FieldValueSanitizerType.NotSet]: eEventPropertyType.Unspecified,
|
|
30
|
-
[FieldValueSanitizerType.Number]: eEventPropertyType.Double,
|
|
31
|
-
[FieldValueSanitizerType.String]: eEventPropertyType.String,
|
|
32
|
-
[FieldValueSanitizerType.Boolean]: eEventPropertyType.Bool,
|
|
33
|
-
[FieldValueSanitizerType.Array | FieldValueSanitizerType.Number]: eEventPropertyType.Double,
|
|
34
|
-
[FieldValueSanitizerType.Array | FieldValueSanitizerType.String]: eEventPropertyType.String,
|
|
35
|
-
[FieldValueSanitizerType.Array | FieldValueSanitizerType.Boolean]: eEventPropertyType.Bool
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @ignore
|
|
40
|
-
*/
|
|
41
|
-
// let _uaDisallowsSameSiteNone = null;
|
|
42
|
-
|
|
43
|
-
var uInt8ArraySupported: boolean | null = null;
|
|
44
|
-
// var _areCookiesAvailable: boolean | undefined;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Checks if document object is available
|
|
48
|
-
*/
|
|
49
|
-
export var isDocumentObjectAvailable: boolean = Boolean(getDocument());
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Checks if window object is available
|
|
53
|
-
*/
|
|
54
|
-
export var isWindowObjectAvailable: boolean = Boolean(getWindow());
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Checks if value is assigned to the given param.
|
|
58
|
-
* @param value - The token from which the tenant id is to be extracted.
|
|
59
|
-
* @returns True/false denoting if value is assigned to the param.
|
|
60
|
-
*/
|
|
61
|
-
export function isValueAssigned(value: any) {
|
|
62
|
-
/// <summary> takes a value and checks for undefined, null and empty string </summary>
|
|
63
|
-
/// <param type="any"> value to be tested </param>
|
|
64
|
-
/// <returns> true if value is null undefined or emptyString </returns>
|
|
65
|
-
return !(value === STR_EMPTY || isNullOrUndefined(value));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Gets the tenant id from the tenant token.
|
|
70
|
-
* @param apiKey - The token from which the tenant id is to be extracted.
|
|
71
|
-
* @returns The tenant id.
|
|
72
|
-
*/
|
|
73
|
-
export function getTenantId(apiKey: string | undefined): string {
|
|
74
|
-
if (apiKey) {
|
|
75
|
-
let indexTenantId = apiKey.indexOf("-");
|
|
76
|
-
if (indexTenantId > -1) {
|
|
77
|
-
return apiKey.substring(0, indexTenantId);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return STR_EMPTY;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Checks if Uint8Array are available in the current environment. Safari and Firefox along with
|
|
85
|
-
* ReactNative are known to not support Uint8Array properly.
|
|
86
|
-
* @returns True if available, false otherwise.
|
|
87
|
-
*/
|
|
88
|
-
export function isUint8ArrayAvailable(): boolean {
|
|
89
|
-
if (uInt8ArraySupported === null) {
|
|
90
|
-
uInt8ArraySupported = !isUndefined(Uint8Array) && !isSafariOrFirefox() && !isReactNative();
|
|
91
|
-
}
|
|
92
|
-
return uInt8ArraySupported;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Checks if the value is a valid EventLatency.
|
|
97
|
-
* @param value - The value that needs to be checked.
|
|
98
|
-
* @returns True if the value is in AWTEventLatency, false otherwise.
|
|
99
|
-
*/
|
|
100
|
-
export function isLatency(value: EventLatency | undefined): boolean {
|
|
101
|
-
if (value && isNumber(value) && value >= EventLatencyValue.Normal && value <= EventLatencyValue.Immediate) {
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Sanitizes the Property. It checks the that the property name and value are valid. It also
|
|
109
|
-
* checks/populates the correct type and pii of the property value.
|
|
110
|
-
* @param name - property name - The property name.
|
|
111
|
-
* @param property - The property value or an IEventProperty containing value,
|
|
112
|
-
* type ,pii and customer content.
|
|
113
|
-
* @returns IEventProperty containing valid name, value, pii and type or null if invalid.
|
|
114
|
-
*/
|
|
115
|
-
export function sanitizeProperty(name: string,
|
|
116
|
-
property: string | number | boolean | string[] | number[] | boolean[] | object | IEventProperty,
|
|
117
|
-
stringifyObjects?: boolean): IEventProperty | null {
|
|
118
|
-
// Check that property is valid
|
|
119
|
-
if ((!property && !isValueAssigned(property)) || typeof name !== "string") {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Perf optimization -- only need to get the type once not multiple times
|
|
124
|
-
let propType = typeof property;
|
|
125
|
-
|
|
126
|
-
// If the property isn't IEventProperty (and is either string, number, boolean or array), convert it into one.
|
|
127
|
-
if (propType === "string" || propType === "number" || propType === "boolean" || isArray(property)) {
|
|
128
|
-
property = ({ value: property } as IEventProperty);
|
|
129
|
-
} else if (propType === "object" && !ObjHasOwnProperty.call(property, "value")) {
|
|
130
|
-
property = ({ value: stringifyObjects ? JSON.stringify(property) : property } as IEventProperty);
|
|
131
|
-
} else if (isNullOrUndefined((property as IEventProperty).value)
|
|
132
|
-
|| (property as IEventProperty).value === STR_EMPTY || (!isString((property as IEventProperty).value)
|
|
133
|
-
&& !isNumber((property as IEventProperty).value) && !isBoolean((property as IEventProperty).value)
|
|
134
|
-
&& !isArray((property as IEventProperty).value))) {
|
|
135
|
-
// Since property is IEventProperty, we need to validate its value
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// We need to check that if the property value is an array, it is valid
|
|
140
|
-
if (isArray((property as IEventProperty).value) &&
|
|
141
|
-
!isArrayValid((property as IEventProperty).value as string[] | number[] | boolean[])) {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// If either pii or cc is set convert value to string (since only string pii/cc is allowed).
|
|
146
|
-
// If the value is a complex type like an array that can't be converted to string we will drop
|
|
147
|
-
// the property.
|
|
148
|
-
if (!isNullOrUndefined((property as IEventProperty).kind)) {
|
|
149
|
-
if (isArray((property as IEventProperty).value) || !isValueKind((property as IEventProperty).kind)) {
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
(property as IEventProperty).value = (property as IEventProperty).value.toString();
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return (property as IEventProperty);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export function getCommonSchemaMetaData(value: string | boolean | number | string[] | number[] | boolean[] | undefined, kind: number | undefined, type?: number | undefined): number {
|
|
160
|
-
let encodedTypeValue = -1;
|
|
161
|
-
|
|
162
|
-
if (!isUndefined(value)) {
|
|
163
|
-
if (kind > 0) {
|
|
164
|
-
if (kind === 32) {
|
|
165
|
-
// encode customer content. Value can only be string. bit 13-16 are for cc
|
|
166
|
-
encodedTypeValue = (1 << 13);
|
|
167
|
-
} else if (kind <= 13) {
|
|
168
|
-
// encode PII. Value can only be string. bits 5-12 are for Pii
|
|
169
|
-
encodedTypeValue = (kind << 5);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// isDataType checks that the "type" is a number so we don't need to check for undefined
|
|
174
|
-
if (isDataType(type)) {
|
|
175
|
-
// Data Type is provided and valid, so use that
|
|
176
|
-
if (encodedTypeValue === -1) {
|
|
177
|
-
// Don't return -1
|
|
178
|
-
encodedTypeValue = 0;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
encodedTypeValue |= type;
|
|
182
|
-
} else {
|
|
183
|
-
let propType = _fieldTypeEventPropMap[getFieldValueType(value)] || -1;
|
|
184
|
-
|
|
185
|
-
if (encodedTypeValue !== -1 && propType !== -1) {
|
|
186
|
-
// pii exists so we must return correct type
|
|
187
|
-
encodedTypeValue |= propType;
|
|
188
|
-
} else if (propType === eEventPropertyType.Double) {
|
|
189
|
-
encodedTypeValue = propType;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return encodedTypeValue;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* @deprecated - Use the core.getCookieMgr().disable()
|
|
199
|
-
* Force the SDK not to store and read any data from cookies.
|
|
200
|
-
* Overriding the applicationinsights-core version for tree-shaking
|
|
201
|
-
*/
|
|
202
|
-
export function disableCookies() {
|
|
203
|
-
safeGetCookieMgr(null).setEnabled(false);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* @deprecated - Use the oneDs.getCookieMgr().set()
|
|
208
|
-
* Sets the value of a cookie.
|
|
209
|
-
* @param name - Cookie name.
|
|
210
|
-
* @param value - Cookie value.
|
|
211
|
-
* @param days - Expiration days.
|
|
212
|
-
*/
|
|
213
|
-
export function setCookie(name: string, value: string, days: number): void {
|
|
214
|
-
if (areCookiesSupported(null)) {
|
|
215
|
-
safeGetCookieMgr(null).set(name, value, days * 86400, null, "/");
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* @deprecated - Use the oneDs.getCookieMgr().del()
|
|
221
|
-
* Deletes a cookie, by setting its expiration to -1.
|
|
222
|
-
* @param name - Cookie name to delete.
|
|
223
|
-
*/
|
|
224
|
-
export function deleteCookie(name: string): void {
|
|
225
|
-
if (areCookiesSupported(null)) {
|
|
226
|
-
safeGetCookieMgr(null).del(name);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* @deprecated - Use the oneDs.getCookieMgr().get()
|
|
232
|
-
* Gets the cookie value for the specified cookie.
|
|
233
|
-
* if value is k1=v1&k2==v2 then will return 'v1' for key 'k1'
|
|
234
|
-
* @param cookieName - Cookie name.
|
|
235
|
-
*/
|
|
236
|
-
export function getCookie(name: string): string {
|
|
237
|
-
if (areCookiesSupported(null)) {
|
|
238
|
-
return getCookieValue(safeGetCookieMgr(null), name);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return STR_EMPTY;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Helper to get and decode the cookie value using decodeURIComponent, this is for historical
|
|
246
|
-
* backward compatibility where the document.cookie value was decoded before parsing.
|
|
247
|
-
* @param cookieMgr - The cookie manager to use
|
|
248
|
-
* @param name - The name of the cookie to get
|
|
249
|
-
* @param decode - A flag to indicate whether the cookie value should be decoded
|
|
250
|
-
* @returns The decoded cookie value (if available) otherwise an empty string.
|
|
251
|
-
*/
|
|
252
|
-
export function getCookieValue(cookieMgr: ICookieMgr, name: string, decode: boolean = true): string {
|
|
253
|
-
let cookieValue: string;
|
|
254
|
-
if (cookieMgr) {
|
|
255
|
-
cookieValue = cookieMgr.get(name);
|
|
256
|
-
if (decode && cookieValue && decodeURIComponent) {
|
|
257
|
-
cookieValue = decodeURIComponent(cookieValue);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return cookieValue || STR_EMPTY;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Create a new guid.
|
|
266
|
-
* @param style - The style of guid to generated, defaults to Digits
|
|
267
|
-
* Digits (Default) : 32 digits separated by hyphens: 00000000-0000-0000-0000-000000000000
|
|
268
|
-
* Braces - 32 digits separated by hyphens, enclosed in braces: {00000000-0000-0000-0000-000000000000}
|
|
269
|
-
* Parentheses - 32 digits separated by hyphens, enclosed in parentheses: (00000000-0000-0000-0000-000000000000)
|
|
270
|
-
* Numeric - 32 digits: 00000000000000000000000000000000
|
|
271
|
-
* @returns The formatted guid.
|
|
272
|
-
*/
|
|
273
|
-
export function createGuid(style: GuidStyle = GuidStyle.Digits): string {
|
|
274
|
-
let theGuid = newGuid();
|
|
275
|
-
if (style === GuidStyle.Braces) {
|
|
276
|
-
theGuid = "{" + theGuid + "}";
|
|
277
|
-
} else if (style === GuidStyle.Parentheses) {
|
|
278
|
-
theGuid = "(" + theGuid + ")";
|
|
279
|
-
} else if (style === GuidStyle.Numeric) {
|
|
280
|
-
theGuid = theGuid.replace(/-/g, STR_EMPTY);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
return theGuid;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Pass in the objects to merge as arguments.
|
|
288
|
-
* @param obj1 - object to merge. Set this argument to 'true' for a deep extend.
|
|
289
|
-
* @param obj2 - object to merge.
|
|
290
|
-
* @param obj3 - object to merge.
|
|
291
|
-
* @param obj4 - object to merge.
|
|
292
|
-
* @param obj5 - object to merge.
|
|
293
|
-
* @returns The extended object.
|
|
294
|
-
*/
|
|
295
|
-
export function extend(obj?: any, obj2?: any, obj3?: any, obj4?: any, obj5?: any): any {
|
|
296
|
-
// Variables
|
|
297
|
-
var extended = {};
|
|
298
|
-
var deep = false;
|
|
299
|
-
var i = 0;
|
|
300
|
-
var length = arguments.length;
|
|
301
|
-
var objProto = Object[strShimPrototype];
|
|
302
|
-
var theArgs = arguments;
|
|
303
|
-
|
|
304
|
-
// Check if a deep merge
|
|
305
|
-
if (objProto.toString.call(theArgs[0]) === "[object Boolean]") {
|
|
306
|
-
deep = theArgs[0];
|
|
307
|
-
i++;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// Loop through each object and conduct a merge
|
|
311
|
-
for (; i < length; i++) {
|
|
312
|
-
var obj = theArgs[i];
|
|
313
|
-
objForEachKey(obj, (prop, value) => {
|
|
314
|
-
// If deep merge and property is an object, merge properties
|
|
315
|
-
if (deep && value && isObject(value)) {
|
|
316
|
-
if (isArray(value)) {
|
|
317
|
-
extended[prop] = extended[prop] || [];
|
|
318
|
-
arrForEach(value, (arrayValue, arrayIndex) => {
|
|
319
|
-
if (arrayValue && isObject(arrayValue)) {
|
|
320
|
-
extended[prop][arrayIndex] = extend(true, extended[prop][arrayIndex], arrayValue);
|
|
321
|
-
} else {
|
|
322
|
-
extended[prop][arrayIndex] = arrayValue;
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
} else {
|
|
326
|
-
extended[prop] = extend(true, extended[prop], value);
|
|
327
|
-
}
|
|
328
|
-
} else {
|
|
329
|
-
extended[prop] = value;
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
return extended;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
export let getTime = perfNow;
|
|
338
|
-
|
|
339
|
-
export function isValueKind(value: number | undefined): boolean {
|
|
340
|
-
// Always assume that it's a number (no type checking) for performance as this is used during the JSON serialization
|
|
341
|
-
if (value === eValueKind.NotSet || ((value > eValueKind.NotSet && value <= eValueKind.Pii_IPV4AddressLegacy) || value === eValueKind.CustomerContent_GenericContent)) {
|
|
342
|
-
return true;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
return false;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
function isDataType(value: number): boolean {
|
|
349
|
-
// Remark: 0 returns false, but it doesn't affect encoding anyways
|
|
350
|
-
// Always assume that it's a number (no type checking) for performance as this is used during the JSON serialization
|
|
351
|
-
if (value >= 0 && value <= 9) {
|
|
352
|
-
return true;
|
|
353
|
-
}
|
|
354
|
-
return false;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
function isSafariOrFirefox(): boolean {
|
|
358
|
-
var nav = getNavigator();
|
|
359
|
-
// If non-browser navigator will be undefined
|
|
360
|
-
if (!isUndefined(nav) && nav.userAgent) {
|
|
361
|
-
var ua = nav.userAgent.toLowerCase();
|
|
362
|
-
if ((ua.indexOf("safari") >= 0 || ua.indexOf("firefox") >= 0) && ua.indexOf("chrome") < 0) {
|
|
363
|
-
return true;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
return false;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
export function isArrayValid(value: any[]): boolean {
|
|
370
|
-
return value.length > 0;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
export function setProcessTelemetryTimings(event: ITelemetryItem, identifier: string): void {
|
|
374
|
-
var evt = event as IExtendedTelemetryItem;
|
|
375
|
-
evt.timings = evt.timings || {};
|
|
376
|
-
evt.timings.processTelemetryStart = evt.timings.processTelemetryStart || {};
|
|
377
|
-
evt.timings.processTelemetryStart[identifier] = getTime();
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Returns a bitwise value for the FieldValueSanitizerType enum representing the decoded type of the passed value
|
|
382
|
-
* @param value The value to determine the type
|
|
383
|
-
*/
|
|
384
|
-
export function getFieldValueType(value: any): FieldValueSanitizerType {
|
|
385
|
-
let theType: FieldValueSanitizerType = FieldValueSanitizerType.NotSet;
|
|
386
|
-
|
|
387
|
-
if (value !== null && value !== undefined) {
|
|
388
|
-
let objType = typeof value;
|
|
389
|
-
if (objType === "string") {
|
|
390
|
-
theType = FieldValueSanitizerType.String;
|
|
391
|
-
} else if (objType === "number") {
|
|
392
|
-
theType = FieldValueSanitizerType.Number;
|
|
393
|
-
} else if (objType === "boolean") {
|
|
394
|
-
theType = FieldValueSanitizerType.Boolean;
|
|
395
|
-
} else if (objType === strShimObject) {
|
|
396
|
-
theType = FieldValueSanitizerType.Object;
|
|
397
|
-
if (isArray(value)) {
|
|
398
|
-
theType = FieldValueSanitizerType.Array;
|
|
399
|
-
if (value.length > 0) {
|
|
400
|
-
// Empty arrays are not supported and are considered to be the same as null
|
|
401
|
-
theType |= getFieldValueType(value[0]);
|
|
402
|
-
}
|
|
403
|
-
} else if (ObjHasOwnProperty.call(value, "value")) {
|
|
404
|
-
// Looks like an IEventProperty
|
|
405
|
-
theType = FieldValueSanitizerType.EventProperty | getFieldValueType(value.value);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
return theType;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
export const Utils = {
|
|
414
|
-
Version: Version,
|
|
415
|
-
FullVersionString: FullVersionString,
|
|
416
|
-
strUndefined: strUndefined,
|
|
417
|
-
strObject: strObject,
|
|
418
|
-
Undefined: strUndefined,
|
|
419
|
-
arrForEach: arrForEach,
|
|
420
|
-
arrIndexOf: arrIndexOf,
|
|
421
|
-
arrMap: arrMap,
|
|
422
|
-
arrReduce: arrReduce,
|
|
423
|
-
objKeys: objKeys,
|
|
424
|
-
toISOString: toISOString,
|
|
425
|
-
isReactNative: isReactNative,
|
|
426
|
-
isString: isString,
|
|
427
|
-
isNumber: isNumber,
|
|
428
|
-
isBoolean: isBoolean,
|
|
429
|
-
isFunction: isFunction,
|
|
430
|
-
isArray: isArray,
|
|
431
|
-
isObject: isObject,
|
|
432
|
-
strTrim: strTrim,
|
|
433
|
-
isDocumentObjectAvailable: isDocumentObjectAvailable,
|
|
434
|
-
isWindowObjectAvailable: isWindowObjectAvailable,
|
|
435
|
-
isValueAssigned: isValueAssigned,
|
|
436
|
-
getTenantId: getTenantId,
|
|
437
|
-
isBeaconsSupported: isBeaconsSupported,
|
|
438
|
-
isUint8ArrayAvailable: isUint8ArrayAvailable,
|
|
439
|
-
isLatency: isLatency,
|
|
440
|
-
sanitizeProperty: sanitizeProperty,
|
|
441
|
-
getISOString: toISOString,
|
|
442
|
-
useXDomainRequest: useXDomainRequest,
|
|
443
|
-
getCommonSchemaMetaData: getCommonSchemaMetaData,
|
|
444
|
-
cookieAvailable: areCookiesSupported,
|
|
445
|
-
disallowsSameSiteNone: uaDisallowsSameSiteNone,
|
|
446
|
-
setCookie: setCookie,
|
|
447
|
-
deleteCookie: deleteCookie,
|
|
448
|
-
getCookie: getCookie,
|
|
449
|
-
createGuid: createGuid,
|
|
450
|
-
extend: extend,
|
|
451
|
-
getTime: getTime,
|
|
452
|
-
isValueKind: isValueKind,
|
|
453
|
-
isArrayValid: isArrayValid,
|
|
454
|
-
objDefineAccessors: objDefineAccessors,
|
|
455
|
-
addPageUnloadEventListener: addPageUnloadEventListener,
|
|
456
|
-
setProcessTelemetryTimings: setProcessTelemetryTimings,
|
|
457
|
-
addEventHandler: addEventHandler,
|
|
458
|
-
getFieldValueType: getFieldValueType,
|
|
459
|
-
strEndsWith: strEndsWith,
|
|
460
|
-
objForEachKey: objForEachKey
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
/**
|
|
464
|
-
* Provides a collection of utility functions, included for backward compatibility with previous releases.
|
|
465
|
-
* @deprecated Marking this instance as deprecated in favor of direct usage of the helper functions
|
|
466
|
-
* as direct usage provides better tree-shaking and minification by avoiding the inclusion of the unused items
|
|
467
|
-
* in your resulting code.
|
|
468
|
-
* Overriding the applicationinsights-core version for tree-shaking
|
|
469
|
-
*/
|
|
470
|
-
export const CoreUtils: ICoreUtils = {
|
|
471
|
-
_canUseCookies: undefined,
|
|
472
|
-
isTypeof: isTypeof,
|
|
473
|
-
isUndefined: isUndefined,
|
|
474
|
-
isNullOrUndefined: isNullOrUndefined,
|
|
475
|
-
hasOwnProperty: hasOwnProperty,
|
|
476
|
-
isFunction: isFunction,
|
|
477
|
-
isObject: isObject,
|
|
478
|
-
isDate: isDate,
|
|
479
|
-
isArray: isArray,
|
|
480
|
-
isError: isError,
|
|
481
|
-
isString: isString,
|
|
482
|
-
isNumber: isNumber,
|
|
483
|
-
isBoolean: isBoolean,
|
|
484
|
-
toISOString: toISOString,
|
|
485
|
-
arrForEach: arrForEach,
|
|
486
|
-
arrIndexOf: arrIndexOf,
|
|
487
|
-
arrMap: arrMap,
|
|
488
|
-
arrReduce: arrReduce,
|
|
489
|
-
strTrim: strTrim,
|
|
490
|
-
objCreate: objCreateFn,
|
|
491
|
-
objKeys: objKeys,
|
|
492
|
-
objDefineAccessors: objDefineAccessors,
|
|
493
|
-
addEventHandler: addEventHandler,
|
|
494
|
-
dateNow: dateNow,
|
|
495
|
-
isIE: isIE,
|
|
496
|
-
disableCookies: disableCookies,
|
|
497
|
-
newGuid: newGuid,
|
|
498
|
-
perfNow: perfNow,
|
|
499
|
-
newId: newId,
|
|
500
|
-
randomValue: randomValue,
|
|
501
|
-
random32: random32,
|
|
502
|
-
mwcRandomSeed: mwcRandomSeed,
|
|
503
|
-
mwcRandom32: mwcRandom32,
|
|
504
|
-
generateW3CId: generateW3CId
|
|
505
|
-
};
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
* Helper to identify whether we are running in a chromium based browser environment
|
|
509
|
-
*/
|
|
510
|
-
export function isChromium() {
|
|
511
|
-
return !!getGlobalInst("chrome");
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* Create and open an XMLHttpRequest object
|
|
516
|
-
* @param method - The request method
|
|
517
|
-
* @param urlString - The url
|
|
518
|
-
* @param withCredentials - Option flag indicating that credentials should be sent
|
|
519
|
-
* @param disabled - Optional flag indicating that the XHR object should be marked as disabled and not tracked (default is false)
|
|
520
|
-
* @param isSync - Optional flag indicating if the instance should be a synchronous request (defaults to false)
|
|
521
|
-
* @param timeout - Optional value identifying the timeout value that should be assigned to the XHR request
|
|
522
|
-
* @returns A new opened XHR request
|
|
523
|
-
*/
|
|
524
|
-
export function openXhr(method: string, urlString: string, withCredentials?: boolean, disabled: boolean = false, isSync: boolean = false, timeout?: number) {
|
|
525
|
-
|
|
526
|
-
function _wrapSetXhrProp<T>(xhr: XMLHttpRequest, prop: string, value: T) {
|
|
527
|
-
try {
|
|
528
|
-
xhr[prop] = value;
|
|
529
|
-
} catch (e) {
|
|
530
|
-
// - Wrapping as depending on the environment setting the property may fail (non-terminally)
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
let xhr = new XMLHttpRequest();
|
|
535
|
-
|
|
536
|
-
if (disabled) {
|
|
537
|
-
// Tag the instance so it's not tracked (trackDependency)
|
|
538
|
-
// If the environment has locked down the XMLHttpRequest (preventExtensions and/or freeze), this would
|
|
539
|
-
// cause the request to fail and we no telemetry would be sent
|
|
540
|
-
_wrapSetXhrProp(xhr, strDisabledPropertyName, disabled);
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
if (withCredentials) {
|
|
544
|
-
// Some libraries require that the withCredentials flag is set "before" open and
|
|
545
|
-
// - Wrapping as IE 10 has started throwing when setting before open
|
|
546
|
-
_wrapSetXhrProp(xhr, strWithCredentials, withCredentials);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
xhr.open(method, urlString, !isSync);
|
|
550
|
-
|
|
551
|
-
if (withCredentials) {
|
|
552
|
-
// withCredentials should be set AFTER open (https://xhr.spec.whatwg.org/#the-withcredentials-attribute)
|
|
553
|
-
// And older firefox instances from 11+ will throw for sync events (current versions don't) which happens during unload processing
|
|
554
|
-
_wrapSetXhrProp(xhr, strWithCredentials, withCredentials);
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
// Only set the timeout for asynchronous requests as
|
|
558
|
-
// "Timeout shouldn't be used for synchronous XMLHttpRequests requests used in a document environment or it will throw an InvalidAccessError exception.""
|
|
559
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/timeout
|
|
560
|
-
if (!isSync && timeout) {
|
|
561
|
-
_wrapSetXhrProp(xhr, strTimeout, timeout);
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
return xhr;
|
|
565
|
-
}
|