@microsoft/applicationinsights-offlinechannel-js 0.1.0-nightly3.2402-06
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/CODE_OF_CONDUCT.md +9 -0
- package/CONTRIBUTING.md +14 -0
- package/LICENSE.TXT +21 -0
- package/PRIVACY +3 -0
- package/README.md +63 -0
- package/SECURITY.md +41 -0
- package/SUPPORT.md +14 -0
- package/dist/es5/applicationinsights-offlinechannel-js.js +6391 -0
- package/dist/es5/applicationinsights-offlinechannel-js.js.map +1 -0
- package/dist/es5/applicationinsights-offlinechannel-js.min.js +6 -0
- package/dist/es5/applicationinsights-offlinechannel-js.min.js.map +1 -0
- package/dist-es5/Helpers/Utils.js +185 -0
- package/dist-es5/Helpers/Utils.js.map +1 -0
- package/dist-es5/InMemoryBatch.js +64 -0
- package/dist-es5/InMemoryBatch.js.map +1 -0
- package/dist-es5/Interfaces/IInMemoryBatch.js +8 -0
- package/dist-es5/Interfaces/IInMemoryBatch.js.map +1 -0
- package/dist-es5/Interfaces/IOfflineBatch.js +9 -0
- package/dist-es5/Interfaces/IOfflineBatch.js.map +1 -0
- package/dist-es5/Interfaces/IOfflineIndexDb.js +8 -0
- package/dist-es5/Interfaces/IOfflineIndexDb.js.map +1 -0
- package/dist-es5/Interfaces/IOfflineProvider.js +8 -0
- package/dist-es5/Interfaces/IOfflineProvider.js.map +1 -0
- package/dist-es5/Interfaces/ISender.js +8 -0
- package/dist-es5/Interfaces/ISender.js.map +1 -0
- package/dist-es5/OfflineBatchHandler.js +343 -0
- package/dist-es5/OfflineBatchHandler.js.map +1 -0
- package/dist-es5/OfflineChannel.js +465 -0
- package/dist-es5/OfflineChannel.js.map +1 -0
- package/dist-es5/PayloadHelper.js +62 -0
- package/dist-es5/PayloadHelper.js.map +1 -0
- package/dist-es5/Providers/IndexDbHelper.js +626 -0
- package/dist-es5/Providers/IndexDbHelper.js.map +1 -0
- package/dist-es5/Providers/IndexDbProvider.js +468 -0
- package/dist-es5/Providers/IndexDbProvider.js.map +1 -0
- package/dist-es5/Providers/WebStorageProvider.js +463 -0
- package/dist-es5/Providers/WebStorageProvider.js.map +1 -0
- package/dist-es5/Sender.js +572 -0
- package/dist-es5/Sender.js.map +1 -0
- package/dist-es5/__DynamicConstants.js +80 -0
- package/dist-es5/__DynamicConstants.js.map +1 -0
- package/dist-es5/applicationinsights-offlinechannel-js.js +11 -0
- package/dist-es5/applicationinsights-offlinechannel-js.js.map +1 -0
- package/package.json +65 -0
- package/tsconfig.json +28 -0
- package/types/applicationinsights-offlinechannel-js.d.ts +605 -0
- package/types/applicationinsights-offlinechannel-js.namespaced.d.ts +601 -0
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Microsoft Application Insights JavaScript SDK Offline Channel, 0.1.0-nightly3.2402-06
|
|
3
|
+
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Microsoft Application Insights Team
|
|
6
|
+
* https://github.com/microsoft/ApplicationInsights-JS#readme
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare namespace ApplicationInsights {
|
|
10
|
+
import { BaseTelemetryPlugin } from '@microsoft/applicationinsights-core-js';
|
|
11
|
+
import { EventPersistence } from '@microsoft/applicationinsights-common';
|
|
12
|
+
import { IAppInsightsCore } from '@microsoft/applicationinsights-core-js';
|
|
13
|
+
import { IChannelControls } from '@microsoft/applicationinsights-core-js';
|
|
14
|
+
import { IConfig } from '@microsoft/applicationinsights-common';
|
|
15
|
+
import { IConfiguration } from '@microsoft/applicationinsights-core-js';
|
|
16
|
+
import { IDiagnosticLogger } from '@microsoft/applicationinsights-core-js';
|
|
17
|
+
import { IOfflineListener } from '@microsoft/applicationinsights-common';
|
|
18
|
+
import { IPayloadData } from '@microsoft/applicationinsights-core-js';
|
|
19
|
+
import { IPlugin } from '@microsoft/applicationinsights-core-js';
|
|
20
|
+
import { IProcessTelemetryContext } from '@microsoft/applicationinsights-core-js';
|
|
21
|
+
import { IProcessTelemetryUnloadContext } from '@microsoft/applicationinsights-core-js';
|
|
22
|
+
import { IPromise } from '@nevware21/ts-async';
|
|
23
|
+
import { ITelemetryItem } from '@microsoft/applicationinsights-core-js';
|
|
24
|
+
import { ITelemetryPluginChain } from '@microsoft/applicationinsights-core-js';
|
|
25
|
+
import { ITelemetryUnloadState } from '@microsoft/applicationinsights-core-js';
|
|
26
|
+
import { IUnloadHookContainer } from '@microsoft/applicationinsights-core-js';
|
|
27
|
+
import { IXHROverride } from '@microsoft/applicationinsights-core-js';
|
|
28
|
+
import { SendRequestReason } from '@microsoft/applicationinsights-core-js';
|
|
29
|
+
|
|
30
|
+
type createDefaultOfflineDetector = (cfg?: IOfflineDetectorCfg) => IOfflineDetector;
|
|
31
|
+
|
|
32
|
+
type createNoopOfflineDetector = (cfg?: IOfflineDetectorCfg) => IOfflineDetector;
|
|
33
|
+
|
|
34
|
+
const enum eBatchSendStatus {
|
|
35
|
+
Complete = 1,
|
|
36
|
+
Retry = 2,
|
|
37
|
+
Drop = 3,
|
|
38
|
+
Failure = 4
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const enum eBatchStoreStatus {
|
|
42
|
+
Success = 1,
|
|
43
|
+
Failure = 2,
|
|
44
|
+
Drop = 3
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Identifies the Storage Providers used by the LocalStorageChannel
|
|
49
|
+
*/
|
|
50
|
+
const enum eStorageProviders {
|
|
51
|
+
/**
|
|
52
|
+
* Identifies that the provider that uses (window||globalThis||self).localStorage
|
|
53
|
+
*/
|
|
54
|
+
LocalStorage = 1,
|
|
55
|
+
/**
|
|
56
|
+
* Identifies that the provider that uses (window||globalThis||self).sessionStorage
|
|
57
|
+
*/
|
|
58
|
+
SessionStorage = 2,
|
|
59
|
+
/**
|
|
60
|
+
* Identifies that the provider that uses (window||globalThis||self).indexedDB
|
|
61
|
+
*/
|
|
62
|
+
IndexedDb = 3
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const enum eStorageType {
|
|
66
|
+
Unknown = 0,
|
|
67
|
+
LocalStorage = 1,
|
|
68
|
+
SessionStorage = 2,
|
|
69
|
+
IndexDb = 3
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* An internal interface which defines a in memory batch
|
|
74
|
+
*/
|
|
75
|
+
interface IInMemoryBatch {
|
|
76
|
+
/**
|
|
77
|
+
* Enqueue the payload
|
|
78
|
+
*/
|
|
79
|
+
addEvent: (evt: IPostTransmissionTelemetryItem | ITelemetryItem) => boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Returns the number of elements in the buffer
|
|
82
|
+
*/
|
|
83
|
+
count: () => number;
|
|
84
|
+
/**
|
|
85
|
+
* Returns items stored in the buffer
|
|
86
|
+
*/
|
|
87
|
+
getItems: () => IPostTransmissionTelemetryItem[] | ITelemetryItem[];
|
|
88
|
+
/**
|
|
89
|
+
* Split this batch into 2 with any events > fromEvent returned in the new batch and all other
|
|
90
|
+
* events are kept in the current batch.
|
|
91
|
+
* @param fromEvt The first event to remove from the current batch.
|
|
92
|
+
* @param numEvts The number of events to be removed from the current batch and returned in the new one. Defaults to all trailing events
|
|
93
|
+
*/
|
|
94
|
+
split: (fromEvt: number, numEvts?: number) => IInMemoryBatch;
|
|
95
|
+
/**
|
|
96
|
+
* create current buffer to a new endpoint with current logger
|
|
97
|
+
* @param endpoint new endpoint
|
|
98
|
+
* @param evts new events to be added
|
|
99
|
+
* @param evtsLimitInMem new evtsLimitInMem
|
|
100
|
+
*/
|
|
101
|
+
createNew(endpoint: string, evts?: IPostTransmissionTelemetryItem[] | ITelemetryItem[], evtsLimitInMem?: number): IInMemoryBatch;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* An internal interface which defines a common provider context that is used to pass multiple values when initializing provider instances
|
|
106
|
+
*/
|
|
107
|
+
interface ILocalStorageProviderContext {
|
|
108
|
+
/**
|
|
109
|
+
* Identifies the context for the current event
|
|
110
|
+
*/
|
|
111
|
+
itemCtx?: IProcessTelemetryContext;
|
|
112
|
+
/**
|
|
113
|
+
* Identifies the local storage config that should be used to initialize the provider
|
|
114
|
+
*/
|
|
115
|
+
storageConfig: IOfflineChannelConfiguration;
|
|
116
|
+
/**
|
|
117
|
+
* Identifies the unique identifier to be used for this provider instance, when not provided a new Guid will be generated for this instance.
|
|
118
|
+
* This value must be unique across all instances to avoid polluting events between browser / tabs instances as they may share the same persistent storage.
|
|
119
|
+
* The primary use case for setting this value is for unit testing.
|
|
120
|
+
*/
|
|
121
|
+
id?: string;
|
|
122
|
+
/**
|
|
123
|
+
* Identifies endpoint url.
|
|
124
|
+
*/
|
|
125
|
+
endpoint?: string;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Class that implements storing of events using the WebStorage Api ((window||globalThis||self).localstorage, (window||globalThis||self).sessionStorage).
|
|
130
|
+
*/
|
|
131
|
+
class IndexedDbProvider implements IOfflineProvider {
|
|
132
|
+
id: string;
|
|
133
|
+
/**
|
|
134
|
+
* Creates a WebStorageProvider using the provider storageType
|
|
135
|
+
*/
|
|
136
|
+
constructor(id?: string, unloadHookContainer?: IUnloadHookContainer);
|
|
137
|
+
/**
|
|
138
|
+
* Initializes the provider using the config
|
|
139
|
+
* @param providerContext The provider context that should be used to initialize the provider
|
|
140
|
+
* @returns True if the provider is initialized and available for use otherwise false
|
|
141
|
+
*/
|
|
142
|
+
initialize(providerContext: ILocalStorageProviderContext): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Identifies whether this storage provider support synchronous requests
|
|
145
|
+
*/
|
|
146
|
+
supportsSyncRequests(): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Get all of the currently cached events from the storage mechanism
|
|
149
|
+
*/
|
|
150
|
+
getNextBatch(): IStorageTelemetryItem[] | IPromise<IStorageTelemetryItem[]> | null;
|
|
151
|
+
/**
|
|
152
|
+
* Get all of the currently cached events from the storage mechanism
|
|
153
|
+
*/
|
|
154
|
+
getAllEvents(cnt?: number): IStorageTelemetryItem[] | IPromise<IStorageTelemetryItem[]> | null;
|
|
155
|
+
/**
|
|
156
|
+
* Stores the value into the storage using the specified key.
|
|
157
|
+
* @param key - The key value to use for the value
|
|
158
|
+
* @param evt - The actual event of the request
|
|
159
|
+
* @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
|
|
160
|
+
* can optionally use this to access the current core instance or define / pass additional information
|
|
161
|
+
* to later plugins (vs appending items to the telemetry item)
|
|
162
|
+
*/
|
|
163
|
+
addEvent(key: string, evt: any, itemCtx: IProcessTelemetryContext): IStorageTelemetryItem | IPromise<IStorageTelemetryItem> | null;
|
|
164
|
+
/**
|
|
165
|
+
* Removes the value associated with the provided key
|
|
166
|
+
* @param evts - The events to be removed
|
|
167
|
+
*/
|
|
168
|
+
removeEvents(evts: any[]): IStorageTelemetryItem[] | IPromise<IStorageTelemetryItem[]> | null;
|
|
169
|
+
/**
|
|
170
|
+
* Removes all entries from the storage provider, if there are any.
|
|
171
|
+
*/
|
|
172
|
+
clear(disable?: boolean): IStorageTelemetryItem[] | IPromise<IStorageTelemetryItem[]> | null;
|
|
173
|
+
/**
|
|
174
|
+
* Removes all entries with stroage time longer than inStorageMaxTime from the storage provider
|
|
175
|
+
*/
|
|
176
|
+
clean(disable?: boolean): boolean | IPromise<boolean>;
|
|
177
|
+
/**
|
|
178
|
+
* Shuts-down the telemetry plugin. This is usually called when telemetry is shut down.
|
|
179
|
+
*/
|
|
180
|
+
teardown(): void;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
class InMemoryBatch implements IInMemoryBatch {
|
|
184
|
+
constructor(logger: IDiagnosticLogger, endpoint: string, evts?: IPostTransmissionTelemetryItem[], evtsLimitInMem?: number);
|
|
185
|
+
addEvent(payload: IPostTransmissionTelemetryItem | ITelemetryItem): any;
|
|
186
|
+
endpoint(): any;
|
|
187
|
+
count(): number;
|
|
188
|
+
clear(): void;
|
|
189
|
+
getItems(): IPostTransmissionTelemetryItem[] | ITelemetryItem[];
|
|
190
|
+
/**
|
|
191
|
+
* Split this batch into 2 with any events > fromEvent returned in the new batch and all other
|
|
192
|
+
* events are kept in the current batch.
|
|
193
|
+
* @param fromEvt The first event to remove from the current batch.
|
|
194
|
+
* @param numEvts The number of events to be removed from the current batch and returned in the new one. Defaults to all trailing events
|
|
195
|
+
*/
|
|
196
|
+
split(fromEvt: number, numEvts?: number): any;
|
|
197
|
+
/**
|
|
198
|
+
* create current buffer to a new endpoint
|
|
199
|
+
* @param endpoint if not defined, current endpoint will be used
|
|
200
|
+
* @param evts new events to be added
|
|
201
|
+
* @param addCurEvts if it is set to true, current itemss will be transferred to the new batch
|
|
202
|
+
*/
|
|
203
|
+
createNew(endpoint: string, evts?: IPostTransmissionTelemetryItem[] | ITelemetryItem[], evtsLimitInMem?: number): any;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
interface IOfflineBatchCleanResponse {
|
|
207
|
+
batchCnt: number;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
interface IOfflineBatchHandler {
|
|
211
|
+
storeBatch(batch: IPayloadData, cb?: OfflineBatchStoreCallback, sync?: boolean): undefined | IOfflineBatchStoreResponse | IPromise<IOfflineBatchStoreResponse>;
|
|
212
|
+
sendNextBatch(cb?: OfflineBatchCallback, sync?: boolean, xhrOverride?: IXHROverride, cnt?: number): undefined | IOfflineBatchResponse | IPromise<IOfflineBatchResponse>;
|
|
213
|
+
hasStoredBatch(callback?: (hasBatches: boolean) => void): undefined | boolean | IPromise<boolean>;
|
|
214
|
+
cleanStorage(cb?: (res: IOfflineBatchCleanResponse) => void): undefined | IOfflineBatchCleanResponse | IPromise<IOfflineBatchCleanResponse>;
|
|
215
|
+
teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
interface IOfflineBatchHandlerCfg {
|
|
219
|
+
batchMaxSize?: number;
|
|
220
|
+
storageType?: eStorageType;
|
|
221
|
+
offineDetector?: IOfflineDetector;
|
|
222
|
+
autoClean?: Boolean;
|
|
223
|
+
maxRetryCnt?: number;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
interface IOfflineBatchResponse {
|
|
227
|
+
state: eBatchSendStatus;
|
|
228
|
+
data?: any;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
interface IOfflineBatchStoreResponse {
|
|
232
|
+
state: eBatchStoreStatus;
|
|
233
|
+
item?: any;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* The IOfflineChannelConfiguration interface defines the configuration options for offline channel,
|
|
238
|
+
* supports offline events storage, retrieval and re-sending.
|
|
239
|
+
*/
|
|
240
|
+
interface IOfflineChannelConfiguration {
|
|
241
|
+
/**
|
|
242
|
+
* [Optional] The max size in bytes that should be used for storing events(default up to 5 Mb).
|
|
243
|
+
* The maximum size in bytes that should be used for storing events in storage If not specified, the system will use up to 5 MB
|
|
244
|
+
* @default 5000000
|
|
245
|
+
*/
|
|
246
|
+
maxStorageSizeInBytes?: number;
|
|
247
|
+
/**
|
|
248
|
+
* [Optional] The storage key prefix that should be used when storing events in persistent storage.
|
|
249
|
+
* @default AIOffline
|
|
250
|
+
*/
|
|
251
|
+
storageKeyPrefix?: string;
|
|
252
|
+
/**
|
|
253
|
+
* [Optional] Identifies the minimum level that will be cached in the offline channel. Valid values of this
|
|
254
|
+
* setting are defined by the EventPersistence enum, currently Normal (1) and Critical (2) with the default
|
|
255
|
+
* value being Normal (1), which means all events without a persistence level set or with invalid persistence level will be marked as Normal(1) events.
|
|
256
|
+
* @default 1
|
|
257
|
+
*/
|
|
258
|
+
minPersistenceLevel?: number | EventPersistence;
|
|
259
|
+
/**
|
|
260
|
+
* [Optional] Identifies the StorageProviders that should be used by the system if available, the first available
|
|
261
|
+
* provider will be used. Valid available values are defined by the eStorageProviders enum. Only the first 5 entries
|
|
262
|
+
* are processed, so if this value contains more than 5 elements they will be ignored.
|
|
263
|
+
* Note: LocalStorage will be used to save unload events even if it is not in the providers list
|
|
264
|
+
* Default order is [StorageProviders.LocalStorage, StorageProviders.IndexedDB]
|
|
265
|
+
*/
|
|
266
|
+
providers?: number[] | eStorageProviders[];
|
|
267
|
+
/**
|
|
268
|
+
* [Optional] The IndexedDb database name that should be used when storing events using (window||globalThis||self).indexedDb.
|
|
269
|
+
*/
|
|
270
|
+
indexedDbName?: string;
|
|
271
|
+
/**
|
|
272
|
+
* [Optional] Identifies the maximum number of events to store in memory before sending to persistent storage.
|
|
273
|
+
*/
|
|
274
|
+
eventsLimitInMem?: number;
|
|
275
|
+
/**
|
|
276
|
+
* [Optional] Identifies if events that have existed in storage longer than the maximum allowed time (configured in inStorageMaxTime) should be cleaned after connection with storage.
|
|
277
|
+
* If not provided, default is false
|
|
278
|
+
*/
|
|
279
|
+
autoClean?: boolean;
|
|
280
|
+
/**
|
|
281
|
+
* [Optional] Identifies the maximum time in ms that items should be in memory before being saved into storage.
|
|
282
|
+
|
|
283
|
+
* @default 15000
|
|
284
|
+
*/
|
|
285
|
+
inMemoMaxTime?: number;
|
|
286
|
+
/**
|
|
287
|
+
* [Optional] Identifies the maximum time in ms that items should be in persistent storage.
|
|
288
|
+
* default: 10080000 (around 7days)
|
|
289
|
+
*/
|
|
290
|
+
inStorageMaxTime?: number;
|
|
291
|
+
/**
|
|
292
|
+
* [Optional] Identifies the maximum retry times for an event batch.
|
|
293
|
+
* default: 1
|
|
294
|
+
*/
|
|
295
|
+
maxRetry?: number;
|
|
296
|
+
/**
|
|
297
|
+
* Identifies online channel IDs in order. The first available one will be used.
|
|
298
|
+
* default is [AppInsightsChannelPlugin, PostChannel]
|
|
299
|
+
*/
|
|
300
|
+
primaryOnlineChannelId?: string[];
|
|
301
|
+
/**
|
|
302
|
+
* Identifies the maximum size per batch in bytes that is saved in persistent storage.
|
|
303
|
+
* default 63000
|
|
304
|
+
*/
|
|
305
|
+
maxBatchsize?: number;
|
|
306
|
+
/**
|
|
307
|
+
* Identifies offline sender properties. If not defined, settings will be the same as the online channel configured in primaryOnlineChannelId.
|
|
308
|
+
*/
|
|
309
|
+
senderCfg?: IOfflineSenderConfig;
|
|
310
|
+
/**
|
|
311
|
+
* Identifies the interval time in ms that previously stored offline event batches should be sent under online status.
|
|
312
|
+
* default 15000
|
|
313
|
+
*/
|
|
314
|
+
maxSentBatchInterval?: number;
|
|
315
|
+
/**
|
|
316
|
+
* Identifies the maximum event batch count when cleaning or releasing space for persistent storage per time.
|
|
317
|
+
* default 10
|
|
318
|
+
*/
|
|
319
|
+
EventsToDropPerTime?: number;
|
|
320
|
+
/**
|
|
321
|
+
* Identifies the maximum critical events count for an event batch to be able to drop when releasing space for persistent storage per time.
|
|
322
|
+
* default 2
|
|
323
|
+
*/
|
|
324
|
+
maxCriticalEvtsDropCnt?: number;
|
|
325
|
+
/**
|
|
326
|
+
* Identifies overridden for the Instrumentation key when the offline channel calls processTelemetry.
|
|
327
|
+
*/
|
|
328
|
+
overrideInstrumentationKey?: string;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
interface IOfflineDetector {
|
|
332
|
+
startPolling(): boolean;
|
|
333
|
+
stopPolling(): boolean;
|
|
334
|
+
getOfflineListener(): IOfflineListener;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
interface IOfflineDetectorCfg {
|
|
338
|
+
autoStop: boolean;
|
|
339
|
+
pollingInterval: number;
|
|
340
|
+
pollingUrl: string;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
interface IOfflineProvider {
|
|
344
|
+
/**
|
|
345
|
+
* Initializes the provider using the config
|
|
346
|
+
* @param providerContext The provider context that should be used to initialize the provider
|
|
347
|
+
* @returns True if the provider is initialized and available for use otherwise false
|
|
348
|
+
*/
|
|
349
|
+
initialize(providerContext: ILocalStorageProviderContext): boolean;
|
|
350
|
+
/**
|
|
351
|
+
* Identifies whether this storage provider support synchronious requests
|
|
352
|
+
*/
|
|
353
|
+
supportsSyncRequests(): boolean;
|
|
354
|
+
/**
|
|
355
|
+
* Stores the value into the storage using the specified key.
|
|
356
|
+
* @param key - The key value to use for the value
|
|
357
|
+
* @param evt - The actual event of the request
|
|
358
|
+
* @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
|
|
359
|
+
* can optionally use this to access the current core instance or define / pass additional information
|
|
360
|
+
* to later plugins (vs appending items to the telemetry item)
|
|
361
|
+
* @return Either the added element (for synchronous operation) or a Promise for an asynchronous processing
|
|
362
|
+
*/
|
|
363
|
+
addEvent(key: string, evt: IStorageTelemetryItem, itemCtx: IProcessTelemetryContext): IStorageTelemetryItem | IPromise<IStorageTelemetryItem> | null;
|
|
364
|
+
/**
|
|
365
|
+
* Get Next batch from the storage
|
|
366
|
+
*/
|
|
367
|
+
getNextBatch(): IStorageTelemetryItem[] | IPromise<IStorageTelemetryItem[]> | null;
|
|
368
|
+
/**
|
|
369
|
+
* Get all stored batches from the storage.
|
|
370
|
+
* @param cnt batch numbers if it is defined, it will returns given number of batches.
|
|
371
|
+
* if cnt is not defined, it will return all available batches
|
|
372
|
+
*/
|
|
373
|
+
getAllEvents(cnt?: number): IStorageTelemetryItem[] | IPromise<IStorageTelemetryItem[]> | null;
|
|
374
|
+
/**
|
|
375
|
+
* Removes the value associated with the provided key
|
|
376
|
+
* @param evts - The events to be removed
|
|
377
|
+
* @return Either the removed item array (for synchronous operation) or a Promise for an asynchronous processing
|
|
378
|
+
*/
|
|
379
|
+
removeEvents(evts: IStorageTelemetryItem[]): IStorageTelemetryItem[] | IPromise<IStorageTelemetryItem[]> | null;
|
|
380
|
+
/**
|
|
381
|
+
* Removes all entries from the storage provider, if there are any.
|
|
382
|
+
* @return Either the removed item array (for synchronous operation) or a Promise for an asynchronous processing
|
|
383
|
+
*/
|
|
384
|
+
clear(): IStorageTelemetryItem[] | IPromise<IStorageTelemetryItem[]> | null;
|
|
385
|
+
/**
|
|
386
|
+
* Removes all entries with stroage time longer than inStorageMaxTime from the storage provider
|
|
387
|
+
*/
|
|
388
|
+
clean(disable?: boolean): boolean | IPromise<boolean>;
|
|
389
|
+
/**
|
|
390
|
+
* Shuts-down the telemetry plugin. This is usually called when telemetry is shut down.
|
|
391
|
+
*/
|
|
392
|
+
teardown(): void;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
interface IOfflineSenderConfig {
|
|
396
|
+
/**
|
|
397
|
+
* Identifies status codes for re-sending event batches
|
|
398
|
+
* Default: [401, 403, 408, 429, 500, 502, 503, 504]
|
|
399
|
+
*/
|
|
400
|
+
retryCodes?: number[];
|
|
401
|
+
/**
|
|
402
|
+
* [Optional] Either an array or single value identifying the requested TransportType type(s) that should be used for sending events
|
|
403
|
+
* If not defined, the same transports will be used in the channel with the primaryOnlineChannelId
|
|
404
|
+
*/
|
|
405
|
+
transports?: number | number[];
|
|
406
|
+
/**
|
|
407
|
+
* [Optional] The HTTP override that should be used to send requests, as an IXHROverride object.
|
|
408
|
+
*/
|
|
409
|
+
httpXHROverride?: IXHROverride;
|
|
410
|
+
/**
|
|
411
|
+
* Identifies if provided httpXhrOverride will always be used
|
|
412
|
+
* default false
|
|
413
|
+
*/
|
|
414
|
+
alwaysUseXhrOverride?: boolean;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
interface IPostTransmissionTelemetryItem extends ITelemetryItem {
|
|
418
|
+
/**
|
|
419
|
+
* [Optional] An EventPersistence value, that specifies the persistence for the event. The EventPersistence constant
|
|
420
|
+
*/
|
|
421
|
+
persistence?: EventPersistence;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* An internal interface which defines a common storage item
|
|
426
|
+
*/
|
|
427
|
+
interface IStorageTelemetryItem extends IPayloadData {
|
|
428
|
+
id?: string;
|
|
429
|
+
iKey?: string;
|
|
430
|
+
sync?: boolean;
|
|
431
|
+
criticalCnt?: number;
|
|
432
|
+
isArr?: boolean;
|
|
433
|
+
attempCnt?: number;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
type OfflineBatchCallback = (response: IOfflineBatchResponse) => void;
|
|
437
|
+
|
|
438
|
+
class OfflineBatchHandler implements IOfflineBatchHandler {
|
|
439
|
+
constructor(logger?: IDiagnosticLogger, unloadHookContainer?: IUnloadHookContainer);
|
|
440
|
+
/**
|
|
441
|
+
* Initializes the provider using the config
|
|
442
|
+
* @returns True if the provider is initialized and available for use otherwise false
|
|
443
|
+
*/
|
|
444
|
+
initialize(providerContext: ILocalStorageProviderContext): any;
|
|
445
|
+
storeBatch(batch: IPayloadData, cb?: OfflineBatchStoreCallback, sync?: boolean): undefined | IOfflineBatchStoreResponse | IPromise<IOfflineBatchStoreResponse>;
|
|
446
|
+
sendNextBatch(cb?: OfflineBatchCallback, sync?: boolean, xhrOverride?: IXHROverride, cnt?: number): undefined | IOfflineBatchResponse | IPromise<IOfflineBatchResponse>;
|
|
447
|
+
hasStoredBatch(callback?: (hasBatches: boolean) => void): undefined | boolean | IPromise<boolean>;
|
|
448
|
+
cleanStorage(cb?: (res: IOfflineBatchCleanResponse) => void): undefined | IOfflineBatchCleanResponse | IPromise<IOfflineBatchCleanResponse>;
|
|
449
|
+
teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): any;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
type OfflineBatchSendCallback = (response: IOfflineBatchResponse) => void;
|
|
453
|
+
|
|
454
|
+
type OfflineBatchStoreCallback = (response: IOfflineBatchStoreResponse) => void;
|
|
455
|
+
|
|
456
|
+
class OfflineChannel extends BaseTelemetryPlugin implements IChannelControls {
|
|
457
|
+
identifier: string;
|
|
458
|
+
priority: number;
|
|
459
|
+
version: string;
|
|
460
|
+
id: string;
|
|
461
|
+
constructor();
|
|
462
|
+
/**
|
|
463
|
+
* The function does the initial set up. It adds a notification listener to determine which events to remove.
|
|
464
|
+
* @param coreConfig - The core configuration.
|
|
465
|
+
* @param core - The AppInsights core.
|
|
466
|
+
* @param extensions - An array of all the plugins being used.
|
|
467
|
+
*/
|
|
468
|
+
initialize(coreConfig: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
|
|
469
|
+
/**
|
|
470
|
+
* Process an event to add it to the local storage and then pass it to the next plugin.
|
|
471
|
+
* @param event - The event that needs to be stored.
|
|
472
|
+
* @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
|
|
473
|
+
* can optionally use this to access the current core instance or define / pass additional information
|
|
474
|
+
* to later plugins (vs appending items to the telemetry item)
|
|
475
|
+
*/
|
|
476
|
+
processTelemetry(evt: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
|
|
477
|
+
/**
|
|
478
|
+
* Pauses the adding of new events to the plugin. Also calls pause on the next
|
|
479
|
+
* plugin.
|
|
480
|
+
*/
|
|
481
|
+
pause(): void;
|
|
482
|
+
/**
|
|
483
|
+
* Resumes the adding of new events to the plugin. Also calls resume on
|
|
484
|
+
* the next plugin. Adds all events in storage to the next plugin.
|
|
485
|
+
*/
|
|
486
|
+
resume(): void;
|
|
487
|
+
/**
|
|
488
|
+
* Get offline listener
|
|
489
|
+
* @returns offline listener
|
|
490
|
+
*/
|
|
491
|
+
getOfflineListener(): any;
|
|
492
|
+
/**
|
|
493
|
+
*No op
|
|
494
|
+
*/
|
|
495
|
+
flush(sync: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): boolean | void | IPromise<boolean>;
|
|
496
|
+
/**
|
|
497
|
+
* Flush the batched events synchronously (if possible -- based on configuration).
|
|
498
|
+
* Will not flush if the Send has been paused.
|
|
499
|
+
*/
|
|
500
|
+
onunloadFlush(): void;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
class Sender {
|
|
504
|
+
_appId: string;
|
|
505
|
+
constructor();
|
|
506
|
+
/**
|
|
507
|
+
* Pause the sending (transmission) of events, this will cause all events to be batched only until the maximum limits are
|
|
508
|
+
* hit at which point new events are dropped. Will also cause events to NOT be sent during page unload, so if Session storage
|
|
509
|
+
* is disabled events will be lost.
|
|
510
|
+
*/
|
|
511
|
+
pause(): void;
|
|
512
|
+
/**
|
|
513
|
+
* Resume the sending (transmission) of events, this will restart the timer and any batched events will be sent using the normal
|
|
514
|
+
* send interval.
|
|
515
|
+
*/
|
|
516
|
+
resume(): void;
|
|
517
|
+
initialize(config: IConfiguration & IConfig, core: IAppInsightsCore, cxt: IProcessTelemetryContext, diagLog: IDiagnosticLogger, channelId?: string, unloadHookContainer?: IUnloadHookContainer): void;
|
|
518
|
+
/**
|
|
519
|
+
* Trigger the immediate send of buffered data; If executing asynchronously (the default) this may (not required) return
|
|
520
|
+
* an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html) that will resolve once the
|
|
521
|
+
* send is complete. The actual implementation of the `IPromise` will be a native Promise (if supported) or the default
|
|
522
|
+
* as supplied by [ts-async library](https://github.com/nevware21/ts-async)
|
|
523
|
+
* @param async - Indicates if the events should be sent asynchronously
|
|
524
|
+
* @param forcedSender - {SenderFunction} - Indicates the forcedSender, undefined if not passed
|
|
525
|
+
* @returns - Nothing or optionally, if occurring asynchronously a [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
|
|
526
|
+
* which will be resolved (or reject) once the send is complete, the [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
|
|
527
|
+
* should only be returned when async is true.
|
|
528
|
+
*/
|
|
529
|
+
triggerSend(async?: boolean, forcedSender?: SenderFunction, sendReason?: SendRequestReason): void | IPromise<boolean>;
|
|
530
|
+
/**
|
|
531
|
+
* Check if there are no active requests being sent.
|
|
532
|
+
* @returns True if idle, false otherwise.
|
|
533
|
+
*/
|
|
534
|
+
isCompletelyIdle(): boolean;
|
|
535
|
+
/**
|
|
536
|
+
* Get current xhr instance
|
|
537
|
+
*/
|
|
538
|
+
getXhrInst(sync?: boolean): any;
|
|
539
|
+
_doTeardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
type SenderFunction = (payload: string[], isAsync: boolean) => void | IPromise<boolean>;
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Class that implements storing of events using the WebStorage Api ((window||globalThis||self).localstorage, (window||globalThis||self).sessionStorage).
|
|
546
|
+
*/
|
|
547
|
+
class WebStorageProvider implements IOfflineProvider {
|
|
548
|
+
id: string;
|
|
549
|
+
/**
|
|
550
|
+
* Creates a WebStorageProvider using the provider storageType
|
|
551
|
+
* @param storageType The type of Storage provider, normal values are "localStorage" or "sessionStorage"
|
|
552
|
+
*/
|
|
553
|
+
constructor(storageType: string, id?: string, unloadHookContainer?: IUnloadHookContainer);
|
|
554
|
+
/**
|
|
555
|
+
* Initializes the provider using the config
|
|
556
|
+
* @param providerContext The provider context that should be used to initialize the provider
|
|
557
|
+
* @returns True if the provider is initialized and available for use otherwise false
|
|
558
|
+
*/
|
|
559
|
+
initialize(providerContext: ILocalStorageProviderContext): boolean;
|
|
560
|
+
/**
|
|
561
|
+
* Identifies whether this storage provider support synchronous requests
|
|
562
|
+
*/
|
|
563
|
+
supportsSyncRequests(): boolean;
|
|
564
|
+
/**
|
|
565
|
+
* Get all of the currently cached events from the storage mechanism
|
|
566
|
+
*/
|
|
567
|
+
getAllEvents(cnt?: number): IStorageTelemetryItem[] | IPromise<IStorageTelemetryItem[]> | null;
|
|
568
|
+
/**
|
|
569
|
+
* Get the Next one cached batch from the storage mechanism
|
|
570
|
+
*/
|
|
571
|
+
getNextBatch(): IStorageTelemetryItem[] | IPromise<IStorageTelemetryItem[]> | null;
|
|
572
|
+
/**
|
|
573
|
+
* Stores the value into the storage using the specified key.
|
|
574
|
+
* @param key - The key value to use for the value
|
|
575
|
+
* @param evt - The actual event of the request
|
|
576
|
+
* @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
|
|
577
|
+
* can optionally use this to access the current core instance or define / pass additional information
|
|
578
|
+
* to later plugins (vs appending items to the telemetry item)
|
|
579
|
+
*/
|
|
580
|
+
addEvent(key: string, evt: any, itemCtx: IProcessTelemetryContext): IStorageTelemetryItem | IPromise<IStorageTelemetryItem> | null;
|
|
581
|
+
/**
|
|
582
|
+
* Removes the value associated with the provided key
|
|
583
|
+
* @param evts - The events to be removed
|
|
584
|
+
*/
|
|
585
|
+
removeEvents(evts: any[]): IStorageTelemetryItem[] | IPromise<IStorageTelemetryItem[]> | null;
|
|
586
|
+
/**
|
|
587
|
+
* Removes all entries from the storage provider, if there are any.
|
|
588
|
+
*/
|
|
589
|
+
clear(): IStorageTelemetryItem[] | IPromise<IStorageTelemetryItem[]> | null;
|
|
590
|
+
/**
|
|
591
|
+
* Removes all entries with stroage time longer than inStorageMaxTime from the storage provider
|
|
592
|
+
*/
|
|
593
|
+
clean(): boolean | IPromise<boolean>;
|
|
594
|
+
/**
|
|
595
|
+
* Shuts-down the telemetry plugin. This is usually called when telemetry is shut down.
|
|
596
|
+
*/
|
|
597
|
+
teardown(): void;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
}
|