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