@microsoft/applicationinsights-channel-js 3.0.0-beta.2303-11 → 3.0.0-nightly3.2304-28
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/browser/es5/applicationinsights-channel-js.3.0.0-nightly3.2304-28.cjs.js +5768 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-nightly3.2304-28.cjs.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-nightly3.2304-28.cjs.min.js +6 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-nightly3.2304-28.cjs.min.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-nightly3.2304-28.gbl.js +5772 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-nightly3.2304-28.gbl.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-nightly3.2304-28.gbl.min.js +6 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-nightly3.2304-28.gbl.min.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-nightly3.2304-28.integrity.json +66 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-nightly3.2304-28.js +5774 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-nightly3.2304-28.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-nightly3.2304-28.min.js +6 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-nightly3.2304-28.min.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.cjs.js +5768 -0
- package/browser/es5/applicationinsights-channel-js.3.cjs.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.cjs.min.js +6 -0
- package/browser/es5/applicationinsights-channel-js.3.cjs.min.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.gbl.js +5772 -0
- package/browser/es5/applicationinsights-channel-js.3.gbl.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.gbl.min.js +6 -0
- package/browser/es5/applicationinsights-channel-js.3.gbl.min.js.map +1 -0
- package/{dist/applicationinsights-channel-js.js → browser/es5/applicationinsights-channel-js.3.js} +875 -829
- package/browser/es5/applicationinsights-channel-js.3.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.min.js +6 -0
- package/browser/es5/applicationinsights-channel-js.3.min.js.map +1 -0
- package/{browser → dist/es5}/applicationinsights-channel-js.js +874 -828
- package/dist/es5/applicationinsights-channel-js.js.map +1 -0
- package/dist/es5/applicationinsights-channel-js.min.js +6 -0
- package/dist/es5/applicationinsights-channel-js.min.js.map +1 -0
- package/{dist-esm → dist-es5}/EnvelopeCreator.js +2 -2
- package/dist-es5/EnvelopeCreator.js.map +1 -0
- package/dist-es5/Interfaces.js +6 -0
- package/{dist-esm → dist-es5}/InternalConstants.js +1 -1
- package/{dist-esm → dist-es5}/Offline.js +8 -7
- package/dist-es5/Offline.js.map +1 -0
- package/{dist-esm → dist-es5}/SendBuffer.js +1 -1
- package/{dist-esm → dist-es5}/Sender.js +6 -4
- package/dist-es5/Sender.js.map +1 -0
- package/{dist-esm → dist-es5}/Serializer.js +1 -1
- package/{dist-esm → dist-es5}/TelemetryProcessors/Sample.js +1 -1
- package/{dist-esm → dist-es5}/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.js +1 -1
- package/{dist-esm → dist-es5}/TelemetryProcessors/SamplingScoreGenerators/SamplingScoreGenerator.js +1 -1
- package/{dist-esm → dist-es5}/__DynamicConstants.js +2 -1
- package/dist-es5/__DynamicConstants.js.map +1 -0
- package/dist-es5/applicationinsights-channel-js.js +6 -0
- package/package.json +18 -17
- package/tsconfig.json +5 -4
- package/types/applicationinsights-channel-js.d.ts +284 -1
- package/{dist/applicationinsights-channel-js.d.ts → types/applicationinsights-channel-js.namespaced.d.ts} +1 -1
- package/browser/applicationinsights-channel-js.integrity.json +0 -26
- package/browser/applicationinsights-channel-js.js.map +0 -1
- package/browser/applicationinsights-channel-js.min.js +0 -6
- package/browser/applicationinsights-channel-js.min.js.map +0 -1
- package/dist/applicationinsights-channel-js.api.json +0 -1357
- package/dist/applicationinsights-channel-js.api.md +0 -60
- package/dist/applicationinsights-channel-js.js.map +0 -1
- package/dist/applicationinsights-channel-js.min.js +0 -6
- package/dist/applicationinsights-channel-js.min.js.map +0 -1
- package/dist/applicationinsights-channel-js.rollup.d.ts +0 -285
- package/dist-esm/EnvelopeCreator.js.map +0 -1
- package/dist-esm/Interfaces.js +0 -6
- package/dist-esm/Offline.js.map +0 -1
- package/dist-esm/Sender.js.map +0 -1
- package/dist-esm/__DynamicConstants.js.map +0 -1
- package/dist-esm/applicationinsights-channel-js.js +0 -6
- package/src/EnvelopeCreator.ts +0 -351
- package/src/Interfaces.ts +0 -114
- package/src/InternalConstants.ts +0 -11
- package/src/Offline.ts +0 -106
- package/src/SendBuffer.ts +0 -396
- package/src/Sender.ts +0 -1256
- package/src/Serializer.ts +0 -177
- package/src/TelemetryProcessors/Sample.ts +0 -49
- package/src/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.ts +0 -37
- package/src/TelemetryProcessors/SamplingScoreGenerators/SamplingScoreGenerator.ts +0 -35
- package/src/__DynamicConstants.ts +0 -64
- package/src/applicationinsights-channel-js.ts +0 -1
- package/types/EnvelopeCreator.d.ts +0 -12
- package/types/Interfaces.d.ts +0 -95
- package/types/InternalConstants.d.ts +0 -1
- package/types/Offline.d.ts +0 -10
- package/types/SendBuffer.d.ts +0 -73
- package/types/Sender.d.ts +0 -84
- package/types/Serializer.d.ts +0 -9
- package/types/TelemetryProcessors/Sample.d.ts +0 -12
- package/types/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.d.ts +0 -5
- package/types/TelemetryProcessors/SamplingScoreGenerators/SamplingScoreGenerator.d.ts +0 -5
- package/types/__DynamicConstants.d.ts +0 -52
- package/types/tsdoc-metadata.json +0 -11
- /package/{dist-esm → dist-es5}/Interfaces.js.map +0 -0
- /package/{dist-esm → dist-es5}/InternalConstants.js.map +0 -0
- /package/{dist-esm → dist-es5}/SendBuffer.js.map +0 -0
- /package/{dist-esm → dist-es5}/Serializer.js.map +0 -0
- /package/{dist-esm → dist-es5}/TelemetryProcessors/Sample.js.map +0 -0
- /package/{dist-esm → dist-es5}/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.js.map +0 -0
- /package/{dist-esm → dist-es5}/TelemetryProcessors/SamplingScoreGenerators/SamplingScoreGenerator.js.map +0 -0
- /package/{dist-esm → dist-es5}/applicationinsights-channel-js.js.map +0 -0
package/src/SendBuffer.ts
DELETED
|
@@ -1,396 +0,0 @@
|
|
|
1
|
-
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
2
|
-
import { utlGetSessionStorage, utlSetSessionStorage } from "@microsoft/applicationinsights-common";
|
|
3
|
-
import {
|
|
4
|
-
IDiagnosticLogger, _eInternalMessageId, _throwInternal, arrForEach, arrIndexOf, dumpObj, eLoggingSeverity, getExceptionName, getJSON,
|
|
5
|
-
isArray, isFunction, isString
|
|
6
|
-
} from "@microsoft/applicationinsights-core-js";
|
|
7
|
-
import { ISenderConfig } from "./Interfaces";
|
|
8
|
-
|
|
9
|
-
export interface ISendBuffer {
|
|
10
|
-
/**
|
|
11
|
-
* Enqueue the payload
|
|
12
|
-
*/
|
|
13
|
-
enqueue: (payload: string) => void;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Returns the number of elements in the buffer
|
|
17
|
-
*/
|
|
18
|
-
count: () => number;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Returns the current size of the serialized buffer
|
|
22
|
-
*/
|
|
23
|
-
size: () => number;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Clears the buffer
|
|
27
|
-
*/
|
|
28
|
-
clear: () => void;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Returns items stored in the buffer
|
|
32
|
-
*/
|
|
33
|
-
getItems: () => string[];
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Build a batch of all elements in the payload array
|
|
37
|
-
*/
|
|
38
|
-
batchPayloads: (payload: string[]) => string;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Moves items to the SENT_BUFFER.
|
|
42
|
-
* The buffer holds items which were sent, but we haven't received any response from the backend yet.
|
|
43
|
-
*/
|
|
44
|
-
markAsSent: (payload: string[]) => void;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Removes items from the SENT_BUFFER. Should be called on successful response from the backend.
|
|
48
|
-
*/
|
|
49
|
-
clearSent: (payload: string[]) => void;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Copy current buffer items to a new buffer.
|
|
53
|
-
* if canUseSessionStorage is undefined, it will set to false.
|
|
54
|
-
* if newLogger and newConfig are undefined, current logger and empty config will be used.
|
|
55
|
-
* if canUseSessionStorage is set to true, new SessionStorageSendBuffer will be returned otherwise ArraySendBuffer will be returned.
|
|
56
|
-
*/
|
|
57
|
-
createNew: (newLogger?: IDiagnosticLogger, newConfig?: ISenderConfig, canUseSessionStorage?: boolean) => ArraySendBuffer | SessionStorageSendBuffer;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
abstract class BaseSendBuffer {
|
|
61
|
-
|
|
62
|
-
protected _get: () => string[];
|
|
63
|
-
protected _set: (buffer: string[]) => string[];
|
|
64
|
-
|
|
65
|
-
constructor(logger: IDiagnosticLogger, config: ISenderConfig) {
|
|
66
|
-
let _buffer: string[] = [];
|
|
67
|
-
let _bufferFullMessageSent = false;
|
|
68
|
-
|
|
69
|
-
this._get = () => {
|
|
70
|
-
return _buffer;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
this._set = (buffer: string[]) => {
|
|
74
|
-
_buffer = buffer;
|
|
75
|
-
return _buffer;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
dynamicProto(BaseSendBuffer, this, (_self) => {
|
|
79
|
-
|
|
80
|
-
_self.enqueue = (payload: string) => {
|
|
81
|
-
if (_self.count() >= config.eventsLimitInMem) {
|
|
82
|
-
// sent internal log only once per page view
|
|
83
|
-
if (!_bufferFullMessageSent) {
|
|
84
|
-
_throwInternal(logger,
|
|
85
|
-
eLoggingSeverity.WARNING,
|
|
86
|
-
_eInternalMessageId.InMemoryStorageBufferFull,
|
|
87
|
-
"Maximum in-memory buffer size reached: " + _self.count(),
|
|
88
|
-
true);
|
|
89
|
-
_bufferFullMessageSent = true;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
_buffer.push(payload);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
_self.count = (): number => {
|
|
99
|
-
return _buffer.length;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
_self.size = (): number => {
|
|
103
|
-
let size = _buffer.length;
|
|
104
|
-
for (let lp = 0; lp < _buffer.length; lp++) {
|
|
105
|
-
size += _buffer[lp].length;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (!config.emitLineDelimitedJson) {
|
|
109
|
-
size += 2;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return size;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
_self.clear = () => {
|
|
116
|
-
_buffer = [];
|
|
117
|
-
_bufferFullMessageSent = false;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
_self.getItems = (): string[] => {
|
|
121
|
-
return _buffer.slice(0)
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
_self.batchPayloads = (payload: string[]): string => {
|
|
125
|
-
if (payload && payload.length > 0) {
|
|
126
|
-
const batch = config.emitLineDelimitedJson ?
|
|
127
|
-
payload.join("\n") :
|
|
128
|
-
"[" + payload.join(",") + "]";
|
|
129
|
-
|
|
130
|
-
return batch;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return null;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
_self.createNew = (newLogger?: IDiagnosticLogger, newConfig?: ISenderConfig, canUseSessionStorage?: boolean): ArraySendBuffer | SessionStorageSendBuffer => {
|
|
137
|
-
let items = _buffer.slice(0);
|
|
138
|
-
newLogger = newLogger || logger;
|
|
139
|
-
newConfig = newConfig || {} as ISenderConfig;
|
|
140
|
-
let newBuffer = !!canUseSessionStorage? new SessionStorageSendBuffer(newLogger, newConfig) : new ArraySendBuffer(newLogger, newConfig);
|
|
141
|
-
arrForEach(items, (payload) => {
|
|
142
|
-
newBuffer.enqueue(payload);
|
|
143
|
-
});
|
|
144
|
-
return newBuffer;
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
public enqueue(payload: string) {
|
|
150
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
public count(): number {
|
|
154
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
155
|
-
return 0;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
public size(): number {
|
|
159
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
160
|
-
return 0;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
public clear() {
|
|
164
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
public getItems(): string[] {
|
|
168
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
public batchPayloads(payload: string[]): string {
|
|
173
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
public createNew(newLogger?: IDiagnosticLogger, newConfig?: ISenderConfig, canUseSessionStorage?: boolean): ArraySendBuffer | SessionStorageSendBuffer {
|
|
178
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
179
|
-
return null
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/*
|
|
184
|
-
* An array based send buffer.
|
|
185
|
-
*/
|
|
186
|
-
export class ArraySendBuffer extends BaseSendBuffer implements ISendBuffer {
|
|
187
|
-
|
|
188
|
-
constructor(logger: IDiagnosticLogger, config: ISenderConfig) {
|
|
189
|
-
super(logger, config);
|
|
190
|
-
|
|
191
|
-
dynamicProto(ArraySendBuffer, this, (_self, _base) => {
|
|
192
|
-
|
|
193
|
-
_self.markAsSent = (payload: string[]) => {
|
|
194
|
-
_base.clear();
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
_self.clearSent = (payload: string[]) => {
|
|
198
|
-
// not supported
|
|
199
|
-
};
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
public markAsSent(payload: string[]) {
|
|
204
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
public clearSent(payload: string[]) {
|
|
208
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/*
|
|
213
|
-
* Session storage buffer holds a copy of all unsent items in the browser session storage.
|
|
214
|
-
*/
|
|
215
|
-
export class SessionStorageSendBuffer extends BaseSendBuffer implements ISendBuffer {
|
|
216
|
-
static BUFFER_KEY = "AI_buffer";
|
|
217
|
-
static SENT_BUFFER_KEY = "AI_sentBuffer";
|
|
218
|
-
|
|
219
|
-
// Maximum number of payloads stored in the buffer. If the buffer is full, new elements will be dropped.
|
|
220
|
-
static MAX_BUFFER_SIZE = 2000;
|
|
221
|
-
|
|
222
|
-
constructor(logger: IDiagnosticLogger, config: ISenderConfig) {
|
|
223
|
-
super(logger, config);
|
|
224
|
-
let _bufferFullMessageSent = false;
|
|
225
|
-
//Note: should not use config.namePrefix directly, because it will always refers to the latest namePrefix
|
|
226
|
-
let _namePrefix = config?.namePrefix;
|
|
227
|
-
|
|
228
|
-
dynamicProto(SessionStorageSendBuffer, this, (_self, _base) => {
|
|
229
|
-
const bufferItems = _getBuffer(SessionStorageSendBuffer.BUFFER_KEY);
|
|
230
|
-
const notDeliveredItems = _getBuffer(SessionStorageSendBuffer.SENT_BUFFER_KEY);
|
|
231
|
-
|
|
232
|
-
let buffer = _self._set(bufferItems.concat(notDeliveredItems));
|
|
233
|
-
|
|
234
|
-
// If the buffer has too many items, drop items from the end.
|
|
235
|
-
if (buffer.length > SessionStorageSendBuffer.MAX_BUFFER_SIZE) {
|
|
236
|
-
buffer.length = SessionStorageSendBuffer.MAX_BUFFER_SIZE;
|
|
237
|
-
}
|
|
238
|
-
_setBuffer(SessionStorageSendBuffer.SENT_BUFFER_KEY, []);
|
|
239
|
-
_setBuffer(SessionStorageSendBuffer.BUFFER_KEY, buffer);
|
|
240
|
-
|
|
241
|
-
_self.enqueue = (payload: string) => {
|
|
242
|
-
if (_self.count() >= SessionStorageSendBuffer.MAX_BUFFER_SIZE) {
|
|
243
|
-
// sent internal log only once per page view
|
|
244
|
-
if (!_bufferFullMessageSent) {
|
|
245
|
-
_throwInternal(logger,
|
|
246
|
-
eLoggingSeverity.WARNING,
|
|
247
|
-
_eInternalMessageId.SessionStorageBufferFull,
|
|
248
|
-
"Maximum buffer size reached: " + _self.count(),
|
|
249
|
-
true);
|
|
250
|
-
_bufferFullMessageSent = true;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
_base.enqueue(payload);
|
|
257
|
-
_setBuffer(SessionStorageSendBuffer.BUFFER_KEY, _self._get());
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
_self.clear = () => {
|
|
261
|
-
_base.clear();
|
|
262
|
-
_setBuffer(SessionStorageSendBuffer.BUFFER_KEY, _self._get());
|
|
263
|
-
_setBuffer(SessionStorageSendBuffer.SENT_BUFFER_KEY, []);
|
|
264
|
-
|
|
265
|
-
_bufferFullMessageSent = false;
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
_self.markAsSent = (payload: string[]) => {
|
|
269
|
-
_setBuffer(SessionStorageSendBuffer.BUFFER_KEY,
|
|
270
|
-
_self._set(_removePayloadsFromBuffer(payload, _self._get())));
|
|
271
|
-
|
|
272
|
-
let sentElements = _getBuffer(SessionStorageSendBuffer.SENT_BUFFER_KEY);
|
|
273
|
-
if (sentElements instanceof Array && payload instanceof Array) {
|
|
274
|
-
sentElements = sentElements.concat(payload);
|
|
275
|
-
|
|
276
|
-
if (sentElements.length > SessionStorageSendBuffer.MAX_BUFFER_SIZE) {
|
|
277
|
-
// We send telemetry normally. If the SENT_BUFFER is too big we don't add new elements
|
|
278
|
-
// until we receive a response from the backend and the buffer has free space again (see clearSent method)
|
|
279
|
-
_throwInternal(logger,
|
|
280
|
-
eLoggingSeverity.CRITICAL,
|
|
281
|
-
_eInternalMessageId.SessionStorageBufferFull,
|
|
282
|
-
"Sent buffer reached its maximum size: " + sentElements.length,
|
|
283
|
-
true);
|
|
284
|
-
|
|
285
|
-
sentElements.length = SessionStorageSendBuffer.MAX_BUFFER_SIZE;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
_setBuffer(SessionStorageSendBuffer.SENT_BUFFER_KEY, sentElements);
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
_self.clearSent = (payload: string[]) => {
|
|
293
|
-
let sentElements = _getBuffer(SessionStorageSendBuffer.SENT_BUFFER_KEY);
|
|
294
|
-
sentElements = _removePayloadsFromBuffer(payload, sentElements);
|
|
295
|
-
|
|
296
|
-
_setBuffer(SessionStorageSendBuffer.SENT_BUFFER_KEY, sentElements);
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
_self.createNew = (newLogger?: IDiagnosticLogger, newConfig?: ISenderConfig, canUseSessionStorage?: boolean) => {
|
|
300
|
-
canUseSessionStorage = !!canUseSessionStorage;
|
|
301
|
-
let unsentItems = _self._get().slice(0);
|
|
302
|
-
let sentItems = _getBuffer(SessionStorageSendBuffer.SENT_BUFFER_KEY).slice(0);
|
|
303
|
-
newLogger = newLogger || logger;
|
|
304
|
-
newConfig = newConfig || {} as ISenderConfig;
|
|
305
|
-
|
|
306
|
-
// to make sure that we do not send duplicated payloads when it is switched back to previous one
|
|
307
|
-
_self.clear();
|
|
308
|
-
let newBuffer = canUseSessionStorage? new SessionStorageSendBuffer(newLogger, newConfig) : new ArraySendBuffer(newLogger, newConfig);
|
|
309
|
-
arrForEach(unsentItems, (payload) => {
|
|
310
|
-
newBuffer.enqueue(payload);
|
|
311
|
-
});
|
|
312
|
-
if (canUseSessionStorage) {
|
|
313
|
-
// arr buffer will clear all payloads if markAsSent() is called
|
|
314
|
-
newBuffer.markAsSent(sentItems);
|
|
315
|
-
}
|
|
316
|
-
return newBuffer;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
function _removePayloadsFromBuffer(payloads: string[], buffer: string[]): string[] {
|
|
320
|
-
const remaining: string[] = [];
|
|
321
|
-
arrForEach(buffer, (value) => {
|
|
322
|
-
if (!isFunction(value) && arrIndexOf(payloads, value) === -1) {
|
|
323
|
-
remaining.push(value);
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
return remaining;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
function _getBuffer(key: string): string[] {
|
|
331
|
-
let prefixedKey = key;
|
|
332
|
-
try {
|
|
333
|
-
prefixedKey = _namePrefix ? _namePrefix + "_" + prefixedKey : prefixedKey;
|
|
334
|
-
const bufferJson = utlGetSessionStorage(logger, prefixedKey);
|
|
335
|
-
if (bufferJson) {
|
|
336
|
-
let buffer: string[] = getJSON().parse(bufferJson);
|
|
337
|
-
if (isString(buffer)) {
|
|
338
|
-
// When using some version prototype.js the stringify / parse cycle does not decode array's correctly
|
|
339
|
-
buffer = getJSON().parse(buffer as any);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
if (buffer && isArray(buffer)) {
|
|
343
|
-
return buffer;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
} catch (e) {
|
|
347
|
-
_throwInternal(logger, eLoggingSeverity.CRITICAL,
|
|
348
|
-
_eInternalMessageId.FailedToRestoreStorageBuffer,
|
|
349
|
-
" storage key: " + prefixedKey + ", " + getExceptionName(e),
|
|
350
|
-
{ exception: dumpObj(e) });
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
return [];
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
function _setBuffer(key: string, buffer: string[]) {
|
|
357
|
-
let prefixedKey = key;
|
|
358
|
-
try {
|
|
359
|
-
prefixedKey = _namePrefix ? _namePrefix + "_" + prefixedKey : prefixedKey;
|
|
360
|
-
const bufferJson = JSON.stringify(buffer);
|
|
361
|
-
utlSetSessionStorage(logger, prefixedKey, bufferJson);
|
|
362
|
-
} catch (e) {
|
|
363
|
-
// if there was an error, clear the buffer
|
|
364
|
-
// telemetry is stored in the _buffer array so we won't loose any items
|
|
365
|
-
utlSetSessionStorage(logger, prefixedKey, JSON.stringify([]));
|
|
366
|
-
|
|
367
|
-
_throwInternal(logger, eLoggingSeverity.WARNING,
|
|
368
|
-
_eInternalMessageId.FailedToSetStorageBuffer,
|
|
369
|
-
" storage key: " + prefixedKey + ", " + getExceptionName(e) + ". Buffer cleared",
|
|
370
|
-
{ exception: dumpObj(e) });
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
public enqueue(payload: string) {
|
|
377
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
public clear() {
|
|
381
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
public markAsSent(payload: string[]) {
|
|
385
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
public clearSent(payload: string[]) {
|
|
389
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
public createNew(newLogger?: IDiagnosticLogger, newConfig?: ISenderConfig, canUseSessionStorage?: boolean): ArraySendBuffer | SessionStorageSendBuffer {
|
|
393
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
394
|
-
return null
|
|
395
|
-
}
|
|
396
|
-
}
|