@microsoft/1ds-post-js 3.1.6 → 3.1.10

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 (60) hide show
  1. package/README.md +2 -1
  2. package/bundle/ms.post-3.1.10.gbl.js +3595 -0
  3. package/bundle/ms.post-3.1.10.gbl.js.map +1 -0
  4. package/bundle/ms.post-3.1.10.gbl.min.js +7 -0
  5. package/bundle/ms.post-3.1.10.gbl.min.js.map +1 -0
  6. package/bundle/ms.post-3.1.10.integrity.json +46 -0
  7. package/bundle/{ms.post-test.js → ms.post-3.1.10.js} +333 -163
  8. package/bundle/ms.post-3.1.10.js.map +1 -0
  9. package/bundle/ms.post-3.1.10.min.js +7 -0
  10. package/bundle/ms.post-3.1.10.min.js.map +1 -0
  11. package/bundle/{ms.post-3.1.6.gbl.js → ms.post.gbl.js} +332 -162
  12. package/bundle/ms.post.gbl.js.map +1 -0
  13. package/bundle/ms.post.gbl.min.js +7 -0
  14. package/bundle/ms.post.gbl.min.js.map +1 -0
  15. package/bundle/ms.post.integrity.json +46 -0
  16. package/bundle/{ms.post-3.1.6.js → ms.post.js} +333 -163
  17. package/bundle/ms.post.js.map +1 -0
  18. package/bundle/ms.post.min.js +7 -0
  19. package/bundle/ms.post.min.js.map +1 -0
  20. package/dist/ms.post.js +149 -89
  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 +1 -1
  26. package/dist-esm/src/Constants.d.ts +24 -0
  27. package/dist-esm/src/Constants.js +30 -0
  28. package/dist-esm/src/Constants.js.map +1 -0
  29. package/dist-esm/src/DataModels.d.ts +11 -2
  30. package/dist-esm/src/DataModels.js +1 -1
  31. package/dist-esm/src/EventBatch.d.ts +5 -2
  32. package/dist-esm/src/EventBatch.js +35 -15
  33. package/dist-esm/src/EventBatch.js.map +1 -1
  34. package/dist-esm/src/HttpManager.d.ts +1 -1
  35. package/dist-esm/src/HttpManager.js +121 -79
  36. package/dist-esm/src/HttpManager.js.map +1 -1
  37. package/dist-esm/src/Index.js +1 -1
  38. package/dist-esm/src/KillSwitch.js +1 -1
  39. package/dist-esm/src/PostChannel.js +10 -8
  40. package/dist-esm/src/PostChannel.js.map +1 -1
  41. package/dist-esm/src/RetryPolicy.js +1 -1
  42. package/dist-esm/src/Serializer.js +1 -1
  43. package/dist-esm/src/typings/XDomainRequest.js +1 -1
  44. package/package.json +3 -3
  45. package/src/Constants.ts +27 -0
  46. package/src/DataModels.ts +13 -3
  47. package/src/EventBatch.ts +47 -14
  48. package/src/HttpManager.ts +155 -85
  49. package/src/PostChannel.ts +9 -6
  50. package/bundle/ms.post-3.1.6.gbl.js.map +0 -1
  51. package/bundle/ms.post-3.1.6.gbl.min.js +0 -7
  52. package/bundle/ms.post-3.1.6.gbl.min.js.map +0 -1
  53. package/bundle/ms.post-3.1.6.integrity.json +0 -46
  54. package/bundle/ms.post-3.1.6.js.map +0 -1
  55. package/bundle/ms.post-3.1.6.min.js +0 -7
  56. package/bundle/ms.post-3.1.6.min.js.map +0 -1
  57. package/bundle/ms.post-test.integrity.json +0 -26
  58. package/bundle/ms.post-test.js.map +0 -1
  59. package/bundle/ms.post-test.min.js +0 -7
  60. package/bundle/ms.post-test.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 3.1.6
2
+ * 1DS JS SDK POST plugin, 3.1.10
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 3.1.6
2
+ * 1DS JS SDK POST plugin, 3.1.10
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -0,0 +1,24 @@
1
+ export declare const Method = "POST";
2
+ export declare const DisabledPropertyName: string;
3
+ export declare const strDropped = "drop";
4
+ export declare const strSending = "send";
5
+ export declare const strRequeue = "requeue";
6
+ export declare const strResponseFail = "rspFail";
7
+ export declare const strOther = "oth";
8
+ export declare const defaultCacheControl = "no-cache, no-store";
9
+ export declare const defaultContentType = "application/x-json-stream";
10
+ export declare const strCacheControl = "cache-control";
11
+ export declare const strContentTypeHeader = "content-type";
12
+ export declare const strKillTokensHeader = "kill-tokens";
13
+ export declare const strKillDurationHeader = "kill-duration";
14
+ export declare const strKillDurationSecondsHeader = "kill-duration-seconds";
15
+ export declare const strTimeDeltaHeader = "time-delta-millis";
16
+ export declare const strClientVersion = "client-version";
17
+ export declare const strClientId = "client-id";
18
+ export declare const strTimeDeltaToApply = "time-delta-to-apply-millis";
19
+ export declare const strUploadTime = "upload-time";
20
+ export declare const strApiKey = "apikey";
21
+ export declare const strMsaDeviceTicket = "AuthMsaDeviceTicket";
22
+ export declare const strAuthXToken = "AuthXToken";
23
+ export declare const strSdkVersion = "sdk-version";
24
+ export declare const strMsfpc = "msfpc";
@@ -0,0 +1,30 @@
1
+ /*
2
+ * 1DS JS SDK POST plugin, 3.1.10
3
+ * Copyright (c) Microsoft and contributors. All rights reserved.
4
+ * (Microsoft Internal Only)
5
+ */
6
+ export var Method = "POST";
7
+ export var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
8
+ export var strDropped = "drop";
9
+ export var strSending = "send";
10
+ export var strRequeue = "requeue";
11
+ export var strResponseFail = "rspFail";
12
+ export var strOther = "oth";
13
+ export var defaultCacheControl = "no-cache, no-store";
14
+ export var defaultContentType = "application/x-json-stream";
15
+ export var strCacheControl = "cache-control";
16
+ export var strContentTypeHeader = "content-type";
17
+ export var strKillTokensHeader = "kill-tokens";
18
+ export var strKillDurationHeader = "kill-duration";
19
+ export var strKillDurationSecondsHeader = "kill-duration-seconds";
20
+ export var strTimeDeltaHeader = "time-delta-millis";
21
+ export var strClientVersion = "client-version";
22
+ export var strClientId = "client-id";
23
+ export var strTimeDeltaToApply = "time-delta-to-apply-millis";
24
+ export var strUploadTime = "upload-time";
25
+ export var strApiKey = "apikey";
26
+ export var strMsaDeviceTicket = "AuthMsaDeviceTicket";
27
+ export var strAuthXToken = "AuthXToken";
28
+ export var strSdkVersion = "sdk-version";
29
+ export var strMsfpc = "msfpc";
30
+ //# sourceMappingURL=Constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Constants.js.map","sources":["Constants.js"],"sourcesContent":["export var Method = \"POST\";\r\nexport var DisabledPropertyName = \"Microsoft_ApplicationInsights_BypassAjaxInstrumentation\";\r\nexport var strDropped = \"drop\";\r\nexport var strSending = \"send\";\r\nexport var strRequeue = \"requeue\";\r\nexport var strResponseFail = \"rspFail\";\r\nexport var strOther = \"oth\";\r\nexport var defaultCacheControl = \"no-cache, no-store\";\r\nexport var defaultContentType = \"application/x-json-stream\";\r\nexport var strCacheControl = \"cache-control\";\r\nexport var strContentTypeHeader = \"content-type\";\r\nexport var strKillTokensHeader = \"kill-tokens\";\r\nexport var strKillDurationHeader = \"kill-duration\";\r\nexport var strKillDurationSecondsHeader = \"kill-duration-seconds\";\r\nexport var strTimeDeltaHeader = \"time-delta-millis\";\r\nexport var strClientVersion = \"client-version\";\r\nexport var strClientId = \"client-id\";\r\nexport var strTimeDeltaToApply = \"time-delta-to-apply-millis\";\r\nexport var strUploadTime = \"upload-time\";\r\nexport var strApiKey = \"apikey\";\r\nexport var strMsaDeviceTicket = \"AuthMsaDeviceTicket\";\r\nexport var strAuthXToken = \"AuthXToken\";\r\nexport var strSdkVersion = \"sdk-version\";\r\nexport var strMsfpc = \"msfpc\";\r\n//# sourceMappingURL=Constants.js.map"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
@@ -112,8 +112,11 @@ export interface IChannelConfiguration {
112
112
  */
113
113
  stringifyObjects?: boolean;
114
114
  /**
115
- * [Optional] Enables support for objects with compound keys which indirectly represent an object eg. event: { "somedata.embeddedvalue": 123 }
116
- * where the "key" of the object contains a "." as part of it's name.
115
+ * [Optional] Enables support for objects with compound keys which indirectly represent an object where the "key" of the object contains a "." as part of it's name.
116
+ * @example
117
+ * ```typescript
118
+ * event: { "somedata.embeddedvalue": 123 }
119
+ * ```
117
120
  */
118
121
  enableCompoundKey?: boolean;
119
122
  /**
@@ -129,6 +132,12 @@ export interface IChannelConfiguration {
129
132
  * This is used during initialization to identify the requested send transport, it will be ignored if a httpXHROverride is provided.
130
133
  */
131
134
  transports?: number | number[];
135
+ /**
136
+ * [Optional] Avoid adding request headers to the outgoing request that would cause a pre-flight (OPTIONS) request to be sent for each request.
137
+ * This currently defaults to true but will be changed once the collector handles additional settings to allow the browser to better cache any
138
+ * previous OPTIONS response, at which point some of the current dynamic values sent on the query string will be moved to a header.
139
+ */
140
+ avoidOptions?: boolean;
132
141
  }
133
142
  /**
134
143
  * SendPOSTFunction type defines how an HTTP POST request is sent to an ingestion server
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 3.1.6
2
+ * 1DS JS SDK POST plugin, 3.1.10
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -20,6 +20,10 @@ export declare class EventBatch {
20
20
  * Returns the iKey associated with this batch of events
21
21
  */
22
22
  iKey: () => string;
23
+ /**
24
+ * Returns the first msfpc value from the batch
25
+ */
26
+ Msfpc: () => string;
23
27
  /**
24
28
  * Returns the number of events contained in the batch
25
29
  */
@@ -29,10 +33,9 @@ export declare class EventBatch {
29
33
  * Add all of the events to the current batch, if the max number of events would be exceeded then no
30
34
  * events are added.
31
35
  * @param theEvents - The events that needs to be batched.
32
- * @param append - True (default) add the event to the end of the queue otherwise prepend (used for re-queuing)
33
36
  * @returns The number of events added.
34
37
  */
35
- addEvents: (theEvents: IPostTransmissionTelemetryItem[], append: boolean) => number;
38
+ addEvent: (theEvents: IPostTransmissionTelemetryItem) => boolean;
36
39
  /**
37
40
  * Split this batch into 2 with any events > fromEvent returned in the new batch and all other
38
41
  * events are kept in the current batch.
@@ -1,9 +1,24 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 3.1.6
2
+ * 1DS JS SDK POST plugin, 3.1.10
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
6
- import { isNullOrUndefined } from "@microsoft/1ds-core-js";
6
+ import { isNullOrUndefined, isValueAssigned } from "@microsoft/1ds-core-js";
7
+ import { strMsfpc } from "./Constants";
8
+ function _getEventMsfpc(theEvent) {
9
+ var intWeb = ((theEvent.ext || {})["intweb"]);
10
+ if (intWeb && isValueAssigned(intWeb[strMsfpc])) {
11
+ return intWeb[strMsfpc];
12
+ }
13
+ return null;
14
+ }
15
+ function _getMsfpc(theEvents) {
16
+ var msfpc = null;
17
+ for (var lp = 0; msfpc === null && lp < theEvents.length; lp++) {
18
+ msfpc = _getEventMsfpc(theEvents[lp]);
19
+ }
20
+ return msfpc;
21
+ }
7
22
  /**
8
23
  * This class defines a "batch" events related to a specific iKey, it is used by the PostChannel and HttpManager
9
24
  * to collect and transfer ownership of events without duplicating them in-memory. This reduces the previous
@@ -19,39 +34,44 @@ var EventBatch = /** @class */ (function () {
19
34
  function EventBatch(iKey, addEvents) {
20
35
  var events = addEvents ? [].concat(addEvents) : [];
21
36
  var _self = this;
37
+ var _msfpc = _getMsfpc(events);
22
38
  _self.iKey = function () {
23
39
  return iKey;
24
40
  };
41
+ _self.Msfpc = function () {
42
+ // return the cached value unless it's undefined -- used to avoid cpu
43
+ return _msfpc || "";
44
+ };
25
45
  _self.count = function () {
26
46
  return events.length;
27
47
  };
28
48
  _self.events = function () {
29
49
  return events;
30
50
  };
31
- _self.addEvents = function (theEvents, append) {
32
- if (append === void 0) { append = true; }
33
- if (theEvents && theEvents.length > 0) {
34
- if (append) {
35
- events = events.concat(theEvents);
36
- }
37
- else {
38
- events = theEvents.concat(events);
51
+ _self.addEvent = function (theEvent) {
52
+ if (theEvent) {
53
+ events.push(theEvent);
54
+ if (!_msfpc) {
55
+ // Not found so try and find one
56
+ _msfpc = _getEventMsfpc(theEvent);
39
57
  }
40
- return theEvents.length;
58
+ return true;
41
59
  }
42
- return 0;
60
+ return false;
43
61
  };
44
62
  _self.split = function (fromEvent, numEvents) {
45
63
  // Create a new batch with the same iKey
46
- var newBatch = new EventBatch(iKey);
64
+ var theEvents;
47
65
  if (fromEvent < events.length) {
48
66
  var cnt = events.length - fromEvent;
49
67
  if (!isNullOrUndefined(numEvents)) {
50
68
  cnt = numEvents < cnt ? numEvents : cnt;
51
69
  }
52
- newBatch.addEvents(events.splice(fromEvent, cnt), true);
70
+ theEvents = events.splice(fromEvent, cnt);
71
+ // reset the fetched msfpc value
72
+ _msfpc = _getMsfpc(events);
53
73
  }
54
- return newBatch;
74
+ return new EventBatch(iKey, theEvents);
55
75
  };
56
76
  }
57
77
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"EventBatch.js.map","sources":["EventBatch.js"],"sourcesContent":["import { isNullOrUndefined } from \"@microsoft/1ds-core-js\";\r\n/**\r\n* This class defines a \"batch\" events related to a specific iKey, it is used by the PostChannel and HttpManager\r\n* to collect and transfer ownership of events without duplicating them in-memory. This reduces the previous\r\n* array duplication and shared ownership issues that occurred due to race conditions caused by the async nature\r\n* of sending requests.\r\n*/\r\nvar EventBatch = /** @class */ (function () {\r\n /**\r\n * Private constructor so that caller is forced to use the static create method.\r\n * @param iKey - The iKey to associate with the events (not validated)\r\n * @param addEvents - The optional collection of events to assign to this batch - defaults to an empty array.\r\n */\r\n function EventBatch(iKey, addEvents) {\r\n var events = addEvents ? [].concat(addEvents) : [];\r\n var _self = this;\r\n _self.iKey = function () {\r\n return iKey;\r\n };\r\n _self.count = function () {\r\n return events.length;\r\n };\r\n _self.events = function () {\r\n return events;\r\n };\r\n _self.addEvents = function (theEvents, append) {\r\n if (append === void 0) { append = true; }\r\n if (theEvents && theEvents.length > 0) {\r\n if (append) {\r\n events = events.concat(theEvents);\r\n }\r\n else {\r\n events = theEvents.concat(events);\r\n }\r\n return theEvents.length;\r\n }\r\n return 0;\r\n };\r\n _self.split = function (fromEvent, numEvents) {\r\n // Create a new batch with the same iKey\r\n var newBatch = new EventBatch(iKey);\r\n if (fromEvent < events.length) {\r\n var cnt = events.length - fromEvent;\r\n if (!isNullOrUndefined(numEvents)) {\r\n cnt = numEvents < cnt ? numEvents : cnt;\r\n }\r\n newBatch.addEvents(events.splice(fromEvent, cnt), true);\r\n }\r\n return newBatch;\r\n };\r\n }\r\n /**\r\n * Creates a new Event Batch object\r\n * @param iKey The iKey associated with this batch of events\r\n */\r\n EventBatch.create = function (iKey, theEvents) {\r\n return new EventBatch(iKey, theEvents);\r\n };\r\n return EventBatch;\r\n}());\r\nexport { EventBatch };\r\n//# sourceMappingURL=EventBatch.js.map"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
1
+ {"version":3,"file":"EventBatch.js.map","sources":["EventBatch.js"],"sourcesContent":["import { isNullOrUndefined, isValueAssigned } from \"@microsoft/1ds-core-js\";\r\nimport { strMsfpc } from \"./Constants\";\r\nfunction _getEventMsfpc(theEvent) {\r\n var intWeb = ((theEvent.ext || {})[\"intweb\"]);\r\n if (intWeb && isValueAssigned(intWeb[strMsfpc])) {\r\n return intWeb[strMsfpc];\r\n }\r\n return null;\r\n}\r\nfunction _getMsfpc(theEvents) {\r\n var msfpc = null;\r\n for (var lp = 0; msfpc === null && lp < theEvents.length; lp++) {\r\n msfpc = _getEventMsfpc(theEvents[lp]);\r\n }\r\n return msfpc;\r\n}\r\n/**\r\n* This class defines a \"batch\" events related to a specific iKey, it is used by the PostChannel and HttpManager\r\n* to collect and transfer ownership of events without duplicating them in-memory. This reduces the previous\r\n* array duplication and shared ownership issues that occurred due to race conditions caused by the async nature\r\n* of sending requests.\r\n*/\r\nvar EventBatch = /** @class */ (function () {\r\n /**\r\n * Private constructor so that caller is forced to use the static create method.\r\n * @param iKey - The iKey to associate with the events (not validated)\r\n * @param addEvents - The optional collection of events to assign to this batch - defaults to an empty array.\r\n */\r\n function EventBatch(iKey, addEvents) {\r\n var events = addEvents ? [].concat(addEvents) : [];\r\n var _self = this;\r\n var _msfpc = _getMsfpc(events);\r\n _self.iKey = function () {\r\n return iKey;\r\n };\r\n _self.Msfpc = function () {\r\n // return the cached value unless it's undefined -- used to avoid cpu\r\n return _msfpc || \"\";\r\n };\r\n _self.count = function () {\r\n return events.length;\r\n };\r\n _self.events = function () {\r\n return events;\r\n };\r\n _self.addEvent = function (theEvent) {\r\n if (theEvent) {\r\n events.push(theEvent);\r\n if (!_msfpc) {\r\n // Not found so try and find one\r\n _msfpc = _getEventMsfpc(theEvent);\r\n }\r\n return true;\r\n }\r\n return false;\r\n };\r\n _self.split = function (fromEvent, numEvents) {\r\n // Create a new batch with the same iKey\r\n var theEvents;\r\n if (fromEvent < events.length) {\r\n var cnt = events.length - fromEvent;\r\n if (!isNullOrUndefined(numEvents)) {\r\n cnt = numEvents < cnt ? numEvents : cnt;\r\n }\r\n theEvents = events.splice(fromEvent, cnt);\r\n // reset the fetched msfpc value\r\n _msfpc = _getMsfpc(events);\r\n }\r\n return new EventBatch(iKey, theEvents);\r\n };\r\n }\r\n /**\r\n * Creates a new Event Batch object\r\n * @param iKey The iKey associated with this batch of events\r\n */\r\n EventBatch.create = function (iKey, theEvents) {\r\n return new EventBatch(iKey, theEvents);\r\n };\r\n return EventBatch;\r\n}());\r\nexport { EventBatch };\r\n//# sourceMappingURL=EventBatch.js.map"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
@@ -11,7 +11,7 @@ import { IChannelConfiguration } from "./Index";
11
11
  /**
12
12
  * Class managing the sending of requests.
13
13
  */
14
- export default class HttpManager {
14
+ export declare class HttpManager {
15
15
  sendHook: PayloadPreprocessorFunction | undefined;
16
16
  sendListener: PayloadListenerFunction | undefined;
17
17
  _responseHandlers: Array<(responseText: string) => void>;
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 3.1.6
2
+ * 1DS JS SDK POST plugin, 3.1.10
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -9,27 +9,13 @@ var _a;
9
9
  * @author Abhilash Panwar (abpanwar); Hector Hernandez (hectorh); Nev Wylie (newylie)
10
10
  * @copyright Microsoft 2018-2020
11
11
  */
12
- import { isReactNative, isValueAssigned, isString, getTime, arrForEach, getLocation, strTrim, isFetchSupported, isXhrSupported, isBeaconsSupported, FullVersionString, useXDomainRequest, LoggingSeverity, _ExtendedInternalMessageId, strUndefined, getNavigator, doPerf, dateNow, isUndefined, isNullOrUndefined, objForEachKey, isNumber, isArray, dumpObj, objKeys, extend, hasOwnProperty } from "@microsoft/1ds-core-js";
12
+ import { isReactNative, isValueAssigned, isString, getTime, arrForEach, getLocation, strTrim, isFetchSupported, isXhrSupported, isBeaconsSupported, FullVersionString, useXDomainRequest, LoggingSeverity, _ExtendedInternalMessageId, strUndefined, getNavigator, doPerf, dateNow, isUndefined, isNullOrUndefined, objForEachKey, isNumber, isArray, dumpObj, objKeys, extend, hasOwnProperty, openXhr } from "@microsoft/1ds-core-js";
13
13
  import { Serializer } from "./Serializer";
14
14
  import RetryPolicy from "./RetryPolicy";
15
15
  import EVTKillSwitch from "./KillSwitch";
16
16
  import EVTClockSkewManager from "./ClockSkewManager";
17
17
  import dynamicProto from "@microsoft/dynamicproto-js";
18
- var Method = "POST";
19
- var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
20
- var strDropped = "drop";
21
- var strSending = "send";
22
- var strRequeue = "requeue";
23
- var strResponseFail = "rspFail";
24
- var strOther = "oth";
25
- var defaultCacheControl = "no-cache, no-store";
26
- var defaultContentType = "application/x-json-stream";
27
- var strCacheControl = "cache-control";
28
- var strContentTypeHeader = "content-type";
29
- var strKillTokensHeader = "kill-tokens";
30
- var strKillDurationHeader = "kill-duration";
31
- var strKillDurationSecondsHeader = "kill-duration-seconds";
32
- var strTimeDeltaHeader = "time-delta-millis";
18
+ import { defaultCacheControl, defaultContentType, DisabledPropertyName, Method, strApiKey, strCacheControl, strClientId, strClientVersion, strContentTypeHeader, strDropped, strKillDurationHeader, strKillDurationSecondsHeader, strKillTokensHeader, strMsaDeviceTicket, strMsfpc, strOther, strRequeue, strResponseFail, strSending, strTimeDeltaHeader, strTimeDeltaToApply, strUploadTime } from "./Constants";
33
19
  /**
34
20
  * Identifies the default notification reason to the action names
35
21
  */
@@ -40,6 +26,13 @@ var _eventActionMap = (_a = {},
40
26
  _a[8004 /* KillSwitch */] = strDropped,
41
27
  _a[8003 /* SizeLimitExceeded */] = strDropped,
42
28
  _a);
29
+ var _collectorQsHeaders = {};
30
+ var _collectorHeaderToQs = {};
31
+ function _addCollectorHeaderQsMapping(qsName, headerName) {
32
+ _collectorQsHeaders[qsName] = headerName;
33
+ _collectorHeaderToQs[headerName] = qsName;
34
+ }
35
+ _addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket);
43
36
  function _getResponseText(xhr) {
44
37
  try {
45
38
  return xhr.responseText;
@@ -67,6 +60,17 @@ function _hasHeader(headers, header) {
67
60
  }
68
61
  return hasHeader;
69
62
  }
63
+ function _addRequestDetails(details, name, value, useHeaders) {
64
+ if (name && value && value.length > 0) {
65
+ if (useHeaders && _collectorQsHeaders[name]) {
66
+ details.hdrs[_collectorQsHeaders[name]] = value;
67
+ details.useHdrs = true;
68
+ }
69
+ else {
70
+ details.url += "&" + name + "=" + value;
71
+ }
72
+ }
73
+ }
70
74
  /**
71
75
  * Class managing the sending of requests.
72
76
  */
@@ -77,8 +81,7 @@ var HttpManager = /** @class */ (function () {
77
81
  */
78
82
  function HttpManager(maxEventsPerBatch, maxConnections, maxRetries, actions) {
79
83
  this._responseHandlers = [];
80
- var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType + "&client-id=NO_AUTH&client-version="
81
- + FullVersionString;
84
+ var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType;
82
85
  var _killSwitch = new EVTKillSwitch();
83
86
  var _paused = false;
84
87
  var _clockSkewManager = new EVTClockSkewManager();
@@ -95,6 +98,7 @@ var HttpManager = /** @class */ (function () {
95
98
  var _enableEventTimings = false;
96
99
  var _cookieMgr;
97
100
  var _isUnloading = false;
101
+ var _useHeaders = false;
98
102
  dynamicProto(HttpManager, this, function (_self) {
99
103
  var _sendCredentials = true;
100
104
  _self.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {
@@ -103,6 +107,8 @@ var HttpManager = /** @class */ (function () {
103
107
  channelConfig = {};
104
108
  }
105
109
  _urlString = endpointUrl + _urlString;
110
+ // Task 12886642: Defaulting to 'false' until the Collector handles sending upload-time header in the OPTIONS call
111
+ _useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : false;
106
112
  _core = core;
107
113
  _cookieMgr = core.getCookieMgr();
108
114
  _enableEventTimings = !_core.config.disableEventTimings;
@@ -113,12 +119,6 @@ var HttpManager = /** @class */ (function () {
113
119
  if (!isUndefined(channelConfig.enableCompoundKey)) {
114
120
  enableCompoundKey = !!channelConfig.enableCompoundKey;
115
121
  }
116
- // For this to work the collection MUST return "Cache-control" in the OPTIONS response in the Allow-Control-Allow-Headers
117
- // ONLY un-comment the below once the collector has changed and deployed.
118
- // if (!!channelConfig.disableCacheHeader) {
119
- // // Stop Chrome from stalling/throttling requests see task #7178858
120
- // _self.addHeader("Cache-control", "no-cache, no-store");
121
- // }
122
122
  _useBeacons = !isReactNative(); // Only use beacons if not running in React Native
123
123
  _serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);
124
124
  var syncHttpInterface = httpInterface;
@@ -229,6 +229,8 @@ var HttpManager = /** @class */ (function () {
229
229
  }
230
230
  function _fetchSendPost(payload, oncomplete, sync) {
231
231
  var _a;
232
+ var ignoreResponse = false;
233
+ var responseHandled = false;
232
234
  var requestInit = (_a = {
233
235
  body: payload.data,
234
236
  method: Method
@@ -237,6 +239,11 @@ var HttpManager = /** @class */ (function () {
237
239
  _a);
238
240
  if (sync) {
239
241
  requestInit.keepalive = true;
242
+ if (payload._sendReason === 2 /* Unload */) {
243
+ // As a sync request (during unload), it is unlikely that we will get a chance to process the response so
244
+ // just like beacon send assume that the events have been accepted and processed
245
+ ignoreResponse = true;
246
+ }
240
247
  }
241
248
  if (_sendCredentials) {
242
249
  // Don't send credentials when URL is file://
@@ -259,13 +266,24 @@ var HttpManager = /** @class */ (function () {
259
266
  responseText = text;
260
267
  });
261
268
  }
262
- _doOnComplete(oncomplete, response.status, headerMap, responseText);
263
- _handleCollectorResponse(responseText);
269
+ if (!responseHandled) {
270
+ responseHandled = true;
271
+ _doOnComplete(oncomplete, response.status, headerMap, responseText);
272
+ _handleCollectorResponse(responseText);
273
+ }
264
274
  })["catch"](function (error) {
265
275
  // In case there is an error in the request. Set the status to 0
266
276
  // so that the events can be retried later.
267
- _doOnComplete(oncomplete, 0, {});
277
+ if (!responseHandled) {
278
+ responseHandled = true;
279
+ _doOnComplete(oncomplete, 0, {});
280
+ }
268
281
  });
282
+ if (ignoreResponse && !responseHandled) {
283
+ // Assume success during unload processing
284
+ responseHandled = true;
285
+ _doOnComplete(oncomplete, 200, {});
286
+ }
269
287
  }
270
288
  function _xhrSendPost(payload, oncomplete, sync) {
271
289
  function _appendHeader(theHeaders, xhr, name) {
@@ -295,19 +313,7 @@ var HttpManager = /** @class */ (function () {
295
313
  function xhrComplete(xhr, responseTxt) {
296
314
  _doOnComplete(oncomplete, xhr.status, _getAllResponseHeaders(xhr), responseTxt);
297
315
  }
298
- var xhRequest = new XMLHttpRequest();
299
- try {
300
- xhRequest[DisabledPropertyName] = true;
301
- }
302
- catch (e) {
303
- // If the environment has locked down the XMLHttpRequest (preventExtensions and/or freeze), this would
304
- // cause the request to fail and we no telemetry would be sent
305
- }
306
- if (_sendCredentials) {
307
- // Special case where a local html file fails with a CORS error on Chromium browsers (protocol is only evaluated on initialization)
308
- xhRequest.withCredentials = true;
309
- }
310
- xhRequest.open(Method, payload.urlString, !sync);
316
+ var xhRequest = openXhr(Method, payload.urlString, _sendCredentials, true, sync);
311
317
  // Set custom headers (e.g. gzip) here (after open())
312
318
  objForEachKey(payload.headers, function (name, value) {
313
319
  xhRequest.setRequestHeader(name, value);
@@ -575,8 +581,34 @@ var HttpManager = /** @class */ (function () {
575
581
  _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.CannotSerializeObject, "Unexpected Exception sending batch: " + dumpObj(ex));
576
582
  }
577
583
  }
578
- function _buildQueryString(thePayload) {
579
- var urlString = _urlString;
584
+ function _buildRequestDetails(thePayload, useHeaders) {
585
+ var requestDetails = {
586
+ url: _urlString,
587
+ hdrs: {},
588
+ useHdrs: false // Assume no headers
589
+ };
590
+ // ----------------------------------------------------------------------------------------------------------------
591
+ // Task 12886642: Need to wait until an updated version of the collector is released to return these as allowed in the OPTIONS call
592
+ // ----------------------------------------------------------------------------------------------------------------
593
+ // if (!useHeaders) {
594
+ // // Attempt to map headers to a query string if possible
595
+ // objForEachKey(_headers, (name, value) => {
596
+ // if (_collectorHeaderToQs[name]) {
597
+ // _addRequestDetails(requestDetails, _collectorHeaderToQs[name], value, false);
598
+ // } else {
599
+ // // No mapping, so just include in the headers anyway (may not get sent if using sendBeacon())
600
+ // requestDetails.hdrs[name] = value;
601
+ // requestDetails.useHdrs = true;
602
+ // }
603
+ // });
604
+ // } else {
605
+ // Copy the pre-defined headers into the payload headers
606
+ requestDetails.hdrs = extend(requestDetails.hdrs, _headers);
607
+ requestDetails.useHdrs = (objKeys(requestDetails.hdrs).length > 0);
608
+ // }
609
+ // ----------------------------------------------------------------------------------------------------------------
610
+ _addRequestDetails(requestDetails, strClientId, "NO_AUTH", useHeaders);
611
+ _addRequestDetails(requestDetails, strClientVersion, FullVersionString, useHeaders);
580
612
  var apiQsKeys = "";
581
613
  arrForEach(thePayload.apiKeys, function (apiKey) {
582
614
  if (apiQsKeys.length > 0) {
@@ -584,27 +616,25 @@ var HttpManager = /** @class */ (function () {
584
616
  }
585
617
  apiQsKeys += apiKey;
586
618
  });
587
- if (apiQsKeys.length > 0) {
588
- urlString += "&apikey=" + apiQsKeys;
589
- }
590
- urlString += "&upload-time=" + dateNow().toString();
619
+ _addRequestDetails(requestDetails, strApiKey, apiQsKeys, useHeaders);
620
+ _addRequestDetails(requestDetails, strUploadTime, dateNow().toString(), useHeaders);
591
621
  var msfpc = _getMsfpc(thePayload);
592
622
  if (isValueAssigned(msfpc)) {
593
- urlString = urlString + "&ext.intweb.msfpc=" + msfpc;
623
+ requestDetails.url += "&ext.intweb.msfpc=" + msfpc;
594
624
  }
595
625
  if (_clockSkewManager.shouldAddClockSkewHeaders()) {
596
- urlString += "&time-delta-to-apply-millis=" + _clockSkewManager.getClockSkewHeaderValue();
626
+ _addRequestDetails(requestDetails, strTimeDeltaToApply, _clockSkewManager.getClockSkewHeaderValue(), useHeaders);
597
627
  }
598
628
  if (_core.getWParam) {
599
629
  var wParam = _core.getWParam();
600
630
  if (wParam >= 0) {
601
- urlString += "&w=" + wParam;
631
+ requestDetails.url += "&w=" + wParam;
602
632
  }
603
633
  }
604
634
  for (var i = 0; i < _queryStringParameters.length; i++) {
605
- urlString += "&" + _queryStringParameters[i].name + "=" + _queryStringParameters[i].value;
635
+ requestDetails.url += "&" + _queryStringParameters[i].name + "=" + _queryStringParameters[i].value;
606
636
  }
607
- return urlString;
637
+ return requestDetails;
608
638
  }
609
639
  function _canUseSendBeaconApi() {
610
640
  return !_customHttpInterface && _useBeacons && isBeaconsSupported();
@@ -615,7 +645,19 @@ var HttpManager = /** @class */ (function () {
615
645
  }
616
646
  function _doPayloadSend(thePayload, serializationStart, serializationCompleted, sendReason) {
617
647
  if (thePayload && thePayload.payloadBlob && thePayload.payloadBlob.length > 0) {
618
- var urlString_1 = _buildQueryString(thePayload);
648
+ var useSendHook_1 = !!_self.sendHook;
649
+ var sendInterface_1 = _sendInterfaces[thePayload.sendType];
650
+ // Send all data using a beacon style transport if closing mode is on or channel was teared down
651
+ if (!_isBeaconPayload(thePayload.sendType) && thePayload.isBeacon && thePayload.sendReason === 2 /* Unload */) {
652
+ sendInterface_1 = _sendInterfaces[2 /* SendBeacon */] || _sendInterfaces[3 /* SyncFetch */] || sendInterface_1;
653
+ }
654
+ var useHeaders_1 = _useHeaders;
655
+ // Disable header usage if we know we are using sendBeacon as additional headers are not supported
656
+ if (thePayload.isBeacon || sendInterface_1._transport === 3 /* Beacon */) {
657
+ useHeaders_1 = false;
658
+ }
659
+ var requestDetails_1 = _buildRequestDetails(thePayload, useHeaders_1);
660
+ useHeaders_1 = useHeaders_1 || requestDetails_1.useHdrs;
619
661
  var sendEventStart_1 = getTime();
620
662
  var strSendAttempt_1 = "sendAttempt";
621
663
  doPerf(_core, function () { return "HttpManager:_doPayloadSend"; }, function () {
@@ -636,27 +678,27 @@ var HttpManager = /** @class */ (function () {
636
678
  }
637
679
  // Note: always sending this notification in a synchronous manner.
638
680
  _sendBatchesNotification(thePayload.batches, (1000 /* SendingUndefined */ + (sendReason || 0 /* Undefined */)), thePayload.sendType, true);
681
+ // Disabling the use of const because of Issue:
682
+ // - Task 9227844: [1DS] Some environments and packagers automatically "freeze" objects which are defined as const which causes any mutations to throw
683
+ // eslint-disable-next-line prefer-const
639
684
  var orgPayloadData = {
640
685
  data: thePayload.payloadBlob,
641
- urlString: urlString_1,
642
- headers: extend({}, _headers),
686
+ urlString: requestDetails_1.url,
687
+ headers: requestDetails_1.hdrs,
643
688
  _thePayload: thePayload,
644
689
  _sendReason: sendReason
645
690
  };
646
- if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {
647
- orgPayloadData.headers[strCacheControl] = defaultCacheControl;
648
- }
649
- if (!_hasHeader(orgPayloadData.headers, strContentTypeHeader)) {
650
- orgPayloadData.headers[strContentTypeHeader] = defaultContentType;
691
+ // Only automatically add the following headers if already sending headers and we are not attempting to avoid an options call
692
+ if (useHeaders_1) {
693
+ if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {
694
+ orgPayloadData.headers[strCacheControl] = defaultCacheControl;
695
+ }
696
+ if (!_hasHeader(orgPayloadData.headers, strContentTypeHeader)) {
697
+ orgPayloadData.headers[strContentTypeHeader] = defaultContentType;
698
+ }
651
699
  }
652
700
  var sender = null;
653
- var useSendHook = !!_self.sendHook;
654
- var sendInterface = _sendInterfaces[thePayload.sendType];
655
- // Send all data using a beacon style transport if closing mode is on or channel was teared down
656
- if (!_isBeaconPayload(thePayload.sendType) && thePayload.isBeacon && thePayload.sendReason === 2 /* Unload */) {
657
- sendInterface = _sendInterfaces[2 /* SendBeacon */] || _sendInterfaces[3 /* SyncFetch */] || sendInterface;
658
- }
659
- if (sendInterface) {
701
+ if (sendInterface_1) {
660
702
  // Send sync requests if the request is immediate or we are tearing down telemetry.
661
703
  sender = function (payload) {
662
704
  // Notify the clock skew manager that we are sending the first request (Potentially blocking all further requests)
@@ -666,7 +708,7 @@ var HttpManager = /** @class */ (function () {
666
708
  };
667
709
  var isSync = thePayload.isTeardown || thePayload.isSync;
668
710
  try {
669
- sendInterface.sendPOST(payload, onComplete, isSync);
711
+ sendInterface_1.sendPOST(payload, onComplete, isSync);
670
712
  if (_self.sendListener) {
671
713
  // Send the original payload to the listener
672
714
  _self.sendListener(orgPayloadData, payload, isSync, thePayload.isBeacon);
@@ -684,13 +726,16 @@ var HttpManager = /** @class */ (function () {
684
726
  _outstandingRequests++;
685
727
  }
686
728
  // Only call the hook if it's defined and we are not using sendBeacon as additional headers are not supported
687
- if (useSendHook && !thePayload.isBeacon && sendInterface._transport !== 3 /* Beacon */) {
729
+ if (useSendHook_1 && !thePayload.isBeacon && sendInterface_1._transport !== 3 /* Beacon */) {
688
730
  // Create a new IPayloadData that is sent into the hook method, so that the hook method
689
731
  // can't change the object references to the orgPayloadData (it can still change the content -- mainly the headers)
732
+ // Disabling the use of const because of Issue:
733
+ // - Task 9227844: [1DS] Some environments and packagers automatically "freeze" objects which are defined as const which causes any mutations to throw
734
+ // eslint-disable-next-line prefer-const
690
735
  var hookData_1 = {
691
736
  data: orgPayloadData.data,
692
737
  urlString: orgPayloadData.urlString,
693
- headers: orgPayloadData.headers
738
+ headers: extend({}, orgPayloadData.headers)
694
739
  };
695
740
  var senderCalled_1 = false;
696
741
  doPerf(_core, function () { return "HttpManager:_doPayloadSend.sendHook"; }, function () {
@@ -886,12 +931,9 @@ var HttpManager = /** @class */ (function () {
886
931
  }
887
932
  function _getMsfpc(thePayload) {
888
933
  for (var lp = 0; lp < thePayload.batches.length; lp++) {
889
- var batchEvents = thePayload.batches[lp].events();
890
- for (var evtLp = 0; evtLp < batchEvents.length; evtLp++) {
891
- var intWeb = ((batchEvents[evtLp].ext || {})["intweb"] || {});
892
- if (isValueAssigned(intWeb["msfpc"])) {
893
- return encodeURIComponent(intWeb["msfpc"]);
894
- }
934
+ var msfpc = thePayload.batches[lp].Msfpc();
935
+ if (msfpc) {
936
+ return encodeURIComponent(msfpc);
895
937
  }
896
938
  }
897
939
  return "";
@@ -909,9 +951,9 @@ var HttpManager = /** @class */ (function () {
909
951
  }
910
952
  if (responseText) {
911
953
  var response = JSON.parse(responseText);
912
- if (isValueAssigned(response.webResult) && isValueAssigned(response.webResult.msfpc)) {
954
+ if (isValueAssigned(response.webResult) && isValueAssigned(response.webResult[strMsfpc])) {
913
955
  // Set cookie
914
- _cookieMgr.set("MSFPC", response.webResult.msfpc, 365 * 86400);
956
+ _cookieMgr.set("MSFPC", response.webResult[strMsfpc], 365 * 86400);
915
957
  }
916
958
  }
917
959
  }
@@ -969,5 +1011,5 @@ var HttpManager = /** @class */ (function () {
969
1011
  // Removed Stub for HttpManager.prototype.sendSynchronousBatch.
970
1012
  return HttpManager;
971
1013
  }());
972
- export default HttpManager;
1014
+ export { HttpManager };
973
1015
  //# sourceMappingURL=HttpManager.js.map