@microsoft/applicationinsights-offlinechannel-js 0.3.3-nightly3.2409-09 → 0.3.3-nightly3.2409-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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-09
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-10
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -7,14 +7,14 @@
7
7
  import { EventPersistence } from "@microsoft/applicationinsights-common";
8
8
  import { generateW3CId } from "@microsoft/applicationinsights-core-js";
9
9
  import { isNumber, isString, objKeys, strSubstr } from "@nevware21/ts-utils";
10
- import { _DYN_CHAR_AT, _DYN_CHAR_CODE_AT, _DYN_DATA, _DYN_FROM_CHAR_CODE, _DYN_GET_TIME, _DYN_INDEX_OF, _DYN_LENGTH, _DYN_PERSISTENCE, _DYN_SPLIT, _DYN_TO_STRING } from "../__DynamicConstants";
10
+ import { _DYN_CHAR_AT, _DYN_CHAR_CODE_AT, _DYN_DATA, _DYN_FROM_CHAR_CODE, _DYN_GET_TIME, _DYN_INDEX_OF, _DYN_LENGTH, _DYN_PERSISTENCE, _DYN_SPLIT, _DYN_TO_STRING, _DYN__CRITICAL, _DYN__NORMAL } from "../__DynamicConstants";
11
11
  /**
12
12
  * Checks if the value is a valid EventPersistence.
13
13
  * @param {enum} value - The value that needs to be checked.
14
14
  * @return {boolean} True if the value is in EventPersistence, false otherwise.
15
15
  */
16
16
  export function isValidPersistenceLevel(value) {
17
- return (isNumber(value) && value >= 0 /* eLoggingSeverity.DISABLED */ && value <= EventPersistence.Critical);
17
+ return (isNumber(value) && value >= 0 /* eLoggingSeverity.DISABLED */ && value <= EventPersistence[_DYN__CRITICAL /* @min:%2eCritical */]);
18
18
  }
19
19
  // Endpoint schema
20
20
  // <prefix>.<suffix>
@@ -161,7 +161,7 @@ export function getTimeFromId(id) {
161
161
  * @returns persistent level
162
162
  */
163
163
  export function getPersistence(item) {
164
- var rlt = EventPersistence.Normal;
164
+ var rlt = EventPersistence[_DYN__NORMAL /* @min:%2eNormal */];
165
165
  // if item is null, return normal level
166
166
  if (!item) {
167
167
  return rlt;
@@ -1 +1 @@
1
- {"version":3,"file":"Utils.js.map","sources":["Utils.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { EventPersistence } from \"@microsoft/applicationinsights-common\";\r\nimport { generateW3CId } from \"@microsoft/applicationinsights-core-js\";\r\nimport { isNumber, isString, objKeys, strSubstr } from \"@nevware21/ts-utils\";\r\nimport { _DYN_CHAR_AT, _DYN_CHAR_CODE_AT, _DYN_DATA, _DYN_FROM_CHAR_CODE, _DYN_GET_TIME, _DYN_INDEX_OF, _DYN_LENGTH, _DYN_PERSISTENCE, _DYN_SPLIT, _DYN_TO_STRING } from \"../__DynamicConstants\";\r\n/**\r\n* Checks if the value is a valid EventPersistence.\r\n* @param {enum} value - The value that needs to be checked.\r\n* @return {boolean} True if the value is in EventPersistence, false otherwise.\r\n*/\r\nexport function isValidPersistenceLevel(value) {\r\n return (isNumber(value) && value >= 0 /* eLoggingSeverity.DISABLED */ && value <= EventPersistence.Critical);\r\n}\r\n// Endpoint schema\r\n// <prefix>.<suffix>\r\n//Prefix: Defines a service.\r\n//Suffix: Defines the common domain name.\r\n/**\r\n * Get domian from an endpoint url.\r\n * for example, https://test.com?auth=true, will return test.com\r\n * @param endpoint endpoint url\r\n * @returns domain string\r\n */\r\nexport function getEndpointDomain(endpoint) {\r\n try {\r\n var url = endpoint.replace(/^https?:\\/\\/|^www\\./, \"\");\r\n url = url.replace(/\\?/, \"/\");\r\n var arr = url[_DYN_SPLIT /* @min:%2esplit */](\"/\");\r\n if (arr && arr[_DYN_LENGTH /* @min:%2elength */] > 0) {\r\n return arr[0];\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n // if we can't get domain, entire endpoint will be used\r\n return endpoint;\r\n}\r\n/**\r\n * If current value is equal or greater than zero.\r\n * @param value number\r\n * @returns boolean\r\n */\r\nexport function isGreaterThanZero(value) {\r\n return value >= 0;\r\n}\r\n//Base64 is a binary encoding rather than a text encoding,\r\n// it were added to the web platform before it supported binary data types.\r\n// As a result, the two functions use strings to represent binary data\r\nvar _base64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\";\r\n/**\r\n * Base64-encodes a Uint8Array.\r\n *\r\n * @param data the Uint8Array or string to encode.\r\n *\r\n * @return the base64-encoded output string.\r\n */\r\nexport function base64Encode(data) {\r\n var line = \"\";\r\n var input = \"\";\r\n if (isString(data)) {\r\n input = data;\r\n }\r\n else {\r\n input = data[_DYN_TO_STRING /* @min:%2etoString */]();\r\n }\r\n var output = \"\";\r\n // tslint:disable-next-line:one-variable-per-declaration\r\n var chr1, chr2, chr3;\r\n var lp = 0;\r\n while (lp < input[_DYN_LENGTH /* @min:%2elength */]) {\r\n chr1 = input[_DYN_CHAR_CODE_AT /* @min:%2echarCodeAt */](lp++);\r\n chr2 = input[_DYN_CHAR_CODE_AT /* @min:%2echarCodeAt */](lp++);\r\n chr3 = input[_DYN_CHAR_CODE_AT /* @min:%2echarCodeAt */](lp++);\r\n // encode 4 character group\r\n line += _base64[_DYN_CHAR_AT /* @min:%2echarAt */](chr1 >> 2);\r\n line += _base64[_DYN_CHAR_AT /* @min:%2echarAt */](((chr1 & 3) << 4) | (chr2 >> 4));\r\n if (isNaN(chr2)) {\r\n line += \"==\";\r\n }\r\n else {\r\n line += _base64[_DYN_CHAR_AT /* @min:%2echarAt */](((chr2 & 15) << 2) | (chr3 >> 6));\r\n line += isNaN(chr3) ? \"=\" : _base64[_DYN_CHAR_AT /* @min:%2echarAt */](chr3 & 63);\r\n }\r\n }\r\n output += line;\r\n return output;\r\n}\r\n/**\r\n * Base64-decodes an encoded string and transforms it back to a Uint8Array.\r\n * @param input the encoded string to decode\r\n * @return Uint8Array\r\n */\r\nexport function base64Decode(input) {\r\n var output = \"\";\r\n var chr1, chr2, chr3;\r\n var enc1, enc2, enc3, enc4;\r\n var i = 0;\r\n input = input.replace(/[^A-Za-z0-9\\+\\/\\=]/g, \"\");\r\n while (i < input[_DYN_LENGTH /* @min:%2elength */]) {\r\n enc1 = _base64[_DYN_INDEX_OF /* @min:%2eindexOf */](input[_DYN_CHAR_AT /* @min:%2echarAt */](i++));\r\n enc2 = _base64[_DYN_INDEX_OF /* @min:%2eindexOf */](input[_DYN_CHAR_AT /* @min:%2echarAt */](i++));\r\n enc3 = _base64[_DYN_INDEX_OF /* @min:%2eindexOf */](input[_DYN_CHAR_AT /* @min:%2echarAt */](i++));\r\n enc4 = _base64[_DYN_INDEX_OF /* @min:%2eindexOf */](input[_DYN_CHAR_AT /* @min:%2echarAt */](i++));\r\n chr1 = (enc1 << 2) | (enc2 >> 4);\r\n chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);\r\n chr3 = ((enc3 & 3) << 6) | enc4;\r\n output = output + String[_DYN_FROM_CHAR_CODE /* @min:%2efromCharCode */](chr1);\r\n if (enc3 != 64) {\r\n output = output + String[_DYN_FROM_CHAR_CODE /* @min:%2efromCharCode */](chr2);\r\n }\r\n if (enc4 != 64) {\r\n output = output + String[_DYN_FROM_CHAR_CODE /* @min:%2efromCharCode */](chr3);\r\n }\r\n }\r\n var arr = output[_DYN_SPLIT /* @min:%2esplit */](\",\").map(function (c) { return Number(c); });\r\n return new Uint8Array(arr);\r\n}\r\n/**\r\n * Get number value of current time and append a random float number.\r\n * For example, if current time value is 12345678, so \"12345678.randomfl\" will be returned\r\n * @returns time id string\r\n */\r\nexport function getTimeId() {\r\n var time = (new Date())[_DYN_GET_TIME /* @min:%2egetTime */]();\r\n // append random digits to avoid same timestamp value\r\n var random = strSubstr(generateW3CId(), 0, 8);\r\n // function to create spanid();\r\n return time + \".\" + random;\r\n}\r\n/**\r\n * Get time value from a time id that is generated from getTimeId() function.\r\n * For example, if time id is \"12345678.randomfl\", 12345678 will be returned\r\n * @param id time id string\r\n * @returns time value number\r\n */\r\nexport function getTimeFromId(id) {\r\n try {\r\n var regex = new RegExp(/\\d+\\./g);\r\n if (id && isString(id) && regex.test(id)) {\r\n var arr = id[_DYN_SPLIT /* @min:%2esplit */](\".\");\r\n return parseInt(arr[0]);\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return 0;\r\n}\r\n/**\r\n * Get persistence level from a telemetry item.\r\n * Persistence level will be get from root, baseData or data in order.\r\n * For example, if persistence level is set both in root and baseData, the root one will be returned.\r\n * If no valid persistence level defined, normal level will be returned.\r\n * @param item telemetry item\r\n * @returns persistent level\r\n */\r\nexport function getPersistence(item) {\r\n var rlt = EventPersistence.Normal;\r\n // if item is null, return normal level\r\n if (!item) {\r\n return rlt;\r\n }\r\n try {\r\n var iItem = item;\r\n var level = iItem.persistence || (iItem.baseData && iItem.baseData.persistence) || (iItem[_DYN_DATA /* @min:%2edata */] && iItem[_DYN_DATA /* @min:%2edata */][_DYN_PERSISTENCE /* @min:%2epersistence */]);\r\n if (level && isValidPersistenceLevel(level)) {\r\n return level;\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return rlt;\r\n}\r\nexport var EVT_DISCARD_STR = \"eventsDiscarded\";\r\nexport var EVT_STORE_STR = \"offlineEventsStored\";\r\nexport var EVT_SENT_STR = \"offlineBatchSent\";\r\nexport var BATCH_DROP_STR = \"offlineBatchDrop\";\r\nexport function forEachMap(map, callback, ordered) {\r\n if (map) {\r\n var keys = objKeys(map);\r\n if (!!ordered && keys) {\r\n var time_1 = (new Date())[_DYN_GET_TIME /* @min:%2egetTime */]();\r\n keys = keys.sort(function (a, b) {\r\n try {\r\n // if getTimeFromId returns 0, mean the time is not valid\r\n var aTime = getTimeFromId(a) || time_1;\r\n var bTime = getTimeFromId(b) || time_1;\r\n return aTime - bTime;\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return -1;\r\n });\r\n }\r\n for (var lp = 0; lp < keys[_DYN_LENGTH /* @min:%2elength */]; lp++) {\r\n var key = keys[lp];\r\n if (!callback(map[key], key)) {\r\n break;\r\n }\r\n }\r\n }\r\n}\r\nexport function callNotification(mgr, evtName, theArgs) {\r\n var manager = (mgr || {});\r\n var notifyFunc = manager[evtName];\r\n if (notifyFunc) {\r\n try {\r\n notifyFunc.apply(manager, theArgs);\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n }\r\n}\r\nexport function batchDropNotification(mgr, cnt, reason) {\r\n if (mgr && cnt > 0) {\r\n callNotification(mgr, BATCH_DROP_STR, [cnt, reason]);\r\n }\r\n return;\r\n}\r\n// OneCollector:\r\n// 200-OK – Success or partial success.\r\n// 204-NoContent – Success or partial success. Regarding accepting events, identical to 200-OK. If the request header contains NoResponseBody with the value of true and the request was successful/partially successful, 204-NoContent status code is returned instead of 200-OK.\r\n// 400-BadRequest – all events were rejected.\r\n// 403-Forbidden – client is above its quota and all events were throttled.\r\n// 413-RequestEntityTooLarge – the request doesn’t conform to limits described in Request constraints section.\r\n// 415-UnsupportedMediaType – the Content-Type or Content-Encoding header has an unexpected value.\r\n// 429-TooManyRequests – the server decided to throttle given request (no data accepted) as the client (device, client version, …) generates too much traffic.\r\n// 401-Unauthorized – Can occur under two conditions:\r\n// All tenant tokens included in this request are invalid (unauthorized). kill-tokens header indicates which one(s). WWW-Authenticate: Token realm=\"ingestion\" (see: rfc2617 for more details) header is added.\r\n// The client has supplied the “strict” header (see section 3.3), and at least one MSA and/or XAuth event token cannot be used as a source of trusted user or device information. The event failure reason “TokenCrackingFailure” will be present in the response’ JSON body. In this scenario, the client is expected to fix or replace the offending ticket and retry.\r\n// 500-InternalServerError – an unexpected exception while handling the request.\r\n// 503-ServiceUnavailable – a machine serving this request is overloaded or shutting down. The request should be retried to a different machine. The server adds Connection: Close header to enforce TCP connection closing.\r\n// Breeze\r\n// 0 ad blockers\r\n// 200 Success!\r\n// 206 - Partial Accept\r\n// 307/308 - Redirect\r\n// 400 - Invalid\r\n// 400 can also be caused by Azure AD authentication.\r\n// 400 is not retriable and SDK should drop invalid data.\r\n// 401 - Unauthorized\r\n// 401 can be also caused by an AAD outage.\r\n// 401 is retriable.\r\n// 402 - Daily Quota Exceeded, drop the data.\r\n// There is no retry-after in the response header for 402.\r\n// 403 - Forbidden\r\n// 403 can also caused by misconfiguring the access control assigned to the Application Insights resource.\r\n// 403 is retriable.\r\n// 404 - Ingestion is allowed only from stamp specific endpoint\r\n// Telemetry will be dropped and customer must update their connection string.\r\n// 404 is not retriable and SDK should drop the data.\r\n// 408 - Timeout, retry it later. (offline might get this)\r\n// 429 - Too Many Requests, Breeze returns retry-after for status code 429 only.\r\n// 500 - Internal Server Error, retry it later.\r\n// 502 - Bad Gateway, retry it later.\r\n// 503 - Service Unavailable, retry it later. (offline)\r\n// 504 - Gateway timeout, retry it later.\r\n// All other response codes, SDK should drop the data.\r\n//# sourceMappingURL=Utils.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;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;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;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
1
+ {"version":3,"file":"Utils.js.map","sources":["Utils.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { EventPersistence } from \"@microsoft/applicationinsights-common\";\r\nimport { generateW3CId } from \"@microsoft/applicationinsights-core-js\";\r\nimport { isNumber, isString, objKeys, strSubstr } from \"@nevware21/ts-utils\";\r\nimport { _DYN_CHAR_AT, _DYN_CHAR_CODE_AT, _DYN_DATA, _DYN_FROM_CHAR_CODE, _DYN_GET_TIME, _DYN_INDEX_OF, _DYN_LENGTH, _DYN_PERSISTENCE, _DYN_SPLIT, _DYN_TO_STRING, _DYN__CRITICAL, _DYN__NORMAL } from \"../__DynamicConstants\";\r\n/**\r\n* Checks if the value is a valid EventPersistence.\r\n* @param {enum} value - The value that needs to be checked.\r\n* @return {boolean} True if the value is in EventPersistence, false otherwise.\r\n*/\r\nexport function isValidPersistenceLevel(value) {\r\n return (isNumber(value) && value >= 0 /* eLoggingSeverity.DISABLED */ && value <= EventPersistence[_DYN__CRITICAL /* @min:%2eCritical */]);\r\n}\r\n// Endpoint schema\r\n// <prefix>.<suffix>\r\n//Prefix: Defines a service.\r\n//Suffix: Defines the common domain name.\r\n/**\r\n * Get domian from an endpoint url.\r\n * for example, https://test.com?auth=true, will return test.com\r\n * @param endpoint endpoint url\r\n * @returns domain string\r\n */\r\nexport function getEndpointDomain(endpoint) {\r\n try {\r\n var url = endpoint.replace(/^https?:\\/\\/|^www\\./, \"\");\r\n url = url.replace(/\\?/, \"/\");\r\n var arr = url[_DYN_SPLIT /* @min:%2esplit */](\"/\");\r\n if (arr && arr[_DYN_LENGTH /* @min:%2elength */] > 0) {\r\n return arr[0];\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n // if we can't get domain, entire endpoint will be used\r\n return endpoint;\r\n}\r\n/**\r\n * If current value is equal or greater than zero.\r\n * @param value number\r\n * @returns boolean\r\n */\r\nexport function isGreaterThanZero(value) {\r\n return value >= 0;\r\n}\r\n//Base64 is a binary encoding rather than a text encoding,\r\n// it were added to the web platform before it supported binary data types.\r\n// As a result, the two functions use strings to represent binary data\r\nvar _base64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\";\r\n/**\r\n * Base64-encodes a Uint8Array.\r\n *\r\n * @param data the Uint8Array or string to encode.\r\n *\r\n * @return the base64-encoded output string.\r\n */\r\nexport function base64Encode(data) {\r\n var line = \"\";\r\n var input = \"\";\r\n if (isString(data)) {\r\n input = data;\r\n }\r\n else {\r\n input = data[_DYN_TO_STRING /* @min:%2etoString */]();\r\n }\r\n var output = \"\";\r\n // tslint:disable-next-line:one-variable-per-declaration\r\n var chr1, chr2, chr3;\r\n var lp = 0;\r\n while (lp < input[_DYN_LENGTH /* @min:%2elength */]) {\r\n chr1 = input[_DYN_CHAR_CODE_AT /* @min:%2echarCodeAt */](lp++);\r\n chr2 = input[_DYN_CHAR_CODE_AT /* @min:%2echarCodeAt */](lp++);\r\n chr3 = input[_DYN_CHAR_CODE_AT /* @min:%2echarCodeAt */](lp++);\r\n // encode 4 character group\r\n line += _base64[_DYN_CHAR_AT /* @min:%2echarAt */](chr1 >> 2);\r\n line += _base64[_DYN_CHAR_AT /* @min:%2echarAt */](((chr1 & 3) << 4) | (chr2 >> 4));\r\n if (isNaN(chr2)) {\r\n line += \"==\";\r\n }\r\n else {\r\n line += _base64[_DYN_CHAR_AT /* @min:%2echarAt */](((chr2 & 15) << 2) | (chr3 >> 6));\r\n line += isNaN(chr3) ? \"=\" : _base64[_DYN_CHAR_AT /* @min:%2echarAt */](chr3 & 63);\r\n }\r\n }\r\n output += line;\r\n return output;\r\n}\r\n/**\r\n * Base64-decodes an encoded string and transforms it back to a Uint8Array.\r\n * @param input the encoded string to decode\r\n * @return Uint8Array\r\n */\r\nexport function base64Decode(input) {\r\n var output = \"\";\r\n var chr1, chr2, chr3;\r\n var enc1, enc2, enc3, enc4;\r\n var i = 0;\r\n input = input.replace(/[^A-Za-z0-9\\+\\/\\=]/g, \"\");\r\n while (i < input[_DYN_LENGTH /* @min:%2elength */]) {\r\n enc1 = _base64[_DYN_INDEX_OF /* @min:%2eindexOf */](input[_DYN_CHAR_AT /* @min:%2echarAt */](i++));\r\n enc2 = _base64[_DYN_INDEX_OF /* @min:%2eindexOf */](input[_DYN_CHAR_AT /* @min:%2echarAt */](i++));\r\n enc3 = _base64[_DYN_INDEX_OF /* @min:%2eindexOf */](input[_DYN_CHAR_AT /* @min:%2echarAt */](i++));\r\n enc4 = _base64[_DYN_INDEX_OF /* @min:%2eindexOf */](input[_DYN_CHAR_AT /* @min:%2echarAt */](i++));\r\n chr1 = (enc1 << 2) | (enc2 >> 4);\r\n chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);\r\n chr3 = ((enc3 & 3) << 6) | enc4;\r\n output = output + String[_DYN_FROM_CHAR_CODE /* @min:%2efromCharCode */](chr1);\r\n if (enc3 != 64) {\r\n output = output + String[_DYN_FROM_CHAR_CODE /* @min:%2efromCharCode */](chr2);\r\n }\r\n if (enc4 != 64) {\r\n output = output + String[_DYN_FROM_CHAR_CODE /* @min:%2efromCharCode */](chr3);\r\n }\r\n }\r\n var arr = output[_DYN_SPLIT /* @min:%2esplit */](\",\").map(function (c) { return Number(c); });\r\n return new Uint8Array(arr);\r\n}\r\n/**\r\n * Get number value of current time and append a random float number.\r\n * For example, if current time value is 12345678, so \"12345678.randomfl\" will be returned\r\n * @returns time id string\r\n */\r\nexport function getTimeId() {\r\n var time = (new Date())[_DYN_GET_TIME /* @min:%2egetTime */]();\r\n // append random digits to avoid same timestamp value\r\n var random = strSubstr(generateW3CId(), 0, 8);\r\n // function to create spanid();\r\n return time + \".\" + random;\r\n}\r\n/**\r\n * Get time value from a time id that is generated from getTimeId() function.\r\n * For example, if time id is \"12345678.randomfl\", 12345678 will be returned\r\n * @param id time id string\r\n * @returns time value number\r\n */\r\nexport function getTimeFromId(id) {\r\n try {\r\n var regex = new RegExp(/\\d+\\./g);\r\n if (id && isString(id) && regex.test(id)) {\r\n var arr = id[_DYN_SPLIT /* @min:%2esplit */](\".\");\r\n return parseInt(arr[0]);\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return 0;\r\n}\r\n/**\r\n * Get persistence level from a telemetry item.\r\n * Persistence level will be get from root, baseData or data in order.\r\n * For example, if persistence level is set both in root and baseData, the root one will be returned.\r\n * If no valid persistence level defined, normal level will be returned.\r\n * @param item telemetry item\r\n * @returns persistent level\r\n */\r\nexport function getPersistence(item) {\r\n var rlt = EventPersistence[_DYN__NORMAL /* @min:%2eNormal */];\r\n // if item is null, return normal level\r\n if (!item) {\r\n return rlt;\r\n }\r\n try {\r\n var iItem = item;\r\n var level = iItem.persistence || (iItem.baseData && iItem.baseData.persistence) || (iItem[_DYN_DATA /* @min:%2edata */] && iItem[_DYN_DATA /* @min:%2edata */][_DYN_PERSISTENCE /* @min:%2epersistence */]);\r\n if (level && isValidPersistenceLevel(level)) {\r\n return level;\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return rlt;\r\n}\r\nexport var EVT_DISCARD_STR = \"eventsDiscarded\";\r\nexport var EVT_STORE_STR = \"offlineEventsStored\";\r\nexport var EVT_SENT_STR = \"offlineBatchSent\";\r\nexport var BATCH_DROP_STR = \"offlineBatchDrop\";\r\nexport function forEachMap(map, callback, ordered) {\r\n if (map) {\r\n var keys = objKeys(map);\r\n if (!!ordered && keys) {\r\n var time_1 = (new Date())[_DYN_GET_TIME /* @min:%2egetTime */]();\r\n keys = keys.sort(function (a, b) {\r\n try {\r\n // if getTimeFromId returns 0, mean the time is not valid\r\n var aTime = getTimeFromId(a) || time_1;\r\n var bTime = getTimeFromId(b) || time_1;\r\n return aTime - bTime;\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return -1;\r\n });\r\n }\r\n for (var lp = 0; lp < keys[_DYN_LENGTH /* @min:%2elength */]; lp++) {\r\n var key = keys[lp];\r\n if (!callback(map[key], key)) {\r\n break;\r\n }\r\n }\r\n }\r\n}\r\nexport function callNotification(mgr, evtName, theArgs) {\r\n var manager = (mgr || {});\r\n var notifyFunc = manager[evtName];\r\n if (notifyFunc) {\r\n try {\r\n notifyFunc.apply(manager, theArgs);\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n }\r\n}\r\nexport function batchDropNotification(mgr, cnt, reason) {\r\n if (mgr && cnt > 0) {\r\n callNotification(mgr, BATCH_DROP_STR, [cnt, reason]);\r\n }\r\n return;\r\n}\r\n// OneCollector:\r\n// 200-OK – Success or partial success.\r\n// 204-NoContent – Success or partial success. Regarding accepting events, identical to 200-OK. If the request header contains NoResponseBody with the value of true and the request was successful/partially successful, 204-NoContent status code is returned instead of 200-OK.\r\n// 400-BadRequest – all events were rejected.\r\n// 403-Forbidden – client is above its quota and all events were throttled.\r\n// 413-RequestEntityTooLarge – the request doesn’t conform to limits described in Request constraints section.\r\n// 415-UnsupportedMediaType – the Content-Type or Content-Encoding header has an unexpected value.\r\n// 429-TooManyRequests – the server decided to throttle given request (no data accepted) as the client (device, client version, …) generates too much traffic.\r\n// 401-Unauthorized – Can occur under two conditions:\r\n// All tenant tokens included in this request are invalid (unauthorized). kill-tokens header indicates which one(s). WWW-Authenticate: Token realm=\"ingestion\" (see: rfc2617 for more details) header is added.\r\n// The client has supplied the “strict” header (see section 3.3), and at least one MSA and/or XAuth event token cannot be used as a source of trusted user or device information. The event failure reason “TokenCrackingFailure” will be present in the response’ JSON body. In this scenario, the client is expected to fix or replace the offending ticket and retry.\r\n// 500-InternalServerError – an unexpected exception while handling the request.\r\n// 503-ServiceUnavailable – a machine serving this request is overloaded or shutting down. The request should be retried to a different machine. The server adds Connection: Close header to enforce TCP connection closing.\r\n// Breeze\r\n// 0 ad blockers\r\n// 200 Success!\r\n// 206 - Partial Accept\r\n// 307/308 - Redirect\r\n// 400 - Invalid\r\n// 400 can also be caused by Azure AD authentication.\r\n// 400 is not retriable and SDK should drop invalid data.\r\n// 401 - Unauthorized\r\n// 401 can be also caused by an AAD outage.\r\n// 401 is retriable.\r\n// 402 - Daily Quota Exceeded, drop the data.\r\n// There is no retry-after in the response header for 402.\r\n// 403 - Forbidden\r\n// 403 can also caused by misconfiguring the access control assigned to the Application Insights resource.\r\n// 403 is retriable.\r\n// 404 - Ingestion is allowed only from stamp specific endpoint\r\n// Telemetry will be dropped and customer must update their connection string.\r\n// 404 is not retriable and SDK should drop the data.\r\n// 408 - Timeout, retry it later. (offline might get this)\r\n// 429 - Too Many Requests, Breeze returns retry-after for status code 429 only.\r\n// 500 - Internal Server Error, retry it later.\r\n// 502 - Bad Gateway, retry it later.\r\n// 503 - Service Unavailable, retry it later. (offline)\r\n// 504 - Gateway timeout, retry it later.\r\n// All other response codes, SDK should drop the data.\r\n//# sourceMappingURL=Utils.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;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;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;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
@@ -1,12 +1,12 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-09
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-10
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
6
6
 
7
7
  import dynamicProto from "@microsoft/dynamicproto-js";
8
8
  import { isNullOrUndefined } from "@microsoft/applicationinsights-core-js";
9
- import { _DYN_ADD_EVENT, _DYN_CLEAR, _DYN_COUNT, _DYN_ENDPOINT, _DYN_GET_ITEMS, _DYN_LENGTH, _DYN_PUSH, _DYN_SPLICE, _DYN_SPLIT } from "./__DynamicConstants";
9
+ import { _DYN_ADD_EVENT, _DYN_CLEAR, _DYN_ENDPOINT, _DYN_GET_ITEMS, _DYN_LENGTH, _DYN_PUSH, _DYN_SPLICE, _DYN_SPLIT } from "./__DynamicConstants";
10
10
  var InMemoryBatch = /** @class */ (function () {
11
11
  function InMemoryBatch(logger, endpoint, evts, evtsLimitInMem) {
12
12
  var _buffer = evts ? [].concat(evts) : [];
@@ -15,13 +15,13 @@ var InMemoryBatch = /** @class */ (function () {
15
15
  return endpoint;
16
16
  };
17
17
  _self[_DYN_ADD_EVENT /* @min:%2eaddEvent */] = function (payload) {
18
- if (!isNullOrUndefined(evtsLimitInMem) && _self[_DYN_COUNT /* @min:%2ecount */]() >= evtsLimitInMem) {
18
+ if (!isNullOrUndefined(evtsLimitInMem) && _self.count() >= evtsLimitInMem) {
19
19
  return false;
20
20
  }
21
21
  _buffer[_DYN_PUSH /* @min:%2epush */](payload);
22
22
  return true;
23
23
  };
24
- _self[_DYN_COUNT /* @min:%2ecount */] = function () {
24
+ _self.count = function () {
25
25
  return _buffer[_DYN_LENGTH /* @min:%2elength */];
26
26
  };
27
27
  _self[_DYN_CLEAR /* @min:%2eclear */] = function () {
@@ -1 +1 @@
1
- {"version":3,"file":"InMemoryBatch.js.map","sources":["InMemoryBatch.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { isNullOrUndefined } from \"@microsoft/applicationinsights-core-js\";\r\nimport { _DYN_ADD_EVENT, _DYN_CLEAR, _DYN_COUNT, _DYN_ENDPOINT, _DYN_GET_ITEMS, _DYN_LENGTH, _DYN_PUSH, _DYN_SPLICE, _DYN_SPLIT } from \"./__DynamicConstants\";\r\nvar InMemoryBatch = /** @class */ (function () {\r\n function InMemoryBatch(logger, endpoint, evts, evtsLimitInMem) {\r\n var _buffer = evts ? [].concat(evts) : [];\r\n dynamicProto(InMemoryBatch, this, function (_self) {\r\n _self[_DYN_ENDPOINT /* @min:%2eendpoint */] = function () {\r\n return endpoint;\r\n };\r\n _self[_DYN_ADD_EVENT /* @min:%2eaddEvent */] = function (payload) {\r\n if (!isNullOrUndefined(evtsLimitInMem) && _self[_DYN_COUNT /* @min:%2ecount */]() >= evtsLimitInMem) {\r\n return false;\r\n }\r\n _buffer[_DYN_PUSH /* @min:%2epush */](payload);\r\n return true;\r\n };\r\n _self[_DYN_COUNT /* @min:%2ecount */] = function () {\r\n return _buffer[_DYN_LENGTH /* @min:%2elength */];\r\n };\r\n _self[_DYN_CLEAR /* @min:%2eclear */] = function () {\r\n _buffer = [];\r\n };\r\n _self[_DYN_GET_ITEMS /* @min:%2egetItems */] = function () {\r\n return _buffer.slice(0);\r\n };\r\n _self[_DYN_SPLIT /* @min:%2esplit */] = function (fromEvt, numEvts) {\r\n // Create a new batch with the same endpointUrl\r\n var theEvts;\r\n if (fromEvt < _buffer[_DYN_LENGTH /* @min:%2elength */]) {\r\n var cnt = _buffer[_DYN_LENGTH /* @min:%2elength */] - fromEvt;\r\n if (!isNullOrUndefined(numEvts)) {\r\n cnt = numEvts < cnt ? numEvts : cnt;\r\n }\r\n theEvts = _buffer[_DYN_SPLICE /* @min:%2esplice */](fromEvt, cnt);\r\n }\r\n return new InMemoryBatch(logger, endpoint, theEvts, evtsLimitInMem);\r\n };\r\n _self.createNew = function (newEndpoint, evts, newEvtsLimitInMem) {\r\n return new InMemoryBatch(logger, newEndpoint, evts, newEvtsLimitInMem);\r\n };\r\n });\r\n }\r\n InMemoryBatch.prototype.addEvent = function (payload) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n InMemoryBatch.prototype.endpoint = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n InMemoryBatch.prototype.count = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return 0;\r\n };\r\n InMemoryBatch.prototype.clear = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n InMemoryBatch.prototype.getItems = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Split this batch into 2 with any events > fromEvent returned in the new batch and all other\r\n * events are kept in the current batch.\r\n * @param fromEvt The first event to remove from the current batch.\r\n * @param numEvts The number of events to be removed from the current batch and returned in the new one. Defaults to all trailing events\r\n */\r\n InMemoryBatch.prototype.split = function (fromEvt, numEvts) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * create current buffer to a new endpoint\r\n * @param endpoint if not defined, current endpoint will be used\r\n * @param evts new events to be added\r\n * @param addCurEvts if it is set to true, current itemss will be transferred to the new batch\r\n */\r\n InMemoryBatch.prototype.createNew = function (endpoint, evts, evtsLimitInMem) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n return InMemoryBatch;\r\n}());\r\nexport { InMemoryBatch };\r\n//# sourceMappingURL=InMemoryBatch.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;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;;;;;;sDAsCM,CAAC;;;;;yBACkB;AACzB;AACA;AACA"}
1
+ {"version":3,"file":"InMemoryBatch.js.map","sources":["InMemoryBatch.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { isNullOrUndefined } from \"@microsoft/applicationinsights-core-js\";\r\nimport { _DYN_ADD_EVENT, _DYN_CLEAR, _DYN_ENDPOINT, _DYN_GET_ITEMS, _DYN_LENGTH, _DYN_PUSH, _DYN_SPLICE, _DYN_SPLIT } from \"./__DynamicConstants\";\r\nvar InMemoryBatch = /** @class */ (function () {\r\n function InMemoryBatch(logger, endpoint, evts, evtsLimitInMem) {\r\n var _buffer = evts ? [].concat(evts) : [];\r\n dynamicProto(InMemoryBatch, this, function (_self) {\r\n _self[_DYN_ENDPOINT /* @min:%2eendpoint */] = function () {\r\n return endpoint;\r\n };\r\n _self[_DYN_ADD_EVENT /* @min:%2eaddEvent */] = function (payload) {\r\n if (!isNullOrUndefined(evtsLimitInMem) && _self.count() >= evtsLimitInMem) {\r\n return false;\r\n }\r\n _buffer[_DYN_PUSH /* @min:%2epush */](payload);\r\n return true;\r\n };\r\n _self.count = function () {\r\n return _buffer[_DYN_LENGTH /* @min:%2elength */];\r\n };\r\n _self[_DYN_CLEAR /* @min:%2eclear */] = function () {\r\n _buffer = [];\r\n };\r\n _self[_DYN_GET_ITEMS /* @min:%2egetItems */] = function () {\r\n return _buffer.slice(0);\r\n };\r\n _self[_DYN_SPLIT /* @min:%2esplit */] = function (fromEvt, numEvts) {\r\n // Create a new batch with the same endpointUrl\r\n var theEvts;\r\n if (fromEvt < _buffer[_DYN_LENGTH /* @min:%2elength */]) {\r\n var cnt = _buffer[_DYN_LENGTH /* @min:%2elength */] - fromEvt;\r\n if (!isNullOrUndefined(numEvts)) {\r\n cnt = numEvts < cnt ? numEvts : cnt;\r\n }\r\n theEvts = _buffer[_DYN_SPLICE /* @min:%2esplice */](fromEvt, cnt);\r\n }\r\n return new InMemoryBatch(logger, endpoint, theEvts, evtsLimitInMem);\r\n };\r\n _self.createNew = function (newEndpoint, evts, newEvtsLimitInMem) {\r\n return new InMemoryBatch(logger, newEndpoint, evts, newEvtsLimitInMem);\r\n };\r\n });\r\n }\r\n InMemoryBatch.prototype.addEvent = function (payload) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n InMemoryBatch.prototype.endpoint = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n InMemoryBatch.prototype.count = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return 0;\r\n };\r\n InMemoryBatch.prototype.clear = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n InMemoryBatch.prototype.getItems = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Split this batch into 2 with any events > fromEvent returned in the new batch and all other\r\n * events are kept in the current batch.\r\n * @param fromEvt The first event to remove from the current batch.\r\n * @param numEvts The number of events to be removed from the current batch and returned in the new one. Defaults to all trailing events\r\n */\r\n InMemoryBatch.prototype.split = function (fromEvt, numEvts) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * create current buffer to a new endpoint\r\n * @param endpoint if not defined, current endpoint will be used\r\n * @param evts new events to be added\r\n * @param addCurEvts if it is set to true, current itemss will be transferred to the new batch\r\n */\r\n InMemoryBatch.prototype.createNew = function (endpoint, evts, evtsLimitInMem) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n return InMemoryBatch;\r\n}());\r\nexport { InMemoryBatch };\r\n//# sourceMappingURL=InMemoryBatch.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;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;;;;;;sDAsCM,CAAC;;;;;yBACkB;AACzB;AACA;AACA"}
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-09
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-10
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-09
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-10
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-09
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-10
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-09
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-10
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-09
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-10
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-09
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-10
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-09
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-10
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -9,23 +9,24 @@ import dynamicProto from "@microsoft/dynamicproto-js";
9
9
  import { BreezeChannelIdentifier, EventPersistence, createOfflineListener } from "@microsoft/applicationinsights-common";
10
10
  import { BaseTelemetryPlugin, EventsDiscardedReason, _throwInternal, arrForEach, createProcessTelemetryContext, createUniqueNamespace, dateNow, mergeEvtNamespace, onConfigChange, runTargetUnload } from "@microsoft/applicationinsights-core-js";
11
11
  import { createAsyncPromise, createTaskScheduler } from "@nevware21/ts-async";
12
- import { isFunction, isString, objDeepFreeze, scheduleTimeout } from "@nevware21/ts-utils";
12
+ import { arrSlice, isFunction, isString, objDeepFreeze, objForEachKey, scheduleTimeout } from "@nevware21/ts-utils";
13
13
  import { EVT_DISCARD_STR, EVT_SENT_STR, EVT_STORE_STR, batchDropNotification, callNotification, isGreaterThanZero, isValidPersistenceLevel } from "./Helpers/Utils";
14
14
  import { InMemoryBatch } from "./InMemoryBatch";
15
15
  import { OfflineBatchHandler } from "./OfflineBatchHandler";
16
16
  import { Sender } from "./Sender";
17
- import { _DYN_ADD_EVENT, _DYN_BATCH_HANDLER, _DYN_CANCEL, _DYN_CLEAR, _DYN_COUNT, _DYN_CREATE_ONE_DSPAYLOAD, _DYN_CRITICAL_CNT, _DYN_DATA, _DYN_DIAG_LOG, _DYN_GET_ITEMS, _DYN_GET_OFFLINE_SUPPORT, _DYN_INITIALIZE, _DYN_INSTRUMENTATION_KEY, _DYN_IS_COMPLETELY_IDLE, _DYN_IS_ONLINE, _DYN_LENGTH, _DYN_MIN_PERSISTENCE_CACH0, _DYN_ONUNLOAD_FLUSH, _DYN_OVERRIDE_INSTRUMENTA1, _DYN_PERSISTENCE, _DYN_PROCESS_NEXT, _DYN_PUSH, _DYN_REFRESH, _DYN_SEND_NEXT_BATCH, _DYN_STATE, _DYN_TEARDOWN } from "./__DynamicConstants";
18
- var version = '0.3.3-nightly3.2409-09';
17
+ import { _DYN_ADD_EVENT, _DYN_BATCH_HANDLER, _DYN_CANCEL, _DYN_CLEAR, _DYN_CREATE_ONE_DSPAYLOAD, _DYN_CRITICAL_CNT, _DYN_DATA, _DYN_DIAG_LOG, _DYN_GET_ITEMS, _DYN_GET_OFFLINE_SUPPORT, _DYN_INITIALIZE, _DYN_INSTRUMENTATION_KEY, _DYN_IS_COMPLETELY_IDLE, _DYN_IS_ONLINE, _DYN_LENGTH, _DYN_MIN_PERSISTENCE_CACH0, _DYN_ONUNLOAD_FLUSH, _DYN_OVERRIDE_INSTRUMENTA1, _DYN_PERSISTENCE, _DYN_PROCESS_NEXT, _DYN_PUSH, _DYN_REFRESH, _DYN_SEND_NEXT_BATCH, _DYN_STATE, _DYN_TEARDOWN, _DYN__CRITICAL, _DYN__NORMAL } from "./__DynamicConstants";
18
+ var version = '0.3.3-nightly3.2409-10';
19
19
  var DefaultOfflineIdentifier = "OfflineChannel";
20
20
  var DefaultBatchInterval = 15000;
21
21
  var DefaultInMemoMaxTime = 15000;
22
22
  var PostChannelIdentifier = "PostChannel";
23
+ var PersistenceKeys = [EventPersistence[_DYN__CRITICAL /* @min:%2eCritical */], EventPersistence.Normal];
23
24
  var undefValue = undefined;
24
25
  var DefaultBatchSizeLimitBytes = 63000; // approx 64kb (the current Edge, Firefox and Chrome max limit)
25
26
  var defaultOfflineChannelConfig = objDeepFreeze({
26
27
  maxStorageSizeInBytes: { isVal: isGreaterThanZero, v: 5000000 },
27
28
  storageKey: undefValue,
28
- minPersistenceLevel: { isVal: isValidPersistenceLevel, v: EventPersistence.Normal },
29
+ minPersistenceLevel: { isVal: isValidPersistenceLevel, v: EventPersistence[_DYN__NORMAL /* @min:%2eNormal */] },
29
30
  providers: [1 /* eStorageProviders.LocalStorage */, 3 /* eStorageProviders.IndexedDb */],
30
31
  indexedDbName: undefValue,
31
32
  maxStorageItems: { isVal: isGreaterThanZero, v: undefValue },
@@ -35,7 +36,8 @@ var defaultOfflineChannelConfig = objDeepFreeze({
35
36
  maxSentBatchInterval: { isVal: isGreaterThanZero, v: DefaultBatchInterval },
36
37
  primaryOnlineChannelId: [BreezeChannelIdentifier, PostChannelIdentifier],
37
38
  overrideInstrumentationKey: undefValue,
38
- senderCfg: {}
39
+ senderCfg: {},
40
+ splitEvts: false
39
41
  });
40
42
  //TODO: add tests for sharedAnanlytics
41
43
  var OfflineChannel = /** @class */ (function (_super) {
@@ -49,7 +51,6 @@ var OfflineChannel = /** @class */ (function (_super) {
49
51
  // Internal properties used for tracking the current state, these are "true" internal/private properties for this instance
50
52
  var _hasInitialized;
51
53
  var _paused;
52
- var _inMemoBatch;
53
54
  var _sender;
54
55
  var _urlCfg;
55
56
  var _offlineListener;
@@ -72,6 +73,8 @@ var OfflineChannel = /** @class */ (function (_super) {
72
73
  var _notificationManager;
73
74
  var _isLazyInit;
74
75
  var _dependencyPlugin;
76
+ var _splitEvts;
77
+ var _inMemoMap;
75
78
  _initDefaults();
76
79
  _self[_DYN_INITIALIZE /* @min:%2einitialize */] = function (coreConfig, core, extensions, pluginChain) {
77
80
  if (!_hasInitialized) {
@@ -132,16 +135,16 @@ var OfflineChannel = /** @class */ (function (_super) {
132
135
  }
133
136
  var item = evt;
134
137
  //TODO: add function to better get level
135
- item[_DYN_PERSISTENCE /* @min:%2epersistence */] = item[_DYN_PERSISTENCE /* @min:%2epersistence */] || (item.baseData && item.baseData[_DYN_PERSISTENCE /* @min:%2epersistence */]) || EventPersistence.Normal; // in case the level is in baseData
136
- if (_shouldCacheEvent(_urlCfg, item) && _inMemoBatch) {
138
+ item.persistence = item.persistence || (item.baseData && item.baseData.persistence) || EventPersistence[_DYN__NORMAL /* @min:%2eNormal */]; // in case the level is in baseData
139
+ if (_shouldCacheEvent(_urlCfg, item) && _inMemoMap) {
137
140
  if (_overrideIkey) {
138
141
  item.iKey = _overrideIkey;
139
142
  }
140
- var added = _inMemoBatch[_DYN_ADD_EVENT /* @min:%2eaddEvent */](evt);
143
+ var added = _addEvtToMap(item);
141
144
  // inMemo is full
142
145
  if (!added) {
143
- _flushInMemoItems();
144
- var retry = _inMemoBatch[_DYN_ADD_EVENT /* @min:%2eaddEvent */](evt);
146
+ _flushInMemoItems(false, item[_DYN_PERSISTENCE /* @min:%2epersistence */]);
147
+ var retry = _addEvtToMap(item);
145
148
  if (!retry) {
146
149
  _evtDropNotification([evt], EventsDiscardedReason.QueueFull);
147
150
  _throwInternal(_diagLogger, 2 /* eLoggingSeverity.WARNING */, 105 /* _eInternalMessageId.InMemoryStorageBufferFull */, "Maximum offline in-memory buffer size reached", true);
@@ -177,7 +180,7 @@ var OfflineChannel = /** @class */ (function (_super) {
177
180
  };
178
181
  _self[_DYN_ONUNLOAD_FLUSH /* @min:%2eonunloadFlush */] = function () {
179
182
  if (!_paused) {
180
- while (_inMemoBatch && _inMemoBatch[_DYN_COUNT /* @min:%2ecount */]()) {
183
+ while (_hasEvts()) {
181
184
  _flushInMemoItems(true);
182
185
  }
183
186
  // TODO: unloadprovider might send events out of order
@@ -203,7 +206,7 @@ var OfflineChannel = /** @class */ (function (_super) {
203
206
  _initDefaults();
204
207
  };
205
208
  _self["_getDbgPlgTargets"] = function () {
206
- return [_urlCfg, _inMemoBatch, _senderInst, _inMemoFlushTimer, _sendNextBatchTimer];
209
+ return [_urlCfg, _inMemoMap, _senderInst, _inMemoFlushTimer, _sendNextBatchTimer];
207
210
  };
208
211
  function _initDefaults() {
209
212
  _hasInitialized = false;
@@ -213,7 +216,6 @@ var OfflineChannel = /** @class */ (function (_super) {
213
216
  _offlineListener = null;
214
217
  _diagLogger = null;
215
218
  _endpoint = null;
216
- _inMemoBatch = null;
217
219
  _convertUndefined = undefValue;
218
220
  _maxBatchSize = null;
219
221
  _sendNextBatchTimer = null;
@@ -227,6 +229,8 @@ var OfflineChannel = /** @class */ (function (_super) {
227
229
  _evtsLimitInMemo = null;
228
230
  _isLazyInit = false;
229
231
  _dependencyPlugin = null;
232
+ _splitEvts = false;
233
+ _inMemoMap = null;
230
234
  }
231
235
  function _shouldCacheEvent(urlConfig, item) {
232
236
  if ((item[_DYN_PERSISTENCE /* @min:%2epersistence */]) < urlConfig[_DYN_MIN_PERSISTENCE_CACH0 /* @min:%2eminPersistenceCacheLevel */]) {
@@ -238,7 +242,8 @@ var OfflineChannel = /** @class */ (function (_super) {
238
242
  if (!_inMemoFlushTimer) {
239
243
  _inMemoFlushTimer = scheduleTimeout(function () {
240
244
  _flushInMemoItems();
241
- if (_inMemoBatch && _inMemoBatch[_DYN_COUNT /* @min:%2ecount */]() && _inMemoFlushTimer) {
245
+ var hasEvts = _hasEvts();
246
+ if (hasEvts && _inMemoFlushTimer) {
242
247
  _inMemoFlushTimer[_DYN_REFRESH /* @min:%2erefresh */]();
243
248
  }
244
249
  _setSendNextTimer();
@@ -251,75 +256,92 @@ var OfflineChannel = /** @class */ (function (_super) {
251
256
  }
252
257
  }
253
258
  //flush only flush max batch size event, may still have events lefts
254
- function _flushInMemoItems(unload) {
259
+ function _flushInMemoItems(unload, mapKey) {
255
260
  try {
256
261
  // TODO: add while loop to flush everything
257
- var inMemo = _inMemoBatch;
258
- var evts = inMemo && inMemo[_DYN_GET_ITEMS /* @min:%2egetItems */]();
259
- if (!evts || !evts[_DYN_LENGTH /* @min:%2elength */]) {
260
- return;
261
- }
262
- var payloadArr_1 = [];
263
- var size_1 = 0;
264
- var idx_1 = -1;
265
- var criticalCnt_1 = 0;
266
- arrForEach(evts, function (evt, index) {
267
- var curEvt = evt;
268
- idx_1 = index;
269
- var payload = _getPayload(curEvt);
270
- size_1 += payload[_DYN_LENGTH /* @min:%2elength */];
271
- if (size_1 > _maxBatchSize) {
262
+ var hasEvts_1 = false;
263
+ // can use objForEachKey(_inMemoMap, (key)), but keys returned by this function is always string
264
+ arrForEach(PersistenceKeys, function (key) {
265
+ var inMemoBatch = _inMemoMap[key];
266
+ var inMemo = inMemoBatch;
267
+ var evts = inMemo && inMemo[_DYN_GET_ITEMS /* @min:%2egetItems */]();
268
+ if (!evts || !evts[_DYN_LENGTH /* @min:%2elength */]) {
272
269
  return;
273
270
  }
274
- if (curEvt[_DYN_PERSISTENCE /* @min:%2epersistence */] == EventPersistence.Critical) {
275
- criticalCnt_1++;
271
+ if (_splitEvts && mapKey && mapKey !== key) {
272
+ // if split evts is set to true
273
+ // specific mapkey is defined
274
+ // for key !== mapkey, only check if there are any events left in order to refresh timer
275
+ hasEvts_1 = hasEvts_1 || !!evts[_DYN_LENGTH /* @min:%2elength */];
276
+ return;
276
277
  }
277
- idx_1 = index;
278
- payloadArr_1[_DYN_PUSH /* @min:%2epush */](payload);
279
- });
280
- if (!payloadArr_1[_DYN_LENGTH /* @min:%2elength */]) {
281
- return;
282
- }
283
- var sentItems_1 = evts.slice(0, idx_1 + 1);
284
- _inMemoBatch = _inMemoBatch.createNew(_endpoint, inMemo[_DYN_GET_ITEMS /* @min:%2egetItems */]().slice(idx_1 + 1), _evtsLimitInMemo);
285
- var payloadData = null;
286
- if (_offineSupport && _offineSupport[_DYN_CREATE_ONE_DSPAYLOAD /* @min:%2ecreateOneDSPayload */]) {
287
- payloadData = _offineSupport[_DYN_CREATE_ONE_DSPAYLOAD /* @min:%2ecreateOneDSPayload */](sentItems_1);
288
- if (payloadData) {
289
- payloadData[_DYN_CRITICAL_CNT /* @min:%2ecriticalCnt */] = criticalCnt_1;
278
+ var payloadArr = [];
279
+ var size = 0;
280
+ var idx = -1;
281
+ var criticalCnt = 0;
282
+ arrForEach(evts, function (evt, index) {
283
+ var curEvt = evt;
284
+ idx = index;
285
+ var payload = _getPayload(curEvt);
286
+ size += payload[_DYN_LENGTH /* @min:%2elength */];
287
+ if (size > _maxBatchSize) {
288
+ return;
289
+ }
290
+ if (curEvt.persistence == EventPersistence[_DYN__CRITICAL /* @min:%2eCritical */]) {
291
+ criticalCnt++;
292
+ }
293
+ idx = index;
294
+ payloadArr[_DYN_PUSH /* @min:%2epush */](payload);
295
+ });
296
+ if (!payloadArr[_DYN_LENGTH /* @min:%2elength */]) {
297
+ return;
290
298
  }
291
- }
292
- else {
293
- payloadData = _constructPayloadData(payloadArr_1, criticalCnt_1);
294
- }
295
- var callback = function (res) {
296
- if (!res || !res[_DYN_STATE /* @min:%2estate */]) {
297
- return null;
299
+ var sentItems = evts.slice(0, idx + 1);
300
+ if (idx + 1 < evts[_DYN_LENGTH /* @min:%2elength */]) {
301
+ // keep track if there is any remaining events
302
+ hasEvts_1 = true;
298
303
  }
299
- var state = res[_DYN_STATE /* @min:%2estate */];
300
- if (state == 2 /* eBatchStoreStatus.Failure */) {
301
- if (!unload) {
302
- // for unload, just try to add each batch once
303
- arrForEach(sentItems_1, function (item) {
304
- _inMemoBatch[_DYN_ADD_EVENT /* @min:%2eaddEvent */](item);
305
- });
306
- _setupInMemoTimer();
307
- }
308
- else {
309
- // unload, drop events
310
- _evtDropNotification(sentItems_1, EventsDiscardedReason.NonRetryableStatus);
304
+ _inMemoMap[key] = inMemoBatch.createNew(_endpoint, arrSlice(inMemo[_DYN_GET_ITEMS /* @min:%2egetItems */](), idx + 1), _evtsLimitInMemo);
305
+ var payloadData = null;
306
+ if (_offineSupport && _offineSupport[_DYN_CREATE_ONE_DSPAYLOAD /* @min:%2ecreateOneDSPayload */]) {
307
+ payloadData = _offineSupport[_DYN_CREATE_ONE_DSPAYLOAD /* @min:%2ecreateOneDSPayload */](sentItems);
308
+ if (payloadData) {
309
+ payloadData[_DYN_CRITICAL_CNT /* @min:%2ecriticalCnt */] = criticalCnt;
311
310
  }
312
311
  }
313
312
  else {
314
- // if eBatchStoreStatus is success
315
- _storeNotification(sentItems_1);
313
+ payloadData = _constructPayloadData(payloadArr, criticalCnt);
316
314
  }
317
- };
318
- if (payloadData && _urlCfg && _urlCfg[_DYN_BATCH_HANDLER /* @min:%2ebatchHandler */]) {
319
- var promise = _urlCfg[_DYN_BATCH_HANDLER /* @min:%2ebatchHandler */].storeBatch(payloadData, callback, unload);
320
- _queueStorageEvent("storeBatch", promise);
321
- }
322
- if (_inMemoBatch && !_inMemoBatch[_DYN_COUNT /* @min:%2ecount */]()) {
315
+ var callback = function (res) {
316
+ if (!res || !res[_DYN_STATE /* @min:%2estate */]) {
317
+ return null;
318
+ }
319
+ var state = res[_DYN_STATE /* @min:%2estate */];
320
+ if (state == 2 /* eBatchStoreStatus.Failure */) {
321
+ if (!unload) {
322
+ // for unload, just try to add each batch once
323
+ arrForEach(sentItems, function (item) {
324
+ _addEvtToMap(item);
325
+ });
326
+ _setupInMemoTimer();
327
+ }
328
+ else {
329
+ // unload, drop events
330
+ _evtDropNotification(sentItems, EventsDiscardedReason.NonRetryableStatus);
331
+ }
332
+ }
333
+ else {
334
+ // if eBatchStoreStatus is success
335
+ _storeNotification(sentItems);
336
+ }
337
+ };
338
+ if (payloadData && _urlCfg && _urlCfg[_DYN_BATCH_HANDLER /* @min:%2ebatchHandler */]) {
339
+ var promise = _urlCfg[_DYN_BATCH_HANDLER /* @min:%2ebatchHandler */].storeBatch(payloadData, callback, unload);
340
+ _queueStorageEvent("storeBatch", promise);
341
+ }
342
+ });
343
+ // this is outside loop
344
+ if (!hasEvts_1) {
323
345
  _inMemoFlushTimer && _inMemoFlushTimer[_DYN_CANCEL /* @min:%2ecancel */]();
324
346
  }
325
347
  }
@@ -511,14 +533,24 @@ var OfflineChannel = /** @class */ (function (_super) {
511
533
  batchHandler: handler
512
534
  };
513
535
  _evtsLimitInMemo = storageConfig.eventsLimitInMem;
536
+ _inMemoMap = _inMemoMap || {};
537
+ var newMap_1 = {};
514
538
  // transfer previous events to new buffer
515
- var evts = null;
516
- var curEvts = _inMemoBatch && _inMemoBatch[_DYN_GET_ITEMS /* @min:%2egetItems */]();
517
- if (curEvts && curEvts[_DYN_LENGTH /* @min:%2elength */]) {
518
- evts = curEvts.slice(0);
519
- _inMemoBatch[_DYN_CLEAR /* @min:%2eclear */]();
520
- }
521
- _inMemoBatch = new InMemoryBatch(_self[_DYN_DIAG_LOG /* @min:%2ediagLog */](), curUrl, evts, _evtsLimitInMemo);
539
+ arrForEach(PersistenceKeys, function (key) {
540
+ // when init map, we will initize a in memo batch for each EventPersistence key
541
+ // evts to be transferred to new inMemo map
542
+ var evts = null;
543
+ if (_inMemoMap && _inMemoMap[key]) {
544
+ var inMemoBatch = _inMemoMap[key];
545
+ var curEvts = inMemoBatch && inMemoBatch[_DYN_GET_ITEMS /* @min:%2egetItems */]();
546
+ if (curEvts && curEvts[_DYN_LENGTH /* @min:%2elength */]) {
547
+ evts = arrSlice(curEvts);
548
+ inMemoBatch && inMemoBatch[_DYN_CLEAR /* @min:%2eclear */]();
549
+ }
550
+ }
551
+ newMap_1[key] = new InMemoryBatch(_self[_DYN_DIAG_LOG /* @min:%2ediagLog */](), curUrl, evts, _evtsLimitInMemo);
552
+ });
553
+ _inMemoMap = newMap_1;
522
554
  _inMemoTimerOut = storageConfig.inMemoMaxTime;
523
555
  var onlineConfig = ctx.getExtCfg(_primaryChannelId, {}) || {};
524
556
  _convertUndefined = onlineConfig.convertUndefined;
@@ -526,6 +558,7 @@ var OfflineChannel = /** @class */ (function (_super) {
526
558
  _setRetryTime();
527
559
  _maxBatchInterval = storageConfig.maxSentBatchInterval;
528
560
  _maxBatchSize = storageConfig.maxBatchsize;
561
+ _splitEvts = storageConfig.splitEvts;
529
562
  }
530
563
  _urlCfg = urlConfig;
531
564
  _endpoint = curUrl;
@@ -549,6 +582,26 @@ var OfflineChannel = /** @class */ (function (_super) {
549
582
  }
550
583
  return _dependencyPlugin;
551
584
  }
585
+ function _hasEvts() {
586
+ var hasEvts = false;
587
+ objForEachKey(_inMemoMap, function (key) {
588
+ var inMemoBatch = _inMemoMap[key];
589
+ if (inMemoBatch && inMemoBatch.count()) {
590
+ hasEvts = true;
591
+ return -1;
592
+ }
593
+ });
594
+ return hasEvts;
595
+ }
596
+ function _addEvtToMap(item) {
597
+ // if split evts is false, all events will be saved into EventPersistence.Normal batch
598
+ var mapKey = EventPersistence[_DYN__NORMAL /* @min:%2eNormal */];
599
+ if (_splitEvts && item[_DYN_PERSISTENCE /* @min:%2epersistence */]) {
600
+ mapKey = item[_DYN_PERSISTENCE /* @min:%2epersistence */];
601
+ }
602
+ var inMemoBatch = _inMemoMap[mapKey];
603
+ return inMemoBatch[_DYN_ADD_EVENT /* @min:%2eaddEvent */](item);
604
+ }
552
605
  function _callNotification(evtName, theArgs) {
553
606
  callNotification(_notificationManager, evtName, theArgs);
554
607
  }