@microsoft/applicationinsights-offlinechannel-js 0.2.2-nightly3.2405-28 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es5/applicationinsights-offlinechannel-js.js +208 -158
- package/dist/es5/applicationinsights-offlinechannel-js.js.map +1 -1
- package/dist/es5/applicationinsights-offlinechannel-js.min.js +2 -2
- package/dist/es5/applicationinsights-offlinechannel-js.min.js.map +1 -1
- package/dist-es5/Helpers/Utils.js +1 -1
- package/dist-es5/InMemoryBatch.js +1 -1
- package/dist-es5/Interfaces/IInMemoryBatch.js +1 -1
- package/dist-es5/Interfaces/IOfflineBatch.js +18 -2
- package/dist-es5/Interfaces/IOfflineBatch.js.map +1 -1
- package/dist-es5/Interfaces/IOfflineIndexDb.js +1 -1
- package/dist-es5/Interfaces/IOfflineProvider.js +7 -2
- package/dist-es5/Interfaces/IOfflineProvider.js.map +1 -1
- package/dist-es5/Interfaces/ISender.js +1 -1
- package/dist-es5/OfflineBatchHandler.js +3 -3
- package/dist-es5/OfflineBatchHandler.js.map +1 -1
- package/dist-es5/OfflineChannel.js +70 -42
- package/dist-es5/OfflineChannel.js.map +1 -1
- package/dist-es5/PayloadHelper.js +1 -1
- package/dist-es5/Providers/IndexDbHelper.js +1 -1
- package/dist-es5/Providers/IndexDbProvider.js +1 -1
- package/dist-es5/Providers/WebStorageProvider.js +1 -1
- package/dist-es5/Sender.js +1 -1
- package/dist-es5/__DynamicConstants.js +2 -1
- package/dist-es5/__DynamicConstants.js.map +1 -1
- package/dist-es5/applicationinsights-offlinechannel-js.js +3 -1
- package/dist-es5/applicationinsights-offlinechannel-js.js.map +1 -1
- package/package.json +62 -65
- package/types/applicationinsights-offlinechannel-js.d.ts +22 -1
- package/types/applicationinsights-offlinechannel-js.namespaced.d.ts +21 -1
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Offline Channel, 0.2.2
|
|
2
|
+
* Application Insights JavaScript SDK - Offline Channel, 0.2.2
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
import { createEnumStyle } from "@microsoft/applicationinsights-core-js";
|
|
8
|
+
export var StorageType = createEnumStyle({
|
|
9
|
+
Unknown: 0 /* eStorageType.Unknown */,
|
|
10
|
+
LocalStorage: 1 /* eStorageType.LocalStorage */,
|
|
11
|
+
SessionStorage: 2 /* eStorageType.SessionStorage */,
|
|
12
|
+
IndexDb: 3 /* eStorageType.IndexDb */
|
|
13
|
+
});
|
|
14
|
+
export var BatchSendStatus = createEnumStyle({
|
|
15
|
+
Complete: 1 /* eBatchSendStatus.Complete */,
|
|
16
|
+
Retry: 2 /* eBatchSendStatus.Retry */,
|
|
17
|
+
Drop: 3 /* eBatchSendStatus.Drop */,
|
|
18
|
+
Failure: 4 /* eBatchSendStatus.Failure */
|
|
19
|
+
});
|
|
20
|
+
export var BatchStoreStatus = createEnumStyle({
|
|
21
|
+
Success: 1 /* eBatchStoreStatus.Success */,
|
|
22
|
+
Failure: 2 /* eBatchStoreStatus.Failure */
|
|
23
|
+
});
|
|
8
24
|
//export declare type createOfflineBatchHandler = (storageType: eStorageType, cfg?: IOfflineBatchHandlerCfg) => IOfflineBatchHandler;
|
|
9
25
|
//# sourceMappingURL=IOfflineBatch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IOfflineBatch.js.map","sources":["IOfflineBatch.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nexport {};\r\n//export declare type createOfflineBatchHandler = (storageType: eStorageType, cfg?: IOfflineBatchHandlerCfg) => IOfflineBatchHandler;\r\n//# sourceMappingURL=IOfflineBatch.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA"}
|
|
1
|
+
{"version":3,"file":"IOfflineBatch.js.map","sources":["IOfflineBatch.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { createEnumStyle } from \"@microsoft/applicationinsights-core-js\";\r\nexport var StorageType = createEnumStyle({\r\n Unknown: 0 /* eStorageType.Unknown */,\r\n LocalStorage: 1 /* eStorageType.LocalStorage */,\r\n SessionStorage: 2 /* eStorageType.SessionStorage */,\r\n IndexDb: 3 /* eStorageType.IndexDb */\r\n});\r\nexport var BatchSendStatus = createEnumStyle({\r\n Complete: 1 /* eBatchSendStatus.Complete */,\r\n Retry: 2 /* eBatchSendStatus.Retry */,\r\n Drop: 3 /* eBatchSendStatus.Drop */,\r\n Failure: 4 /* eBatchSendStatus.Failure */\r\n});\r\nexport var BatchStoreStatus = createEnumStyle({\r\n Success: 1 /* eBatchStoreStatus.Success */,\r\n Failure: 2 /* eBatchStoreStatus.Failure */\r\n});\r\n//export declare type createOfflineBatchHandler = (storageType: eStorageType, cfg?: IOfflineBatchHandlerCfg) => IOfflineBatchHandler;\r\n//# sourceMappingURL=IOfflineBatch.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"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Offline Channel, 0.2.2
|
|
2
|
+
* Application Insights JavaScript SDK - Offline Channel, 0.2.2
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
import { createEnumStyle } from "@microsoft/applicationinsights-core-js";
|
|
8
|
+
export var StorageProviders = createEnumStyle({
|
|
9
|
+
LocalStorage: 1 /* eStorageProviders.LocalStorage */,
|
|
10
|
+
SessionStorage: 2 /* eStorageProviders.SessionStorage */,
|
|
11
|
+
IndexedDb: 3 /* eStorageProviders.IndexedDb */
|
|
12
|
+
});
|
|
8
13
|
//# sourceMappingURL=IOfflineProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IOfflineProvider.js.map","sources":["IOfflineProvider.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nexport {};\r\n//# sourceMappingURL=IOfflineProvider.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA"}
|
|
1
|
+
{"version":3,"file":"IOfflineProvider.js.map","sources":["IOfflineProvider.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { createEnumStyle } from \"@microsoft/applicationinsights-core-js\";\r\nexport var StorageProviders = createEnumStyle({\r\n LocalStorage: 1 /* eStorageProviders.LocalStorage */,\r\n SessionStorage: 2 /* eStorageProviders.SessionStorage */,\r\n IndexedDb: 3 /* eStorageProviders.IndexedDb */\r\n});\r\n//# sourceMappingURL=IOfflineProvider.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Offline Channel, 0.2.2
|
|
2
|
+
* Application Insights JavaScript SDK - Offline Channel, 0.2.2
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -9,7 +9,7 @@ import { isNullOrUndefined, isObject } from "@microsoft/applicationinsights-core
|
|
|
9
9
|
import { createPromise, doAwaitResponse } from "@nevware21/ts-async";
|
|
10
10
|
import { IndexedDbProvider } from "./Providers/IndexDbProvider";
|
|
11
11
|
import { WebStorageProvider } from "./Providers/WebStorageProvider";
|
|
12
|
-
import { _DYN_ADD_EVENT, _DYN_ATTEMP_CNT, _DYN_CLEAR, _DYN_DATA, _DYN_DIAG_LOG, _DYN_GET_NEXT_BATCH, _DYN_INDEX_OF, _DYN_INITIALIZE, _DYN_IS_ARR, _DYN_ITEM_CTX, _DYN_LENGTH, _DYN_REJECTED, _DYN_REMOVE_EVENTS, _DYN_SEND_POST, _DYN_STATE, _DYN_STORAGE_CONFIG, _DYN_TEARDOWN, _DYN_VALUE } from "./__DynamicConstants";
|
|
12
|
+
import { _DYN_ADD_EVENT, _DYN_ATTEMP_CNT, _DYN_CLEAR, _DYN_DATA, _DYN_DIAG_LOG, _DYN_GET_NEXT_BATCH, _DYN_INDEX_OF, _DYN_INITIALIZE, _DYN_IS_ARR, _DYN_ITEM_CTX, _DYN_LENGTH, _DYN_REJECTED, _DYN_REMOVE_EVENTS, _DYN_SEND_NEXT_BATCH, _DYN_SEND_POST, _DYN_STATE, _DYN_STORAGE_CONFIG, _DYN_TEARDOWN, _DYN_VALUE } from "./__DynamicConstants";
|
|
13
13
|
var MaxStorageProviderConfig = 2;
|
|
14
14
|
var NoProviderErrMsg = "No provider is available";
|
|
15
15
|
var OfflineBatchHandler = /** @class */ (function () {
|
|
@@ -79,7 +79,7 @@ var OfflineBatchHandler = /** @class */ (function () {
|
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
81
|
};
|
|
82
|
-
_self
|
|
82
|
+
_self[_DYN_SEND_NEXT_BATCH /* @min:%2esendNextBatch */] = function (cb, sync, xhrOverride, cnt) {
|
|
83
83
|
if (cnt === void 0) { cnt = 1; }
|
|
84
84
|
return createPromise(function (resolve, reject) {
|
|
85
85
|
if (!_provider && !_unloadProvider) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OfflineBatchHandler.js.map","sources":["OfflineBatchHandler.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, isObject } from \"@microsoft/applicationinsights-core-js\";\r\nimport { createPromise, doAwaitResponse } from \"@nevware21/ts-async\";\r\nimport { IndexedDbProvider } from \"./Providers/IndexDbProvider\";\r\nimport { WebStorageProvider } from \"./Providers/WebStorageProvider\";\r\nimport { _DYN_ADD_EVENT, _DYN_ATTEMP_CNT, _DYN_CLEAR, _DYN_DATA, _DYN_DIAG_LOG, _DYN_GET_NEXT_BATCH, _DYN_INDEX_OF, _DYN_INITIALIZE, _DYN_IS_ARR, _DYN_ITEM_CTX, _DYN_LENGTH, _DYN_REJECTED, _DYN_REMOVE_EVENTS, _DYN_SEND_POST, _DYN_STATE, _DYN_STORAGE_CONFIG, _DYN_TEARDOWN, _DYN_VALUE } from \"./__DynamicConstants\";\r\nvar MaxStorageProviderConfig = 2;\r\nvar NoProviderErrMsg = \"No provider is available\";\r\nvar OfflineBatchHandler = /** @class */ (function () {\r\n function OfflineBatchHandler(logger, unloadHookContainer) {\r\n dynamicProto(OfflineBatchHandler, this, function (_self) {\r\n var _isInitialized;\r\n var _logger;\r\n var _provider;\r\n var _unloadProvider;\r\n var _itemCtx;\r\n var _maxRetryCnt;\r\n var _retryCodes;\r\n _initDefaults();\r\n _self[_DYN_INITIALIZE /* @min:%2einitialize */] = function (providerContext) {\r\n // TODO: handle provider change\r\n try {\r\n if (!_isInitialized) {\r\n _logger = logger || providerContext.itemCtx[_DYN_DIAG_LOG /* @min:%2ediagLog */]();\r\n _itemCtx = providerContext[_DYN_ITEM_CTX /* @min:%2eitemCtx */];\r\n _provider = _initProvider(providerContext);\r\n var storeCfg = providerContext[_DYN_STORAGE_CONFIG /* @min:%2estorageConfig */] || {};\r\n var retry = storeCfg.maxRetry;\r\n _maxRetryCnt = !isNullOrUndefined(retry) ? retry : 2;\r\n _retryCodes = (storeCfg.senderCfg || {}).retryCodes;\r\n if (_provider) {\r\n _isInitialized = true;\r\n }\r\n }\r\n }\r\n catch (e) {\r\n _isInitialized = false;\r\n }\r\n return _isInitialized;\r\n };\r\n _self[\"_getDbgPlgTargets\"] = function () {\r\n return [_provider, _isInitialized, _unloadProvider];\r\n };\r\n _self.storeBatch = function (batch, cb, sync) {\r\n var provider = _provider;\r\n if (!!sync) {\r\n provider = _unloadProvider;\r\n }\r\n return createPromise(function (resolve, reject) {\r\n if (!provider) {\r\n reject(new Error(NoProviderErrMsg));\r\n }\r\n var evt = _getOfflineEvt(batch);\r\n return doAwaitResponse(provider[_DYN_ADD_EVENT /* @min:%2eaddEvent */](evt.id, evt, _itemCtx), function (response) {\r\n try {\r\n var evt_1 = response[_DYN_VALUE /* @min:%2evalue */] || response.reason || [];\r\n var state = 2 /* eBatchStoreStatus.Failure */;\r\n if (!response[_DYN_REJECTED /* @min:%2erejected */]) {\r\n state = 1 /* eBatchStoreStatus.Success */;\r\n }\r\n var res = { state: state, item: evt_1 };\r\n try {\r\n cb && cb(res);\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n resolve(res);\r\n }\r\n catch (e) {\r\n reject(e);\r\n }\r\n });\r\n });\r\n };\r\n _self.sendNextBatch = function (cb, sync, xhrOverride, cnt) {\r\n if (cnt === void 0) { cnt = 1; }\r\n return createPromise(function (resolve, reject) {\r\n if (!_provider && !_unloadProvider) {\r\n reject(new Error(NoProviderErrMsg));\r\n }\r\n function storeResolve(result) {\r\n try {\r\n cb && cb(result);\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n resolve(result);\r\n }\r\n var provider = _provider;\r\n try {\r\n if (_unloadProvider) {\r\n doAwaitResponse(_unloadProvider[_DYN_GET_NEXT_BATCH /* @min:%2egetNextBatch */](), function (res) {\r\n if (res && !res[_DYN_REJECTED /* @min:%2erejected */]) {\r\n var unloadEvts = res[_DYN_VALUE /* @min:%2evalue */];\r\n if (unloadEvts && unloadEvts[_DYN_LENGTH /* @min:%2elength */]) {\r\n // always try to send ones from local storage\r\n provider = _unloadProvider;\r\n return _handleNextBatch(unloadEvts);\r\n }\r\n }\r\n return _sendNextBatch();\r\n });\r\n }\r\n else {\r\n return _sendNextBatch();\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n reject(e);\r\n }\r\n function _sendNextBatch() {\r\n return doAwaitResponse(provider[_DYN_GET_NEXT_BATCH /* @min:%2egetNextBatch */](), function (response) {\r\n try {\r\n if (!response || response[_DYN_REJECTED /* @min:%2erejected */]) {\r\n var res = { state: 4 /* eBatchSendStatus.Failure */, data: response.reason };\r\n storeResolve(res);\r\n return;\r\n }\r\n var evts = response[_DYN_VALUE /* @min:%2evalue */] || [];\r\n return _handleNextBatch(evts);\r\n }\r\n catch (e) {\r\n reject(e);\r\n }\r\n });\r\n }\r\n function _handleNextBatch(evts) {\r\n var result = { state: 1 /* eBatchSendStatus.Complete */, data: null };\r\n if (evts[_DYN_LENGTH /* @min:%2elength */]) {\r\n // make sure doawait has resolve\r\n return doAwaitResponse(provider[_DYN_REMOVE_EVENTS /* @min:%2eremoveEvents */](evts), function (res) {\r\n if (res && !res.rejected && res[_DYN_VALUE /* @min:%2evalue */]) {\r\n var deletedItems = res[_DYN_VALUE /* @min:%2evalue */];\r\n var _loop_1 = function (lp) {\r\n try {\r\n var evt_2 = evts[lp];\r\n result[_DYN_DATA /* @min:%2edata */] = evt_2; // add data\r\n if (xhrOverride && xhrOverride[_DYN_SEND_POST /* @min:%2esendPOST */]) {\r\n evt_2[_DYN_ATTEMP_CNT /* @min:%2eattempCnt */]++;\r\n var sender = xhrOverride[_DYN_SEND_POST /* @min:%2esendPOST */]; // use transports\r\n var onCompleteCallback = function (status, headers, res) {\r\n if (status == 200) { // status code (e.g: invalid key) drop payload\r\n result[_DYN_STATE /* @min:%2estate */] = 1 /* eBatchSendStatus.Complete */;\r\n }\r\n else {\r\n var isRetriable = _isRetriable(evt_2, status);\r\n if (isRetriable) {\r\n result[_DYN_STATE /* @min:%2estate */] = 2 /* eBatchSendStatus.Retry */;\r\n _unloadProvider && _unloadProvider[_DYN_ADD_EVENT /* @min:%2eaddEvent */](evt_2.id, evt_2, _itemCtx);\r\n }\r\n else {\r\n result[_DYN_STATE /* @min:%2estate */] = 3 /* eBatchSendStatus.Drop */;\r\n }\r\n }\r\n storeResolve(result);\r\n };\r\n return { value: doAwaitResponse(sender(evt_2, onCompleteCallback, sync), function (res) {\r\n // do nothing, because it should be resolved in callback\r\n }) };\r\n }\r\n // call resolve\r\n result[_DYN_STATE /* @min:%2estate */] = 3 /* eBatchSendStatus.Drop */;\r\n storeResolve(result);\r\n return { value: void 0 };\r\n }\r\n catch (e) {\r\n reject(e);\r\n }\r\n };\r\n for (var lp = 0; lp < deletedItems[_DYN_LENGTH /* @min:%2elength */]; lp++) {\r\n var state_1 = _loop_1(lp);\r\n if (typeof state_1 === \"object\")\r\n return state_1.value;\r\n }\r\n // this case should never happen because this function is called after we confirm that evt is available\r\n // add resolve here in case\r\n result[_DYN_STATE /* @min:%2estate */] = 1 /* eBatchSendStatus.Complete */;\r\n storeResolve(result);\r\n return;\r\n }\r\n // if can not delete first, resolve\r\n result[_DYN_STATE /* @min:%2estate */] = 4 /* eBatchSendStatus.Failure */;\r\n result[_DYN_DATA /* @min:%2edata */] = res.reason;\r\n storeResolve(result);\r\n return;\r\n });\r\n }\r\n storeResolve(result);\r\n }\r\n });\r\n };\r\n _self.hasStoredBatch = function (cb) {\r\n return createPromise(function (resolve, reject) {\r\n if (!_provider) {\r\n reject(new Error(NoProviderErrMsg));\r\n }\r\n return doAwaitResponse(_provider[_DYN_GET_NEXT_BATCH /* @min:%2egetNextBatch */](), function (response) {\r\n try {\r\n var evts = response[_DYN_VALUE /* @min:%2evalue */] || [];\r\n var hasEvts = evts[_DYN_LENGTH /* @min:%2elength */] > 0;\r\n cb && cb(hasEvts);\r\n resolve(hasEvts);\r\n }\r\n catch (e) {\r\n reject(e);\r\n }\r\n });\r\n });\r\n };\r\n _self.cleanStorage = function (cb) {\r\n return createPromise(function (resolve, reject) {\r\n // note: doawaitresponse currently returns undefined\r\n if (!_provider) {\r\n reject(new Error(NoProviderErrMsg));\r\n }\r\n return doAwaitResponse(_provider[_DYN_CLEAR /* @min:%2eclear */](), function (response) {\r\n try {\r\n var cnt = 0;\r\n if (!response[_DYN_REJECTED /* @min:%2erejected */]) {\r\n var evts = response[_DYN_VALUE /* @min:%2evalue */] || [];\r\n cnt = evts[_DYN_LENGTH /* @min:%2elength */];\r\n }\r\n var res = { batchCnt: cnt };\r\n cb && cb(res); // get value. make sure to use callback\r\n resolve(res); // won't get val\r\n }\r\n catch (e) {\r\n reject(e);\r\n }\r\n });\r\n });\r\n };\r\n _self[_DYN_TEARDOWN /* @min:%2eteardown */] = function (unloadCtx, unloadState) {\r\n _provider && _provider[_DYN_TEARDOWN /* @min:%2eteardown */]();\r\n _initDefaults();\r\n };\r\n function _initDefaults() {\r\n _provider = null;\r\n _unloadProvider = null;\r\n _isInitialized = false;\r\n _maxRetryCnt = null;\r\n _retryCodes = null;\r\n }\r\n function _tryGetIndexedDbProvider(providerContext) {\r\n var newProvider = new IndexedDbProvider(undefined, unloadHookContainer);\r\n if (!newProvider[_DYN_INITIALIZE /* @min:%2einitialize */](providerContext)) {\r\n // Failed to initialize the provider\r\n newProvider = null;\r\n }\r\n return newProvider;\r\n }\r\n function _tryGetWebStorageProvider(storageType, providerContext) {\r\n var newProvider = new WebStorageProvider(storageType, undefined, unloadHookContainer);\r\n if (!newProvider[_DYN_INITIALIZE /* @min:%2einitialize */](providerContext)) {\r\n // Failed to initialize the provider\r\n newProvider = null;\r\n }\r\n return newProvider;\r\n }\r\n function _initProvider(providerContext) {\r\n var providers = providerContext[_DYN_STORAGE_CONFIG /* @min:%2estorageConfig */].providers;\r\n var newProvider = null;\r\n var lp = 0;\r\n while (!newProvider && lp < providers[_DYN_LENGTH /* @min:%2elength */] && lp < MaxStorageProviderConfig) {\r\n switch (providers[lp++]) {\r\n case 1 /* eStorageProviders.LocalStorage */:\r\n newProvider = _tryGetWebStorageProvider(\"localStorage\", providerContext);\r\n _unloadProvider = newProvider;\r\n break;\r\n case 2 /* eStorageProviders.SessionStorage */:\r\n newProvider = _tryGetWebStorageProvider(\"sessionStorage\", providerContext);\r\n _unloadProvider = newProvider;\r\n break;\r\n case 3 /* eStorageProviders.IndexedDb */:\r\n newProvider = _tryGetIndexedDbProvider(providerContext);\r\n _unloadProvider = _tryGetWebStorageProvider(\"localStorage\", providerContext);\r\n }\r\n }\r\n return newProvider;\r\n }\r\n function _getOfflineEvt(batch) {\r\n var item = batch;\r\n // TODO: add details\r\n var data = item[_DYN_DATA /* @min:%2edata */];\r\n if (data) {\r\n var isArr = isObject(data);\r\n item[_DYN_IS_ARR /* @min:%2eisArr */] = isArr;\r\n }\r\n return item;\r\n }\r\n /**\r\n * Checks if the SDK should resend the payload after receiving this status code from the backend.\r\n * @param statusCode\r\n */\r\n function _isRetriable(item, statusCode) {\r\n if (!_shouldSend(item)) {\r\n return false;\r\n }\r\n // retryCodes = [] means should not retry\r\n if (!isNullOrUndefined(_retryCodes)) {\r\n return _retryCodes[_DYN_LENGTH /* @min:%2elength */] && _retryCodes[_DYN_INDEX_OF /* @min:%2eindexOf */](statusCode) > -1;\r\n }\r\n return statusCode === 401 // Unauthorized\r\n || statusCode === 403 // Forbidden\r\n || statusCode === 408 // Timeout\r\n || statusCode === 429 // Too many requests.\r\n || statusCode === 500 // Internal server error.\r\n || statusCode === 502 // Bad Gateway.\r\n || statusCode === 503 // Service unavailable.\r\n || statusCode === 504; // Gateway timeout.\r\n }\r\n function _shouldSend(item) {\r\n if (item && item[_DYN_DATA /* @min:%2edata */]) {\r\n item[_DYN_ATTEMP_CNT /* @min:%2eattempCnt */] = item[_DYN_ATTEMP_CNT /* @min:%2eattempCnt */] || 0;\r\n return item[_DYN_ATTEMP_CNT /* @min:%2eattempCnt */] <= _maxRetryCnt;\r\n }\r\n return false;\r\n }\r\n });\r\n }\r\n /**\r\n * Initializes the provider using the config\r\n * @returns True if the provider is initialized and available for use otherwise false\r\n */\r\n OfflineBatchHandler.prototype.initialize = function (providerContext) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n OfflineBatchHandler.prototype.storeBatch = function (batch, cb, sync) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n OfflineBatchHandler.prototype.sendNextBatch = function (cb, sync, xhrOverride, cnt) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n OfflineBatchHandler.prototype.hasStoredBatch = function (callback) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n OfflineBatchHandler.prototype.cleanStorage = function (cb) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n OfflineBatchHandler.prototype.teardown = function (unloadCtx, unloadState) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n return OfflineBatchHandler;\r\n}());\r\nexport { OfflineBatchHandler };\r\n//# sourceMappingURL=OfflineBatchHandler.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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;2DA2BM,CAAC;;;;;+BACwB;AAC/B;AACA;AACA"}
|
|
1
|
+
{"version":3,"file":"OfflineBatchHandler.js.map","sources":["OfflineBatchHandler.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, isObject } from \"@microsoft/applicationinsights-core-js\";\r\nimport { createPromise, doAwaitResponse } from \"@nevware21/ts-async\";\r\nimport { IndexedDbProvider } from \"./Providers/IndexDbProvider\";\r\nimport { WebStorageProvider } from \"./Providers/WebStorageProvider\";\r\nimport { _DYN_ADD_EVENT, _DYN_ATTEMP_CNT, _DYN_CLEAR, _DYN_DATA, _DYN_DIAG_LOG, _DYN_GET_NEXT_BATCH, _DYN_INDEX_OF, _DYN_INITIALIZE, _DYN_IS_ARR, _DYN_ITEM_CTX, _DYN_LENGTH, _DYN_REJECTED, _DYN_REMOVE_EVENTS, _DYN_SEND_NEXT_BATCH, _DYN_SEND_POST, _DYN_STATE, _DYN_STORAGE_CONFIG, _DYN_TEARDOWN, _DYN_VALUE } from \"./__DynamicConstants\";\r\nvar MaxStorageProviderConfig = 2;\r\nvar NoProviderErrMsg = \"No provider is available\";\r\nvar OfflineBatchHandler = /** @class */ (function () {\r\n function OfflineBatchHandler(logger, unloadHookContainer) {\r\n dynamicProto(OfflineBatchHandler, this, function (_self) {\r\n var _isInitialized;\r\n var _logger;\r\n var _provider;\r\n var _unloadProvider;\r\n var _itemCtx;\r\n var _maxRetryCnt;\r\n var _retryCodes;\r\n _initDefaults();\r\n _self[_DYN_INITIALIZE /* @min:%2einitialize */] = function (providerContext) {\r\n // TODO: handle provider change\r\n try {\r\n if (!_isInitialized) {\r\n _logger = logger || providerContext.itemCtx[_DYN_DIAG_LOG /* @min:%2ediagLog */]();\r\n _itemCtx = providerContext[_DYN_ITEM_CTX /* @min:%2eitemCtx */];\r\n _provider = _initProvider(providerContext);\r\n var storeCfg = providerContext[_DYN_STORAGE_CONFIG /* @min:%2estorageConfig */] || {};\r\n var retry = storeCfg.maxRetry;\r\n _maxRetryCnt = !isNullOrUndefined(retry) ? retry : 2;\r\n _retryCodes = (storeCfg.senderCfg || {}).retryCodes;\r\n if (_provider) {\r\n _isInitialized = true;\r\n }\r\n }\r\n }\r\n catch (e) {\r\n _isInitialized = false;\r\n }\r\n return _isInitialized;\r\n };\r\n _self[\"_getDbgPlgTargets\"] = function () {\r\n return [_provider, _isInitialized, _unloadProvider];\r\n };\r\n _self.storeBatch = function (batch, cb, sync) {\r\n var provider = _provider;\r\n if (!!sync) {\r\n provider = _unloadProvider;\r\n }\r\n return createPromise(function (resolve, reject) {\r\n if (!provider) {\r\n reject(new Error(NoProviderErrMsg));\r\n }\r\n var evt = _getOfflineEvt(batch);\r\n return doAwaitResponse(provider[_DYN_ADD_EVENT /* @min:%2eaddEvent */](evt.id, evt, _itemCtx), function (response) {\r\n try {\r\n var evt_1 = response[_DYN_VALUE /* @min:%2evalue */] || response.reason || [];\r\n var state = 2 /* eBatchStoreStatus.Failure */;\r\n if (!response[_DYN_REJECTED /* @min:%2erejected */]) {\r\n state = 1 /* eBatchStoreStatus.Success */;\r\n }\r\n var res = { state: state, item: evt_1 };\r\n try {\r\n cb && cb(res);\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n resolve(res);\r\n }\r\n catch (e) {\r\n reject(e);\r\n }\r\n });\r\n });\r\n };\r\n _self[_DYN_SEND_NEXT_BATCH /* @min:%2esendNextBatch */] = function (cb, sync, xhrOverride, cnt) {\r\n if (cnt === void 0) { cnt = 1; }\r\n return createPromise(function (resolve, reject) {\r\n if (!_provider && !_unloadProvider) {\r\n reject(new Error(NoProviderErrMsg));\r\n }\r\n function storeResolve(result) {\r\n try {\r\n cb && cb(result);\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n resolve(result);\r\n }\r\n var provider = _provider;\r\n try {\r\n if (_unloadProvider) {\r\n doAwaitResponse(_unloadProvider[_DYN_GET_NEXT_BATCH /* @min:%2egetNextBatch */](), function (res) {\r\n if (res && !res[_DYN_REJECTED /* @min:%2erejected */]) {\r\n var unloadEvts = res[_DYN_VALUE /* @min:%2evalue */];\r\n if (unloadEvts && unloadEvts[_DYN_LENGTH /* @min:%2elength */]) {\r\n // always try to send ones from local storage\r\n provider = _unloadProvider;\r\n return _handleNextBatch(unloadEvts);\r\n }\r\n }\r\n return _sendNextBatch();\r\n });\r\n }\r\n else {\r\n return _sendNextBatch();\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n reject(e);\r\n }\r\n function _sendNextBatch() {\r\n return doAwaitResponse(provider[_DYN_GET_NEXT_BATCH /* @min:%2egetNextBatch */](), function (response) {\r\n try {\r\n if (!response || response[_DYN_REJECTED /* @min:%2erejected */]) {\r\n var res = { state: 4 /* eBatchSendStatus.Failure */, data: response.reason };\r\n storeResolve(res);\r\n return;\r\n }\r\n var evts = response[_DYN_VALUE /* @min:%2evalue */] || [];\r\n return _handleNextBatch(evts);\r\n }\r\n catch (e) {\r\n reject(e);\r\n }\r\n });\r\n }\r\n function _handleNextBatch(evts) {\r\n var result = { state: 1 /* eBatchSendStatus.Complete */, data: null };\r\n if (evts[_DYN_LENGTH /* @min:%2elength */]) {\r\n // make sure doawait has resolve\r\n return doAwaitResponse(provider[_DYN_REMOVE_EVENTS /* @min:%2eremoveEvents */](evts), function (res) {\r\n if (res && !res.rejected && res[_DYN_VALUE /* @min:%2evalue */]) {\r\n var deletedItems = res[_DYN_VALUE /* @min:%2evalue */];\r\n var _loop_1 = function (lp) {\r\n try {\r\n var evt_2 = evts[lp];\r\n result[_DYN_DATA /* @min:%2edata */] = evt_2; // add data\r\n if (xhrOverride && xhrOverride[_DYN_SEND_POST /* @min:%2esendPOST */]) {\r\n evt_2[_DYN_ATTEMP_CNT /* @min:%2eattempCnt */]++;\r\n var sender = xhrOverride[_DYN_SEND_POST /* @min:%2esendPOST */]; // use transports\r\n var onCompleteCallback = function (status, headers, res) {\r\n if (status == 200) { // status code (e.g: invalid key) drop payload\r\n result[_DYN_STATE /* @min:%2estate */] = 1 /* eBatchSendStatus.Complete */;\r\n }\r\n else {\r\n var isRetriable = _isRetriable(evt_2, status);\r\n if (isRetriable) {\r\n result[_DYN_STATE /* @min:%2estate */] = 2 /* eBatchSendStatus.Retry */;\r\n _unloadProvider && _unloadProvider[_DYN_ADD_EVENT /* @min:%2eaddEvent */](evt_2.id, evt_2, _itemCtx);\r\n }\r\n else {\r\n result[_DYN_STATE /* @min:%2estate */] = 3 /* eBatchSendStatus.Drop */;\r\n }\r\n }\r\n storeResolve(result);\r\n };\r\n return { value: doAwaitResponse(sender(evt_2, onCompleteCallback, sync), function (res) {\r\n // do nothing, because it should be resolved in callback\r\n }) };\r\n }\r\n // call resolve\r\n result[_DYN_STATE /* @min:%2estate */] = 3 /* eBatchSendStatus.Drop */;\r\n storeResolve(result);\r\n return { value: void 0 };\r\n }\r\n catch (e) {\r\n reject(e);\r\n }\r\n };\r\n for (var lp = 0; lp < deletedItems[_DYN_LENGTH /* @min:%2elength */]; lp++) {\r\n var state_1 = _loop_1(lp);\r\n if (typeof state_1 === \"object\")\r\n return state_1.value;\r\n }\r\n // this case should never happen because this function is called after we confirm that evt is available\r\n // add resolve here in case\r\n result[_DYN_STATE /* @min:%2estate */] = 1 /* eBatchSendStatus.Complete */;\r\n storeResolve(result);\r\n return;\r\n }\r\n // if can not delete first, resolve\r\n result[_DYN_STATE /* @min:%2estate */] = 4 /* eBatchSendStatus.Failure */;\r\n result[_DYN_DATA /* @min:%2edata */] = res.reason;\r\n storeResolve(result);\r\n return;\r\n });\r\n }\r\n storeResolve(result);\r\n }\r\n });\r\n };\r\n _self.hasStoredBatch = function (cb) {\r\n return createPromise(function (resolve, reject) {\r\n if (!_provider) {\r\n reject(new Error(NoProviderErrMsg));\r\n }\r\n return doAwaitResponse(_provider[_DYN_GET_NEXT_BATCH /* @min:%2egetNextBatch */](), function (response) {\r\n try {\r\n var evts = response[_DYN_VALUE /* @min:%2evalue */] || [];\r\n var hasEvts = evts[_DYN_LENGTH /* @min:%2elength */] > 0;\r\n cb && cb(hasEvts);\r\n resolve(hasEvts);\r\n }\r\n catch (e) {\r\n reject(e);\r\n }\r\n });\r\n });\r\n };\r\n _self.cleanStorage = function (cb) {\r\n return createPromise(function (resolve, reject) {\r\n // note: doawaitresponse currently returns undefined\r\n if (!_provider) {\r\n reject(new Error(NoProviderErrMsg));\r\n }\r\n return doAwaitResponse(_provider[_DYN_CLEAR /* @min:%2eclear */](), function (response) {\r\n try {\r\n var cnt = 0;\r\n if (!response[_DYN_REJECTED /* @min:%2erejected */]) {\r\n var evts = response[_DYN_VALUE /* @min:%2evalue */] || [];\r\n cnt = evts[_DYN_LENGTH /* @min:%2elength */];\r\n }\r\n var res = { batchCnt: cnt };\r\n cb && cb(res); // get value. make sure to use callback\r\n resolve(res); // won't get val\r\n }\r\n catch (e) {\r\n reject(e);\r\n }\r\n });\r\n });\r\n };\r\n _self[_DYN_TEARDOWN /* @min:%2eteardown */] = function (unloadCtx, unloadState) {\r\n _provider && _provider[_DYN_TEARDOWN /* @min:%2eteardown */]();\r\n _initDefaults();\r\n };\r\n function _initDefaults() {\r\n _provider = null;\r\n _unloadProvider = null;\r\n _isInitialized = false;\r\n _maxRetryCnt = null;\r\n _retryCodes = null;\r\n }\r\n function _tryGetIndexedDbProvider(providerContext) {\r\n var newProvider = new IndexedDbProvider(undefined, unloadHookContainer);\r\n if (!newProvider[_DYN_INITIALIZE /* @min:%2einitialize */](providerContext)) {\r\n // Failed to initialize the provider\r\n newProvider = null;\r\n }\r\n return newProvider;\r\n }\r\n function _tryGetWebStorageProvider(storageType, providerContext) {\r\n var newProvider = new WebStorageProvider(storageType, undefined, unloadHookContainer);\r\n if (!newProvider[_DYN_INITIALIZE /* @min:%2einitialize */](providerContext)) {\r\n // Failed to initialize the provider\r\n newProvider = null;\r\n }\r\n return newProvider;\r\n }\r\n function _initProvider(providerContext) {\r\n var providers = providerContext[_DYN_STORAGE_CONFIG /* @min:%2estorageConfig */].providers;\r\n var newProvider = null;\r\n var lp = 0;\r\n while (!newProvider && lp < providers[_DYN_LENGTH /* @min:%2elength */] && lp < MaxStorageProviderConfig) {\r\n switch (providers[lp++]) {\r\n case 1 /* eStorageProviders.LocalStorage */:\r\n newProvider = _tryGetWebStorageProvider(\"localStorage\", providerContext);\r\n _unloadProvider = newProvider;\r\n break;\r\n case 2 /* eStorageProviders.SessionStorage */:\r\n newProvider = _tryGetWebStorageProvider(\"sessionStorage\", providerContext);\r\n _unloadProvider = newProvider;\r\n break;\r\n case 3 /* eStorageProviders.IndexedDb */:\r\n newProvider = _tryGetIndexedDbProvider(providerContext);\r\n _unloadProvider = _tryGetWebStorageProvider(\"localStorage\", providerContext);\r\n }\r\n }\r\n return newProvider;\r\n }\r\n function _getOfflineEvt(batch) {\r\n var item = batch;\r\n // TODO: add details\r\n var data = item[_DYN_DATA /* @min:%2edata */];\r\n if (data) {\r\n var isArr = isObject(data);\r\n item[_DYN_IS_ARR /* @min:%2eisArr */] = isArr;\r\n }\r\n return item;\r\n }\r\n /**\r\n * Checks if the SDK should resend the payload after receiving this status code from the backend.\r\n * @param statusCode\r\n */\r\n function _isRetriable(item, statusCode) {\r\n if (!_shouldSend(item)) {\r\n return false;\r\n }\r\n // retryCodes = [] means should not retry\r\n if (!isNullOrUndefined(_retryCodes)) {\r\n return _retryCodes[_DYN_LENGTH /* @min:%2elength */] && _retryCodes[_DYN_INDEX_OF /* @min:%2eindexOf */](statusCode) > -1;\r\n }\r\n return statusCode === 401 // Unauthorized\r\n || statusCode === 403 // Forbidden\r\n || statusCode === 408 // Timeout\r\n || statusCode === 429 // Too many requests.\r\n || statusCode === 500 // Internal server error.\r\n || statusCode === 502 // Bad Gateway.\r\n || statusCode === 503 // Service unavailable.\r\n || statusCode === 504; // Gateway timeout.\r\n }\r\n function _shouldSend(item) {\r\n if (item && item[_DYN_DATA /* @min:%2edata */]) {\r\n item[_DYN_ATTEMP_CNT /* @min:%2eattempCnt */] = item[_DYN_ATTEMP_CNT /* @min:%2eattempCnt */] || 0;\r\n return item[_DYN_ATTEMP_CNT /* @min:%2eattempCnt */] <= _maxRetryCnt;\r\n }\r\n return false;\r\n }\r\n });\r\n }\r\n /**\r\n * Initializes the provider using the config\r\n * @returns True if the provider is initialized and available for use otherwise false\r\n */\r\n OfflineBatchHandler.prototype.initialize = function (providerContext) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n OfflineBatchHandler.prototype.storeBatch = function (batch, cb, sync) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n OfflineBatchHandler.prototype.sendNextBatch = function (cb, sync, xhrOverride, cnt) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n OfflineBatchHandler.prototype.hasStoredBatch = function (callback) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n OfflineBatchHandler.prototype.cleanStorage = function (cb) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n OfflineBatchHandler.prototype.teardown = function (unloadCtx, unloadState) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n return OfflineBatchHandler;\r\n}());\r\nexport { OfflineBatchHandler };\r\n//# sourceMappingURL=OfflineBatchHandler.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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;2DA2BM,CAAC;;;;;+BACwB;AAC/B;AACA;AACA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Offline Channel, 0.2.2
|
|
2
|
+
* Application Insights JavaScript SDK - Offline Channel, 0.2.2
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -15,8 +15,8 @@ import { InMemoryBatch } from "./InMemoryBatch";
|
|
|
15
15
|
import { OfflineBatchHandler } from "./OfflineBatchHandler";
|
|
16
16
|
import { isValidPersistenceLevel } from "./Providers/IndexDbProvider";
|
|
17
17
|
import { Sender } from "./Sender";
|
|
18
|
-
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_STATE, _DYN_TEARDOWN } from "./__DynamicConstants";
|
|
19
|
-
var version = '0.2.2
|
|
18
|
+
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";
|
|
19
|
+
var version = '0.2.2';
|
|
20
20
|
var DefaultOfflineIdentifier = "OfflineChannel";
|
|
21
21
|
var DefaultBatchInterval = 15000;
|
|
22
22
|
var DefaultInMemoMaxTime = 15000;
|
|
@@ -71,10 +71,13 @@ var OfflineChannel = /** @class */ (function (_super) {
|
|
|
71
71
|
var _overrideIkey;
|
|
72
72
|
var _evtsLimitInMemo;
|
|
73
73
|
var _notificationManager;
|
|
74
|
+
var _isLazyInit;
|
|
75
|
+
var _dependencyPlugin;
|
|
74
76
|
_initDefaults();
|
|
75
77
|
_self[_DYN_INITIALIZE /* @min:%2einitialize */] = function (coreConfig, core, extensions, pluginChain) {
|
|
76
78
|
if (!_hasInitialized) {
|
|
77
79
|
_base[_DYN_INITIALIZE /* @min:%2einitialize */](coreConfig, core, extensions);
|
|
80
|
+
// keep setting hasInitialized status here to avoid re-initialize
|
|
78
81
|
_hasInitialized = true;
|
|
79
82
|
_diagLogger = _self[_DYN_DIAG_LOG /* @min:%2ediagLog */]();
|
|
80
83
|
var evtNamespace = mergeEvtNamespace(createUniqueNamespace("OfflineSender"), core.evtNamespace && core.evtNamespace());
|
|
@@ -82,27 +85,33 @@ var OfflineChannel = /** @class */ (function (_super) {
|
|
|
82
85
|
_taskScheduler = createTaskScheduler(createAsyncPromise, "offline channel");
|
|
83
86
|
_notificationManager = core.getNotifyMgr();
|
|
84
87
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
88
|
+
// TODO: add refresh inside timer until dependency plugin is initialized
|
|
89
|
+
scheduleTimeout(function () {
|
|
90
|
+
try {
|
|
91
|
+
var _dependencyPlugin_1 = _getDependencyPlugin(coreConfig, core);
|
|
92
|
+
// make sure that online sender is initialized
|
|
93
|
+
if (!_isLazyInit && _dependencyPlugin_1 && _dependencyPlugin_1.isInitialized()) {
|
|
94
|
+
_isLazyInit = true;
|
|
95
|
+
_createUrlConfig(coreConfig, core, extensions, pluginChain);
|
|
96
|
+
var ctx = _getCoreItemCtx(coreConfig, core, extensions, pluginChain);
|
|
97
|
+
_sender[_DYN_INITIALIZE /* @min:%2einitialize */](coreConfig, core, ctx, _diagLogger, _primaryChannelId, _self._unloadHooks);
|
|
98
|
+
_senderInst = _sender.getXhrInst();
|
|
99
|
+
_offlineListener.addListener(function (val) {
|
|
100
|
+
if (!val[_DYN_IS_ONLINE /* @min:%2eisOnline */]) {
|
|
101
|
+
_sendNextBatchTimer && _sendNextBatchTimer[_DYN_CANCEL /* @min:%2ecancel */]();
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
_setSendNextTimer();
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
// need it for first time to confirm if there are any events
|
|
108
|
+
_setSendNextTimer();
|
|
109
|
+
}
|
|
101
110
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
// eslint-disable-next-line no-empty
|
|
113
|
+
}
|
|
114
|
+
}, 0);
|
|
106
115
|
};
|
|
107
116
|
_self.processTelemetry = function (evt, itemCtx) {
|
|
108
117
|
try {
|
|
@@ -169,7 +178,7 @@ var OfflineChannel = /** @class */ (function (_super) {
|
|
|
169
178
|
};
|
|
170
179
|
_self[_DYN_ONUNLOAD_FLUSH /* @min:%2eonunloadFlush */] = function () {
|
|
171
180
|
if (!_paused) {
|
|
172
|
-
while (_inMemoBatch[_DYN_COUNT /* @min:%2ecount */]()) {
|
|
181
|
+
while (_inMemoBatch && _inMemoBatch[_DYN_COUNT /* @min:%2ecount */]()) {
|
|
173
182
|
_flushInMemoItems(true);
|
|
174
183
|
}
|
|
175
184
|
// TODO: unloadprovider might send events out of order
|
|
@@ -182,10 +191,14 @@ var OfflineChannel = /** @class */ (function (_super) {
|
|
|
182
191
|
_self.getOfflineListener = function () {
|
|
183
192
|
return _offlineListener;
|
|
184
193
|
};
|
|
194
|
+
_self[_DYN_SEND_NEXT_BATCH /* @min:%2esendNextBatch */] = function () {
|
|
195
|
+
// TODO: add callback function
|
|
196
|
+
return _offineSupport && _setSendNextTimer();
|
|
197
|
+
};
|
|
185
198
|
_self._doTeardown = function (unloadCtx, unloadState) {
|
|
186
199
|
_self[_DYN_ONUNLOAD_FLUSH /* @min:%2eonunloadFlush */]();
|
|
187
200
|
_offlineListener && runTargetUnload(_offlineListener, false);
|
|
188
|
-
var handler = _urlCfg[_DYN_BATCH_HANDLER /* @min:%2ebatchHandler */];
|
|
201
|
+
var handler = _urlCfg && _urlCfg[_DYN_BATCH_HANDLER /* @min:%2ebatchHandler */];
|
|
189
202
|
handler && handler[_DYN_TEARDOWN /* @min:%2eteardown */]();
|
|
190
203
|
_clearScheduledTimer();
|
|
191
204
|
_initDefaults();
|
|
@@ -213,6 +226,8 @@ var OfflineChannel = /** @class */ (function (_super) {
|
|
|
213
226
|
_primaryChannelId = null;
|
|
214
227
|
_overrideIkey = null;
|
|
215
228
|
_evtsLimitInMemo = null;
|
|
229
|
+
_isLazyInit = false;
|
|
230
|
+
_dependencyPlugin = null;
|
|
216
231
|
}
|
|
217
232
|
function _shouldCacheEvent(urlConfig, item) {
|
|
218
233
|
if ((item[_DYN_PERSISTENCE /* @min:%2epersistence */]) < urlConfig[_DYN_MIN_PERSISTENCE_CACH0 /* @min:%2eminPersistenceCacheLevel */]) {
|
|
@@ -241,7 +256,7 @@ var OfflineChannel = /** @class */ (function (_super) {
|
|
|
241
256
|
try {
|
|
242
257
|
// TODO: add while loop to flush everything
|
|
243
258
|
var inMemo = _inMemoBatch;
|
|
244
|
-
var evts = inMemo[_DYN_GET_ITEMS /* @min:%2egetItems */]();
|
|
259
|
+
var evts = inMemo && inMemo[_DYN_GET_ITEMS /* @min:%2egetItems */]();
|
|
245
260
|
if (!evts || !evts[_DYN_LENGTH /* @min:%2elength */]) {
|
|
246
261
|
return;
|
|
247
262
|
}
|
|
@@ -341,7 +356,7 @@ var OfflineChannel = /** @class */ (function (_super) {
|
|
|
341
356
|
batchDropNotification(_notificationManager, 1, 1 /* eBatchDiscardedReason.NonRetryableStatus */);
|
|
342
357
|
}
|
|
343
358
|
};
|
|
344
|
-
var promise = _urlCfg[
|
|
359
|
+
var promise = _urlCfg.batchHandler[_DYN_SEND_NEXT_BATCH /* @min:%2esendNextBatch */](callback, false, _senderInst);
|
|
345
360
|
_queueStorageEvent("sendNextBatch", promise);
|
|
346
361
|
}
|
|
347
362
|
}
|
|
@@ -414,7 +429,7 @@ var OfflineChannel = /** @class */ (function (_super) {
|
|
|
414
429
|
function _getPayload(evt) {
|
|
415
430
|
try {
|
|
416
431
|
if (evt) {
|
|
417
|
-
return _offineSupport.serialize(evt, _convertUndefined);
|
|
432
|
+
return _offineSupport && _offineSupport.serialize(evt, _convertUndefined);
|
|
418
433
|
}
|
|
419
434
|
}
|
|
420
435
|
catch (e) {
|
|
@@ -446,21 +461,15 @@ var OfflineChannel = /** @class */ (function (_super) {
|
|
|
446
461
|
var theConfig = details.cfg;
|
|
447
462
|
var ctx = createProcessTelemetryContext(null, theConfig, core);
|
|
448
463
|
storageConfig = ctx.getExtCfg(_self.identifier, defaultOfflineChannelConfig);
|
|
449
|
-
|
|
464
|
+
// let channelIds = storageConfig.primaryOnlineChannelId;
|
|
450
465
|
var onlineUrl = null;
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
_offineSupport = channel[_DYN_GET_OFFLINE_SUPPORT /* @min:%2egetOfflineSupport */]();
|
|
459
|
-
onlineUrl = isFunction(_offineSupport && _offineSupport.getUrl) && _offineSupport.getUrl();
|
|
460
|
-
}
|
|
461
|
-
return;
|
|
462
|
-
}
|
|
463
|
-
});
|
|
466
|
+
var channel = _getDependencyPlugin(coreConfig, core);
|
|
467
|
+
if (!!channel.isInitialized() && isFunction(channel[_DYN_GET_OFFLINE_SUPPORT /* @min:%2egetOfflineSupport */])) {
|
|
468
|
+
_offineSupport = channel[_DYN_GET_OFFLINE_SUPPORT /* @min:%2egetOfflineSupport */]();
|
|
469
|
+
onlineUrl = isFunction(_offineSupport && _offineSupport.getUrl) && _offineSupport.getUrl();
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
return;
|
|
464
473
|
}
|
|
465
474
|
_overrideIkey = storageConfig[_DYN_OVERRIDE_INSTRUMENTA1 /* @min:%2eoverrideInstrumentationKey */];
|
|
466
475
|
var urlConfig = _urlCfg;
|
|
@@ -513,6 +522,24 @@ var OfflineChannel = /** @class */ (function (_super) {
|
|
|
513
522
|
_endpoint = curUrl;
|
|
514
523
|
}));
|
|
515
524
|
}
|
|
525
|
+
function _getDependencyPlugin(coreConfig, core) {
|
|
526
|
+
if (!_dependencyPlugin) {
|
|
527
|
+
var ctx = createProcessTelemetryContext(null, coreConfig, core);
|
|
528
|
+
var storageConfig = ctx.getExtCfg(_self.identifier, defaultOfflineChannelConfig);
|
|
529
|
+
var channelIds = storageConfig.primaryOnlineChannelId;
|
|
530
|
+
if (channelIds && channelIds[_DYN_LENGTH /* @min:%2elength */]) {
|
|
531
|
+
arrForEach(channelIds, function (id) {
|
|
532
|
+
var plugin = core.getPlugin(id);
|
|
533
|
+
var channel = plugin && plugin.plugin;
|
|
534
|
+
if (channel) {
|
|
535
|
+
_dependencyPlugin = channel;
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return _dependencyPlugin;
|
|
542
|
+
}
|
|
516
543
|
function _callNotification(evtName, theArgs) {
|
|
517
544
|
callNotification(_notificationManager, evtName, theArgs);
|
|
518
545
|
}
|
|
@@ -558,6 +585,7 @@ var OfflineChannel = /** @class */ (function (_super) {
|
|
|
558
585
|
// Removed Stub for OfflineChannel.prototype.getOfflineListener.
|
|
559
586
|
// Removed Stub for OfflineChannel.prototype.flush.
|
|
560
587
|
// Removed Stub for OfflineChannel.prototype.onunloadFlush.
|
|
588
|
+
// Removed Stub for OfflineChannel.prototype.sendNextBatch.
|
|
561
589
|
// This is a workaround for an IE bug when using dynamicProto() with classes that don't have any
|
|
562
590
|
// non-dynamic functions or static properties/functions when using uglify-js to minify the resulting code.
|
|
563
591
|
OfflineChannel.__ieDyn=1;
|