@microsoft/1ds-post-js 3.2.3 → 3.2.4

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.
Files changed (69) hide show
  1. package/README.md +1 -1
  2. package/bundle/{ms.post-3.2.3.gbl.js → ms.post-3.2.4.gbl.js} +507 -438
  3. package/bundle/ms.post-3.2.4.gbl.js.map +1 -0
  4. package/bundle/ms.post-3.2.4.gbl.min.js +7 -0
  5. package/bundle/ms.post-3.2.4.gbl.min.js.map +1 -0
  6. package/bundle/ms.post-3.2.4.integrity.json +46 -0
  7. package/bundle/{ms.post-3.2.3.js → ms.post-3.2.4.js} +507 -438
  8. package/bundle/ms.post-3.2.4.js.map +1 -0
  9. package/bundle/ms.post-3.2.4.min.js +7 -0
  10. package/bundle/ms.post-3.2.4.min.js.map +1 -0
  11. package/bundle/ms.post.gbl.js +506 -437
  12. package/bundle/ms.post.gbl.js.map +1 -1
  13. package/bundle/ms.post.gbl.min.js +2 -2
  14. package/bundle/ms.post.gbl.min.js.map +1 -1
  15. package/bundle/ms.post.integrity.json +17 -17
  16. package/bundle/ms.post.js +506 -437
  17. package/bundle/ms.post.js.map +1 -1
  18. package/bundle/ms.post.min.js +2 -2
  19. package/bundle/ms.post.min.js.map +1 -1
  20. package/dist/ms.post.js +197 -187
  21. package/dist/ms.post.js.map +1 -1
  22. package/dist/ms.post.min.js +2 -2
  23. package/dist/ms.post.min.js.map +1 -1
  24. package/dist-esm/src/BatchNotificationActions.js +1 -1
  25. package/dist-esm/src/ClockSkewManager.js +6 -1
  26. package/dist-esm/src/ClockSkewManager.js.map +1 -1
  27. package/dist-esm/src/DataModels.js +1 -1
  28. package/dist-esm/src/EventBatch.d.ts +0 -5
  29. package/dist-esm/src/EventBatch.js +9 -4
  30. package/dist-esm/src/EventBatch.js.map +1 -1
  31. package/dist-esm/src/HttpManager.d.ts +2 -7
  32. package/dist-esm/src/HttpManager.js +62 -54
  33. package/dist-esm/src/HttpManager.js.map +1 -1
  34. package/dist-esm/src/Index.js +1 -1
  35. package/dist-esm/src/InternalConstants.d.ts +27 -0
  36. package/dist-esm/src/InternalConstants.js +40 -0
  37. package/dist-esm/src/InternalConstants.js.map +1 -0
  38. package/dist-esm/src/KillSwitch.js +7 -2
  39. package/dist-esm/src/KillSwitch.js.map +1 -1
  40. package/dist-esm/src/PostChannel.d.ts +1 -1
  41. package/dist-esm/src/PostChannel.js +16 -10
  42. package/dist-esm/src/PostChannel.js.map +1 -1
  43. package/dist-esm/src/RetryPolicy.js +1 -1
  44. package/dist-esm/src/Serializer.d.ts +1 -1
  45. package/dist-esm/src/Serializer.js +9 -3
  46. package/dist-esm/src/Serializer.js.map +1 -1
  47. package/dist-esm/src/TimeoutOverrideWrapper.d.ts +5 -5
  48. package/dist-esm/src/TimeoutOverrideWrapper.js +6 -6
  49. package/dist-esm/src/TimeoutOverrideWrapper.js.map +1 -1
  50. package/dist-esm/src/typings/XDomainRequest.js +1 -1
  51. package/package.json +4 -2
  52. package/src/EventBatch.ts +4 -4
  53. package/src/HttpManager.ts +70 -68
  54. package/src/InternalConstants.ts +41 -0
  55. package/src/KillSwitch.ts +1 -1
  56. package/src/PostChannel.ts +16 -20
  57. package/src/Serializer.ts +7 -5
  58. package/src/TimeoutOverrideWrapper.ts +6 -6
  59. package/bundle/ms.post-3.2.3.gbl.js.map +0 -1
  60. package/bundle/ms.post-3.2.3.gbl.min.js +0 -7
  61. package/bundle/ms.post-3.2.3.gbl.min.js.map +0 -1
  62. package/bundle/ms.post-3.2.3.integrity.json +0 -46
  63. package/bundle/ms.post-3.2.3.js.map +0 -1
  64. package/bundle/ms.post-3.2.3.min.js +0 -7
  65. package/bundle/ms.post-3.2.3.min.js.map +0 -1
  66. package/dist-esm/src/Constants.d.ts +0 -25
  67. package/dist-esm/src/Constants.js +0 -31
  68. package/dist-esm/src/Constants.js.map +0 -1
  69. package/src/Constants.ts +0 -28
@@ -3,38 +3,37 @@
3
3
  * @author Abhilash Panwar (abpanwar); Hector Hernandez (hectorh); Nev Wylie (newylie)
4
4
  * @copyright Microsoft 2018-2020
5
5
  */
6
+ import dynamicProto from "@microsoft/dynamicproto-js";
7
+ import EVTClockSkewManager from "./ClockSkewManager";
8
+ import EVTKillSwitch from "./KillSwitch";
6
9
  import {
7
- isReactNative, isValueAssigned, isString, getTime, arrForEach, getLocation, strTrim, isFetchSupported, isXhrSupported,
8
- isBeaconsSupported, FullVersionString, useXDomainRequest, IExtendedAppInsightsCore, IExtendedConfiguration,
9
- eLoggingSeverity, _eExtendedInternalMessageId, SendRequestReason, strUndefined, getNavigator, doPerf, IPerfEvent,
10
- dateNow, isUndefined, isNullOrUndefined, objForEachKey, ICookieMgr, isNumber, isArray, TransportType, dumpObj, objKeys, extend,
11
- EventSendType, hasOwnProperty, openXhr, _throwInternal, _eInternalMessageId
10
+ EventSendType, FullVersionString, ICookieMgr, IDiagnosticLogger, IExtendedAppInsightsCore, IExtendedConfiguration, IPerfEvent,
11
+ SendRequestReason, TransportType, _eExtendedInternalMessageId, _eInternalMessageId, _throwInternal, _warnToConsole, arrForEach, dateNow,
12
+ doPerf, dumpObj, eLoggingSeverity, extend, getLocation, getNavigator, getTime, hasOwnProperty, isArray, isBeaconsSupported,
13
+ isFetchSupported, isNullOrUndefined, isNumber, isReactNative, isString, isUndefined, isValueAssigned, isXhrSupported, objForEachKey,
14
+ objKeys, openXhr, strTrim, strUndefined, useXDomainRequest
12
15
  } from "@microsoft/1ds-core-js";
16
+ import { BatchNotificationAction, BatchNotificationActions } from "./BatchNotificationActions";
13
17
  import {
14
- IXHROverride, IPostTransmissionTelemetryItem, ICollectorResult,
15
- IPostChannel, PayloadPreprocessorFunction, PayloadListenerFunction, IPayloadData,
16
- SendPOSTFunction, EventBatchNotificationReason,
18
+ EventBatchNotificationReason, ICollectorResult, IPayloadData, IPostChannel, IPostTransmissionTelemetryItem, IXHROverride,
19
+ PayloadListenerFunction, PayloadPreprocessorFunction, SendPOSTFunction
17
20
  } from "./DataModels";
18
- import { BatchNotificationAction, BatchNotificationActions } from "./BatchNotificationActions";
19
21
  import { EventBatch } from "./EventBatch";
20
- import { Serializer, ISerializedPayload } from "./Serializer";
21
- import { retryPolicyGetMillisToBackoffForRetry, retryPolicyShouldRetryForStatus } from "./RetryPolicy";
22
- import EVTKillSwitch from "./KillSwitch";
23
- import EVTClockSkewManager from "./ClockSkewManager";
24
- import dynamicProto from "@microsoft/dynamicproto-js";
25
22
  import { IChannelConfiguration } from "./Index";
26
- import { XDomainRequest as IXDomainRequest } from "./typings/XDomainRequest";
27
- import {
28
- defaultCacheControl, defaultContentType, DisabledPropertyName, Method, strApiKey, strAuthXToken, strCacheControl,
29
- strClientId, strClientVersion, strContentTypeHeader, strDropped, strKillDurationHeader, strKillDurationSecondsHeader,
30
- strKillTokensHeader, strMsaDeviceTicket, strMsfpc, strNoResponseBody, strOther, strRequeue, strResponseFail, strSending, strTimeDeltaHeader,
31
- strTimeDeltaToApply, strUploadTime
32
- } from "./Constants";
23
+ import {
24
+ DEFAULT_CACHE_CONTROL, DEFAULT_CONTENT_TYPE, STR_API_KEY, STR_AUTH_XTOKEN, STR_CACHE_CONTROL, STR_CLIENT_ID, STR_CLIENT_VERSION,
25
+ STR_CONTENT_TYPE_HEADER, STR_DISABLED_PROPERTY_NAME, STR_DROPPED, STR_KILL_DURATION_HEADER, STR_KILL_DURATION_SECONDS_HEADER,
26
+ STR_KILL_TOKENS_HEADER, STR_MSA_DEVICE_TICKET, STR_MSFPC, STR_NO_RESPONSE_BODY, STR_OTHER, STR_POST_METHOD, STR_REQUEUE,
27
+ STR_RESPONSE_FAIL, STR_SENDING, STR_TIME_DELTA_HEADER, STR_TIME_DELTA_TO_APPLY, STR_UPLOAD_TIME
28
+ } from "./InternalConstants";
29
+ import { retryPolicyGetMillisToBackoffForRetry, retryPolicyShouldRetryForStatus } from "./RetryPolicy";
30
+ import { ISerializedPayload, Serializer } from "./Serializer";
33
31
  import { ITimeoutOverrideWrapper } from "./TimeoutOverrideWrapper";
32
+ import { XDomainRequest as IXDomainRequest } from "./typings/XDomainRequest";
34
33
 
35
34
  const strSendAttempt = "sendAttempt";
36
35
 
37
- const _noResponseQs = "&" + strNoResponseBody + "=true";
36
+ const _noResponseQs = "&" + STR_NO_RESPONSE_BODY + "=true";
38
37
 
39
38
  // TypeScript removed this interface so we need to declare the global so we can check for it's existence.
40
39
  declare var XDomainRequest: {
@@ -52,11 +51,11 @@ interface IRequestUrlDetails {
52
51
  * Identifies the default notification reason to the action names
53
52
  */
54
53
  const _eventActionMap: any = {
55
- [EventBatchNotificationReason.Paused]: strRequeue,
56
- [EventBatchNotificationReason.RequeueEvents]: strRequeue,
54
+ [EventBatchNotificationReason.Paused]: STR_REQUEUE,
55
+ [EventBatchNotificationReason.RequeueEvents]: STR_REQUEUE,
57
56
  [EventBatchNotificationReason.Complete]: "sent",
58
- [EventBatchNotificationReason.KillSwitch]: strDropped,
59
- [EventBatchNotificationReason.SizeLimitExceeded]: strDropped
57
+ [EventBatchNotificationReason.KillSwitch]: STR_DROPPED,
58
+ [EventBatchNotificationReason.SizeLimitExceeded]: STR_DROPPED
60
59
  };
61
60
 
62
61
  const _collectorQsHeaders = { };
@@ -69,13 +68,13 @@ function _addCollectorHeaderQsMapping(qsName: string, headerName: string, allowQ
69
68
  }
70
69
  }
71
70
 
72
- _addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket, false);
73
- _addCollectorHeaderQsMapping(strClientVersion, strClientVersion);
74
- _addCollectorHeaderQsMapping(strClientId, "Client-Id");
75
- _addCollectorHeaderQsMapping(strApiKey, strApiKey);
76
- _addCollectorHeaderQsMapping(strTimeDeltaToApply, strTimeDeltaToApply);
77
- _addCollectorHeaderQsMapping(strUploadTime, strUploadTime);
78
- _addCollectorHeaderQsMapping(strAuthXToken, strAuthXToken);
71
+ _addCollectorHeaderQsMapping(STR_MSA_DEVICE_TICKET, STR_MSA_DEVICE_TICKET, false);
72
+ _addCollectorHeaderQsMapping(STR_CLIENT_VERSION, STR_CLIENT_VERSION);
73
+ _addCollectorHeaderQsMapping(STR_CLIENT_ID, "Client-Id");
74
+ _addCollectorHeaderQsMapping(STR_API_KEY, STR_API_KEY);
75
+ _addCollectorHeaderQsMapping(STR_TIME_DELTA_TO_APPLY, STR_TIME_DELTA_TO_APPLY);
76
+ _addCollectorHeaderQsMapping(STR_UPLOAD_TIME, STR_UPLOAD_TIME);
77
+ _addCollectorHeaderQsMapping(STR_AUTH_XTOKEN, STR_AUTH_XTOKEN);
79
78
 
80
79
  type OnCompleteCallback = (status: number, headers: { [headerName: string]: string }, response?: string) => void;
81
80
 
@@ -143,13 +142,14 @@ export class HttpManager {
143
142
  * @param requestQueue - The queue that contains the requests to be sent.
144
143
  */
145
144
  constructor(maxEventsPerBatch: number, maxConnections: number, maxRequestRetriesBeforeBackoff: number, actions: BatchNotificationActions, timeoutOverride: ITimeoutOverrideWrapper) {
146
- let _urlString: string = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType;
145
+ let _urlString: string = "?cors=true&" + STR_CONTENT_TYPE_HEADER.toLowerCase() + "=" + DEFAULT_CONTENT_TYPE;
147
146
  let _killSwitch: EVTKillSwitch = new EVTKillSwitch();
148
147
  let _paused = false;
149
148
  let _clockSkewManager = new EVTClockSkewManager();
150
149
  let _useBeacons = false;
151
150
  let _outstandingRequests = 0; // Holds the number of outstanding async requests that have not returned a response yet
152
151
  let _postManager: IPostChannel;
152
+ let _logger: IDiagnosticLogger;
153
153
  let _sendInterfaces: { [key: number]: IInternalXhrOverride };
154
154
  let _core: IExtendedAppInsightsCore;
155
155
  let _customHttpInterface = true;
@@ -186,6 +186,7 @@ export class HttpManager {
186
186
  _enableEventTimings = !(_core.config as IExtendedConfiguration).disableEventTimings;
187
187
  let enableCompoundKey = !!(_core.config as IExtendedConfiguration).enableCompoundKey;
188
188
  _postManager = postChannel;
189
+ _logger = _postManager.diagLog();
189
190
  let valueSanitizer = channelConfig.valueSanitizer;
190
191
  let stringifyObjects = channelConfig.stringifyObjects;
191
192
  if (!isUndefined(channelConfig.enableCompoundKey)) {
@@ -233,7 +234,7 @@ export class HttpManager {
233
234
  httpInterface = _getSenderInterface(theTransports, false);
234
235
  syncHttpInterface = _getSenderInterface(theTransports, true);
235
236
  if (!httpInterface) {
236
- _postManager.diagLog().warnToConsole("No available transport to send events");
237
+ _warnToConsole(_logger, "No available transport to send events");
237
238
  }
238
239
  }
239
240
 
@@ -285,7 +286,7 @@ export class HttpManager {
285
286
  function _xdrSendPost(payload: IPayloadData, oncomplete: OnCompleteCallback, sync?: boolean) {
286
287
  // It doesn't support custom headers, so no action is taken with current requestHeaders
287
288
  let xdr = new XDomainRequest();
288
- xdr.open(Method, payload.urlString);
289
+ xdr.open(STR_POST_METHOD, payload.urlString);
289
290
  if (payload.timeout) {
290
291
  xdr.timeout = payload.timeout;
291
292
  }
@@ -326,8 +327,8 @@ export class HttpManager {
326
327
  let responseHandled = false;
327
328
  let requestInit: RequestInit = {
328
329
  body: payload.data,
329
- method: Method,
330
- [DisabledPropertyName]: true
330
+ method: STR_POST_METHOD,
331
+ [STR_DISABLED_PROPERTY_NAME]: true
331
332
  };
332
333
 
333
334
  if (sync) {
@@ -353,8 +354,9 @@ export class HttpManager {
353
354
  fetch(theUrl, requestInit).then((response) => {
354
355
  let headerMap = {};
355
356
  let responseText = "";
356
- if (response.headers) {
357
- response.headers.forEach((value: string, name: string) => {
357
+ var headers = response.headers;
358
+ if (headers) {
359
+ headers["forEach"]((value: string, name: string) => {
358
360
  headerMap[name] = value;
359
361
  });
360
362
  }
@@ -417,9 +419,9 @@ export class HttpManager {
417
419
  // Firefox 2-63 doesn't have getAllResponseHeaders function but it does have getResponseHeader
418
420
  // Only call these if getAllResponseHeaders doesn't exist, otherwise we can get invalid response errors
419
421
  // as collector is not currently returning the correct header to allow JS to access these headers
420
- theHeaders = _appendHeader(theHeaders, xhr, strTimeDeltaHeader);
421
- theHeaders = _appendHeader(theHeaders, xhr, strKillDurationHeader);
422
- theHeaders = _appendHeader(theHeaders, xhr, strKillDurationSecondsHeader);
422
+ theHeaders = _appendHeader(theHeaders, xhr, STR_TIME_DELTA_HEADER);
423
+ theHeaders = _appendHeader(theHeaders, xhr, STR_KILL_DURATION_HEADER);
424
+ theHeaders = _appendHeader(theHeaders, xhr, STR_KILL_DURATION_SECONDS_HEADER);
423
425
  } else {
424
426
  theHeaders = _convertAllHeadersToMap(xhr.getAllResponseHeaders());
425
427
  }
@@ -434,7 +436,7 @@ export class HttpManager {
434
436
  sync = false;
435
437
  }
436
438
 
437
- let xhrRequest = openXhr(Method, theUrl, _sendCredentials, true, sync, payload.timeout);
439
+ let xhrRequest = openXhr(STR_POST_METHOD, theUrl, _sendCredentials, true, sync, payload.timeout);
438
440
 
439
441
  // Set custom headers (e.g. gzip) here (after open())
440
442
  objForEachKey(payload.headers, (name, value) => {
@@ -458,7 +460,7 @@ export class HttpManager {
458
460
  try {
459
461
  oncomplete(status, headers, response);
460
462
  } catch (e) {
461
- _throwInternal(_postManager.diagLog(),
463
+ _throwInternal(_logger,
462
464
  eLoggingSeverity.WARNING,
463
465
  _eExtendedInternalMessageId.SendPostOnCompleteFailure, dumpObj(e));
464
466
  }
@@ -500,7 +502,7 @@ export class HttpManager {
500
502
  }
501
503
 
502
504
  } catch (ex) {
503
- _postManager.diagLog().warnToConsole("Failed to send telemetry using sendBeacon API. Ex:" + dumpObj(ex));
505
+ _warnToConsole(_logger, "Failed to send telemetry using sendBeacon API. Ex:" + dumpObj(ex));
504
506
  status = 0;
505
507
  } finally {
506
508
  _doOnComplete(oncomplete, status, {}, "");
@@ -738,7 +740,7 @@ export class HttpManager {
738
740
  _sendBatchesNotification(droppedBatches, EventBatchNotificationReason.KillSwitch, sendType);
739
741
  }, () => ({ batches: _createDebugBatches(orgBatches), retryCount, isTeardown, isSynchronous, sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType }), !isSynchronous);
740
742
  } catch (ex) {
741
- _throwInternal(_postManager.diagLog(),
743
+ _throwInternal(_logger,
742
744
  eLoggingSeverity.WARNING,
743
745
  _eInternalMessageId.CannotSerializeObject, "Unexpected Exception sending batch: " + dumpObj(ex));
744
746
  }
@@ -768,8 +770,8 @@ export class HttpManager {
768
770
  requestDetails.useHdrs = (objKeys(requestDetails.hdrs).length > 0);
769
771
  }
770
772
 
771
- _addRequestDetails(requestDetails, strClientId, "NO_AUTH", useHeaders);
772
- _addRequestDetails(requestDetails, strClientVersion, FullVersionString, useHeaders);
773
+ _addRequestDetails(requestDetails, STR_CLIENT_ID, "NO_AUTH", useHeaders);
774
+ _addRequestDetails(requestDetails, STR_CLIENT_VERSION, FullVersionString, useHeaders);
773
775
 
774
776
  let apiQsKeys = "";
775
777
  arrForEach(thePayload.apiKeys, (apiKey) => {
@@ -780,8 +782,8 @@ export class HttpManager {
780
782
  apiQsKeys += apiKey;
781
783
  });
782
784
 
783
- _addRequestDetails(requestDetails, strApiKey, apiQsKeys, useHeaders);
784
- _addRequestDetails(requestDetails, strUploadTime, dateNow().toString(), useHeaders);
785
+ _addRequestDetails(requestDetails, STR_API_KEY, apiQsKeys, useHeaders);
786
+ _addRequestDetails(requestDetails, STR_UPLOAD_TIME, dateNow().toString(), useHeaders);
785
787
 
786
788
  let msfpc = _getMsfpc(thePayload);
787
789
  if (isValueAssigned(msfpc)) {
@@ -789,7 +791,7 @@ export class HttpManager {
789
791
  }
790
792
 
791
793
  if (_clockSkewManager.shouldAddClockSkewHeaders()) {
792
- _addRequestDetails(requestDetails, strTimeDeltaToApply, _clockSkewManager.getClockSkewHeaderValue(), useHeaders);
794
+ _addRequestDetails(requestDetails, STR_TIME_DELTA_TO_APPLY, _clockSkewManager.getClockSkewHeaderValue(), useHeaders);
793
795
  }
794
796
 
795
797
  if (_core.getWParam) {
@@ -881,12 +883,12 @@ export class HttpManager {
881
883
 
882
884
  // Only automatically add the following headers if already sending headers and we are not attempting to avoid an options call
883
885
  if (useHeaders) {
884
- if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {
885
- orgPayloadData.headers[strCacheControl] = defaultCacheControl;
886
+ if (!_hasHeader(orgPayloadData.headers, STR_CACHE_CONTROL)) {
887
+ orgPayloadData.headers[STR_CACHE_CONTROL] = DEFAULT_CACHE_CONTROL;
886
888
  }
887
889
 
888
- if (!_hasHeader(orgPayloadData.headers, strContentTypeHeader)) {
889
- orgPayloadData.headers[strContentTypeHeader] = defaultContentType;
890
+ if (!_hasHeader(orgPayloadData.headers, STR_CONTENT_TYPE_HEADER)) {
891
+ orgPayloadData.headers[STR_CONTENT_TYPE_HEADER] = DEFAULT_CONTENT_TYPE;
890
892
  }
891
893
  }
892
894
 
@@ -910,7 +912,7 @@ export class HttpManager {
910
912
  _self.sendListener(orgPayloadData, payload, isSync, thePayload.isBeacon);
911
913
  }
912
914
  } catch (ex) {
913
- _postManager.diagLog().warnToConsole("Unexpected exception sending payload. Ex:" + dumpObj(ex));
915
+ _warnToConsole(_logger, "Unexpected exception sending payload. Ex:" + dumpObj(ex));
914
916
 
915
917
  _doOnComplete(onComplete, 0, {});
916
918
  }
@@ -1002,9 +1004,9 @@ export class HttpManager {
1002
1004
 
1003
1005
  if (typeof status !== strUndefined) {
1004
1006
  if (headers) {
1005
- _clockSkewManager.setClockSkew(headers[strTimeDeltaHeader]);
1006
- let killDuration = headers[strKillDurationHeader] || headers["kill-duration-seconds"];
1007
- arrForEach(_killSwitch.setKillSwitchTenants(headers[strKillTokensHeader], killDuration), (killToken) => {
1007
+ _clockSkewManager.setClockSkew(headers[STR_TIME_DELTA_HEADER]);
1008
+ let killDuration = headers[STR_KILL_DURATION_HEADER] || headers["kill-duration-seconds"];
1009
+ arrForEach(_killSwitch.setKillSwitchTenants(headers[STR_KILL_TOKENS_HEADER], killDuration), (killToken) => {
1008
1010
  arrForEach(thePayload.batches, (theBatch) => {
1009
1011
  if (theBatch.iKey() === killToken) {
1010
1012
  // Make sure we have initialized the array
@@ -1184,7 +1186,7 @@ export class HttpManager {
1184
1186
  try {
1185
1187
  responseHandlers[i](responseText);
1186
1188
  } catch (e) {
1187
- _throwInternal(_postManager.diagLog(),
1189
+ _throwInternal(_logger,
1188
1190
  eLoggingSeverity.CRITICAL,
1189
1191
  _eExtendedInternalMessageId.PostResponseHandler,
1190
1192
  "Response handler failed: " + e);
@@ -1192,9 +1194,9 @@ export class HttpManager {
1192
1194
  }
1193
1195
  if (responseText) {
1194
1196
  let response = JSON.parse(responseText) as ICollectorResult;
1195
- if (isValueAssigned(response.webResult) && isValueAssigned(response.webResult[strMsfpc])) {
1197
+ if (isValueAssigned(response.webResult) && isValueAssigned(response.webResult[STR_MSFPC])) {
1196
1198
  // Set cookie
1197
- _cookieMgr.set("MSFPC", response.webResult[strMsfpc], 365 * 86400);
1199
+ _cookieMgr.set("MSFPC", response.webResult[STR_MSFPC], 365 * 86400);
1198
1200
  }
1199
1201
  }
1200
1202
  } catch (ex) {
@@ -1213,7 +1215,7 @@ export class HttpManager {
1213
1215
  try {
1214
1216
  theAction.call(actions, theBatches, batchReason, isSyncRequest, sendType);
1215
1217
  } catch (e) {
1216
- _throwInternal(_postManager.diagLog(),
1218
+ _throwInternal(_logger,
1217
1219
  eLoggingSeverity.CRITICAL,
1218
1220
  _eInternalMessageId.NotificationException,
1219
1221
  "send request notification failed: " + e);
@@ -1227,13 +1229,13 @@ export class HttpManager {
1227
1229
  function _getNotificationAction(reason: EventBatchNotificationReason): string {
1228
1230
  let action = _eventActionMap[reason];
1229
1231
  if (!isValueAssigned(action)) {
1230
- action = strOther;
1232
+ action = STR_OTHER;
1231
1233
  if (reason >= EventBatchNotificationReason.ResponseFailure && reason <= EventBatchNotificationReason.ResponseFailureMax) {
1232
- action = strResponseFail;
1234
+ action = STR_RESPONSE_FAIL;
1233
1235
  } else if (reason >= EventBatchNotificationReason.EventsDropped && reason <= EventBatchNotificationReason.EventsDroppedMax) {
1234
- action = strDropped;
1236
+ action = STR_DROPPED;
1235
1237
  } else if (reason >= EventBatchNotificationReason.SendingUndefined && reason <= EventBatchNotificationReason.SendingEventMax) {
1236
- action = strSending;
1238
+ action = STR_SENDING;
1237
1239
  }
1238
1240
  }
1239
1241
 
@@ -0,0 +1,41 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5
+ // Note: DON'T Export these const from the package as we are still targeting ES3 this will export a mutable variables that someone could change!!!
6
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7
+
8
+ // Generally you should only put values that are used more than 2 times and then only if not already exposed as a constant (such as SdkCoreNames)
9
+ // as when using "short" named values from here they will be will be minified smaller than the SdkCoreNames[eSdkCoreNames.xxxx] value.
10
+
11
+ export const STR_POST_METHOD = "POST";
12
+ export const STR_DISABLED_PROPERTY_NAME: string = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
13
+
14
+ export const STR_DROPPED = "drop";
15
+ export const STR_SENDING = "send";
16
+ export const STR_REQUEUE = "requeue";
17
+ export const STR_RESPONSE_FAIL = "rspFail";
18
+ export const STR_OTHER = "oth";
19
+
20
+ export const DEFAULT_CACHE_CONTROL = "no-cache, no-store";
21
+ export const DEFAULT_CONTENT_TYPE = "application/x-json-stream";
22
+ export const STR_CACHE_CONTROL = "cache-control";
23
+ export const STR_CONTENT_TYPE_HEADER = "content-type";
24
+ export const STR_KILL_TOKENS_HEADER = "kill-tokens";
25
+ export const STR_KILL_DURATION_HEADER = "kill-duration";
26
+ export const STR_KILL_DURATION_SECONDS_HEADER = "kill-duration-seconds";
27
+ export const STR_TIME_DELTA_HEADER = "time-delta-millis";
28
+ export const STR_CLIENT_VERSION = "client-version";
29
+ export const STR_CLIENT_ID = "client-id";
30
+ export const STR_TIME_DELTA_TO_APPLY = "time-delta-to-apply-millis";
31
+ export const STR_UPLOAD_TIME = "upload-time";
32
+ export const STR_API_KEY = "apikey";
33
+ export const STR_MSA_DEVICE_TICKET = "AuthMsaDeviceTicket";
34
+ export const STR_AUTH_XTOKEN = "AuthXToken";
35
+ export const STR_SDK_VERSION = "sdk-version";
36
+ export const STR_NO_RESPONSE_BODY = "NoResponseBody";
37
+
38
+ export const STR_MSFPC = "msfpc";
39
+
40
+ export const STR_TRACE = "trace";
41
+ export const STR_USER = "user";
package/src/KillSwitch.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import dynamicProto from "@microsoft/dynamicproto-js";
8
- import { arrForEach, strTrim, dateNow } from "@microsoft/1ds-core-js";
8
+ import { arrForEach, dateNow, strTrim } from "@microsoft/1ds-core-js";
9
9
 
10
10
  const SecToMsMultiplier = 1000;
11
11
 
@@ -5,26 +5,22 @@
5
5
  */
6
6
  import dynamicProto from "@microsoft/dynamicproto-js";
7
7
  import {
8
- BaseTelemetryPlugin, IChannelControls, IExtendedConfiguration, IExtendedAppInsightsCore,
9
- EventLatencyValue, NotificationManager, EventsDiscardedReason, IPlugin, ITelemetryItem,
10
- IAppInsightsCore, isValueAssigned, setProcessTelemetryTimings,
11
- IProcessTelemetryContext, SendRequestReason, arrForEach, eLoggingSeverity, _eExtendedInternalMessageId,
12
- doPerf, objForEachKey, optimizeObject, isChromium, getWindow, EventSendType, isNumber, mergeEvtNamespace,
13
- createUniqueNamespace, IProcessTelemetryUnloadContext, ITelemetryUnloadState,
14
- addPageUnloadEventListener, addPageHideEventListener, addPageShowEventListener,
15
- removePageUnloadEventListener, removePageHideEventListener, removePageShowEventListener,
16
- _throwInternal, _eInternalMessageId, objDefineAccessors
8
+ BaseTelemetryPlugin, EventLatencyValue, EventSendType, EventsDiscardedReason, IAppInsightsCore, IChannelControls,
9
+ IExtendedAppInsightsCore, IExtendedConfiguration, IPlugin, IProcessTelemetryContext, IProcessTelemetryUnloadContext, ITelemetryItem,
10
+ ITelemetryUnloadState, NotificationManager, SendRequestReason, _eInternalMessageId, _throwInternal, addPageHideEventListener,
11
+ addPageShowEventListener, addPageUnloadEventListener, arrForEach, createUniqueNamespace, doPerf, eLoggingSeverity, getWindow, isChromium,
12
+ isNumber, isValueAssigned, mergeEvtNamespace, objDefineAccessors, objForEachKey, optimizeObject, removePageHideEventListener,
13
+ removePageShowEventListener, removePageUnloadEventListener, setProcessTelemetryTimings
17
14
  } from "@microsoft/1ds-core-js";
18
15
  import {
19
- IChannelConfiguration, RT_PROFILE, NRT_PROFILE, IPostChannel,
20
- BE_PROFILE, IXHROverride, IPostTransmissionTelemetryItem,
21
- EventBatchNotificationReason,
16
+ BE_PROFILE, EventBatchNotificationReason, IChannelConfiguration, IPostChannel, IPostTransmissionTelemetryItem, IXHROverride, NRT_PROFILE,
17
+ RT_PROFILE
22
18
  } from "./DataModels";
23
19
  import { EventBatch } from "./EventBatch";
24
20
  import { HttpManager } from "./HttpManager";
21
+ import { STR_MSA_DEVICE_TICKET, STR_TRACE, STR_USER } from "./InternalConstants";
25
22
  import { retryPolicyGetMillisToBackoffForRetry } from "./RetryPolicy";
26
- import { strMsaDeviceTicket } from "./Constants";
27
- import { createTimeoutWrapper, ITimeoutOverrideWrapper, TimeoutClearFunc, TimeoutSetFunc } from "./TimeoutOverrideWrapper";
23
+ import { ITimeoutOverrideWrapper, TimeoutClearFunc, TimeoutSetFunc, createTimeoutWrapper } from "./TimeoutOverrideWrapper";
28
24
 
29
25
  const FlushCheckTimer = 0.250; // This needs to be in seconds, so this is 250ms
30
26
  const MaxNumberEventPerBatch = 500;
@@ -273,15 +269,15 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
273
269
  }
274
270
 
275
271
  // Remove extra AI properties if present
276
- if (event.ext && event.ext["trace"]) {
277
- delete (event.ext["trace"]);
272
+ if (event.ext && event.ext[STR_TRACE]) {
273
+ delete (event.ext[STR_TRACE]);
278
274
  }
279
- if (event.ext && event.ext["user"] && event.ext["user"]["id"]) {
280
- delete (event.ext["user"]["id"]);
275
+ if (event.ext && event.ext[STR_USER] && event.ext[STR_USER]["id"]) {
276
+ delete (event.ext[STR_USER]["id"]);
281
277
  }
282
278
 
283
279
  // v8 performance optimization for iterating over the keys
284
- if (_optimizeObject) {
280
+ if (_optimizeObject) {setProcessTelemetryTimings
285
281
  event.ext = optimizeObject(event.ext);
286
282
  if (event.baseData) {
287
283
  event.baseData = optimizeObject(event.baseData);
@@ -462,7 +458,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
462
458
  };
463
459
 
464
460
  _self.setMsaAuthTicket = (ticket: string) => {
465
- _httpManager.addHeader(strMsaDeviceTicket, ticket);
461
+ _httpManager.addHeader(STR_MSA_DEVICE_TICKET, ticket);
466
462
  };
467
463
 
468
464
  _self.hasEvents = _hasEvents;
package/src/Serializer.ts CHANGED
@@ -3,14 +3,16 @@
3
3
  * @author Abhilash Panwar (abpanwar); Hector Hernandez (hectorh); Nev Wylie (newylie)
4
4
  * @copyright Microsoft 2018-2020
5
5
  */
6
+ // @skip-file-minify
7
+
8
+ import dynamicProto from "@microsoft/dynamicproto-js";
6
9
  import {
7
- IEventProperty, getTenantId, getCommonSchemaMetaData, isArray, sanitizeProperty,
8
- IPerfManagerProvider, doPerf, isValueAssigned, IValueSanitizer, strStartsWith,
9
- FieldValueSanitizerType, FieldValueSanitizerFunc, objForEachKey, arrIndexOf, optimizeObject, SendRequestReason, EventSendType,
10
+ EventSendType, FieldValueSanitizerFunc, FieldValueSanitizerType, IEventProperty, IPerfManagerProvider, IValueSanitizer,
11
+ SendRequestReason, arrIndexOf, doPerf, getCommonSchemaMetaData, getTenantId, isArray, isValueAssigned, objForEachKey, sanitizeProperty,
12
+ strStartsWith
10
13
  } from "@microsoft/1ds-core-js";
11
- import { IPostTransmissionTelemetryItem } from "./DataModels";
14
+ import { IPostTransmissionTelemetryItem } from "./DataModels";
12
15
  import { EventBatch } from "./EventBatch";
13
- import dynamicProto from "@microsoft/dynamicproto-js";
14
16
 
15
17
  /**
16
18
  * Note: This is an optimization for V8-based browsers. When V8 concatenates a string,
@@ -1,9 +1,9 @@
1
1
  /**
2
- * TimeoutOverrideWrapper.ts
3
- * @author Nev Wylie (newylie)
4
- * @copyright Microsoft 2022
5
- * Simple internal timeout wrapper
6
- */
2
+ * TimeoutOverrideWrapper.ts
3
+ * @author Nev Wylie (newylie)
4
+ * @copyright Microsoft 2022
5
+ * Simple internal timeout wrapper
6
+ */
7
7
 
8
8
  export type TimeoutSetFunc<T = any> = (callback: (...args: any[]) => void, ms: number, ...args: any[]) => T;
9
9
  export type TimeoutClearFunc<T = any> = (timeoutId?: T) => void;
@@ -26,4 +26,4 @@ export function createTimeoutWrapper<T = any>(argSetTimeout?: TimeoutSetFunc<T>,
26
26
  set: argSetTimeout || defaultSetTimeout,
27
27
  clear: argClearTimeout || defaultClearTimeout
28
28
  }
29
- }
29
+ }