kuzzle-logger 1.4.0 → 1.5.0-beta.1

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 (65) hide show
  1. package/README.md +50 -6
  2. package/dist/KuzzleLogger.d.ts +14 -1
  3. package/dist/KuzzleLogger.js +42 -71
  4. package/dist/KuzzleLogger.js.map +1 -1
  5. package/dist/Presets.d.ts +1 -0
  6. package/dist/Presets.js +12 -1
  7. package/dist/Presets.js.map +1 -1
  8. package/dist/esm/browser/KuzzleLogger.d.ts +97 -0
  9. package/dist/esm/browser/KuzzleLogger.js +240 -0
  10. package/dist/esm/browser/KuzzleLogger.js.map +1 -0
  11. package/dist/esm/browser/batchingSender.d.ts +70 -0
  12. package/dist/esm/browser/batchingSender.js +166 -0
  13. package/dist/esm/browser/batchingSender.js.map +1 -0
  14. package/dist/esm/browser/capture.d.ts +48 -0
  15. package/dist/esm/browser/capture.js +139 -0
  16. package/dist/esm/browser/capture.js.map +1 -0
  17. package/dist/esm/browser/index.d.ts +16 -0
  18. package/dist/esm/browser/index.js +12 -0
  19. package/dist/esm/browser/index.js.map +1 -0
  20. package/dist/esm/browser/senders.d.ts +54 -0
  21. package/dist/esm/browser/senders.js +57 -0
  22. package/dist/esm/browser/senders.js.map +1 -0
  23. package/dist/esm/package.json +4 -0
  24. package/dist/esm/protocol/payload.d.ts +60 -0
  25. package/dist/esm/protocol/payload.js +9 -0
  26. package/dist/esm/protocol/payload.js.map +1 -0
  27. package/dist/esm/serializeError.d.ts +27 -0
  28. package/dist/esm/serializeError.js +61 -0
  29. package/dist/esm/serializeError.js.map +1 -0
  30. package/dist/esm/types/JSONObject.d.ts +6 -0
  31. package/dist/esm/types/JSONObject.js +2 -0
  32. package/dist/esm/types/JSONObject.js.map +1 -0
  33. package/dist/index.d.ts +1 -0
  34. package/dist/index.js +1 -0
  35. package/dist/index.js.map +1 -1
  36. package/dist/kuzzle/createBrowserLogsController.d.ts +111 -0
  37. package/dist/kuzzle/createBrowserLogsController.js +131 -0
  38. package/dist/kuzzle/createBrowserLogsController.js.map +1 -0
  39. package/dist/kuzzle/index.d.ts +8 -0
  40. package/dist/kuzzle/index.js +25 -0
  41. package/dist/kuzzle/index.js.map +1 -0
  42. package/dist/protocol/fingerprint.d.ts +22 -0
  43. package/dist/protocol/fingerprint.js +73 -0
  44. package/dist/protocol/fingerprint.js.map +1 -0
  45. package/dist/protocol/index.d.ts +4 -0
  46. package/dist/protocol/index.js +21 -0
  47. package/dist/protocol/index.js.map +1 -0
  48. package/dist/protocol/payload.d.ts +60 -0
  49. package/dist/protocol/payload.js +12 -0
  50. package/dist/protocol/payload.js.map +1 -0
  51. package/dist/protocol/sanitize.d.ts +30 -0
  52. package/dist/protocol/sanitize.js +73 -0
  53. package/dist/protocol/sanitize.js.map +1 -0
  54. package/dist/protocol/validateBatch.d.ts +60 -0
  55. package/dist/protocol/validateBatch.js +191 -0
  56. package/dist/protocol/validateBatch.js.map +1 -0
  57. package/dist/serializeError.d.ts +27 -0
  58. package/dist/serializeError.js +66 -0
  59. package/dist/serializeError.js.map +1 -0
  60. package/dist/tsconfig.build.tsbuildinfo +1 -1
  61. package/dist/types/JSONObject.d.ts +6 -0
  62. package/dist/types/JSONObject.js +3 -0
  63. package/dist/types/JSONObject.js.map +1 -0
  64. package/dist/types/KuzzleLoggerConfig.d.ts +1 -1
  65. package/package.json +48 -6
@@ -0,0 +1,240 @@
1
+ // pino ships no typings for its browser build: the members used are typed below (PinoBrowserLogger).
2
+ import pino from 'pino/browser.js';
3
+ import { BROWSER_LOG_LEVELS } from '../protocol/payload.js';
4
+ import { isErrorLike, serializeError } from '../serializeError.js';
5
+ const ENTRY = Symbol('kuzzle-logger.entry');
6
+ // Set by withoutConsoleMirroring(): pino browser calls write() synchronously
7
+ let consoleMirroringSuppressed = false;
8
+ const LEVEL_VALUES = {
9
+ debug: 20,
10
+ error: 50,
11
+ fatal: 60,
12
+ info: 30,
13
+ silent: Infinity,
14
+ trace: 10,
15
+ warn: 40,
16
+ };
17
+ const CONSOLE_METHODS = {
18
+ debug: 'debug',
19
+ error: 'error',
20
+ fatal: 'error',
21
+ info: 'info',
22
+ trace: 'debug',
23
+ warn: 'warn',
24
+ };
25
+ /**
26
+ * Browser logger, with the same API as the Node KuzzleLogger.
27
+ *
28
+ * Entries are mirrored to the devtools console and handed to the sender, which
29
+ * forwards them to the application backend. It never throws because of its output.
30
+ */
31
+ export class KuzzleLogger {
32
+ _pino;
33
+ output;
34
+ getMergingObject = () => ({});
35
+ get level() {
36
+ return this._pino.level;
37
+ }
38
+ set level(level) {
39
+ this._pino.level = level;
40
+ }
41
+ constructor(config = {}) {
42
+ const { getMergingObject, namespace } = config;
43
+ const consoleOption = config.console ?? true;
44
+ if (getMergingObject || namespace) {
45
+ this.getMergingObject = () => {
46
+ const mergingObject = getMergingObject?.() ?? {};
47
+ return namespace && !mergingObject.namespace
48
+ ? { ...mergingObject, namespace }
49
+ : mergingObject;
50
+ };
51
+ }
52
+ let consoleThreshold = consoleOption ? 0 : Infinity;
53
+ if (typeof consoleOption === 'string') {
54
+ consoleThreshold = LEVEL_VALUES[consoleOption];
55
+ }
56
+ this.output = { consoleThreshold, sender: config.sender };
57
+ const output = this.output;
58
+ const write = (logObject) => emit(output, logObject);
59
+ this._pino = pino({
60
+ browser: {
61
+ formatters: { level: (label) => ({ level: label }) },
62
+ write: Object.fromEntries(BROWSER_LOG_LEVELS.map((level) => [level, write])),
63
+ },
64
+ level: config.level ?? 'info',
65
+ });
66
+ }
67
+ trace(objOrMsg, ...args) {
68
+ this.log('trace', objOrMsg, args);
69
+ }
70
+ debug(objOrMsg, ...args) {
71
+ this.log('debug', objOrMsg, args);
72
+ }
73
+ info(objOrMsg, ...args) {
74
+ this.log('info', objOrMsg, args);
75
+ }
76
+ warn(objOrMsg, ...args) {
77
+ this.log('warn', objOrMsg, args);
78
+ }
79
+ error(objOrMsg, ...args) {
80
+ this.log('error', objOrMsg, args);
81
+ }
82
+ fatal(objOrMsg, ...args) {
83
+ this.log('fatal', objOrMsg, args);
84
+ }
85
+ /**
86
+ * Sends pending entries. Never rejects: sender failures are swallowed.
87
+ */
88
+ async flush() {
89
+ try {
90
+ await this.output.sender?.flush?.();
91
+ }
92
+ catch {
93
+ // Logging must never break the application
94
+ }
95
+ }
96
+ /**
97
+ * Creates a child logger whose namespace is "<parent namespace>:<namespace>".
98
+ * The parent merging object is evaluated on each log, not at creation time.
99
+ */
100
+ child(namespace) {
101
+ const childLogger = Object.create(KuzzleLogger.prototype);
102
+ childLogger._pino = this._pino.child({});
103
+ childLogger.output = this.output;
104
+ childLogger.getMergingObject = () => {
105
+ const parentMergingObject = this.getMergingObject();
106
+ return {
107
+ ...parentMergingObject,
108
+ namespace: parentMergingObject?.namespace
109
+ ? `${parentMergingObject.namespace}:${namespace}`
110
+ : namespace,
111
+ };
112
+ };
113
+ return childLogger;
114
+ }
115
+ log(level, objOrMsg, args) {
116
+ if (typeof objOrMsg === 'object' && objOrMsg !== null) {
117
+ const message = args.shift();
118
+ if (isErrorLike(objOrMsg)) {
119
+ this._pino[level](this.toLogObject({}, objOrMsg), message ?? objOrMsg.message, ...args);
120
+ return;
121
+ }
122
+ this._pino[level](this.toLogObject(objOrMsg), message, ...args);
123
+ return;
124
+ }
125
+ this._pino[level](this.toLogObject({}), objOrMsg, ...args);
126
+ }
127
+ toLogObject(obj, err) {
128
+ const { namespace, ...context } = { ...obj, ...this.getMergingObject() };
129
+ const entry = {};
130
+ // Same keys as the Node error serializers
131
+ for (const key of ['err', 'error']) {
132
+ if (err === undefined && isErrorLike(context[key])) {
133
+ err = context[key];
134
+ delete context[key];
135
+ }
136
+ }
137
+ if (err !== undefined) {
138
+ entry.err = err;
139
+ }
140
+ if (Object.keys(context).length > 0) {
141
+ entry.context = context;
142
+ }
143
+ if (typeof namespace === 'string' && namespace.length > 0) {
144
+ entry.namespace = namespace;
145
+ }
146
+ return { [ENTRY]: entry };
147
+ }
148
+ }
149
+ /**
150
+ * Runs fn with console mirroring disabled for every logger. Used by the capture
151
+ * helpers for errors that the browser, or the helper itself, already prints.
152
+ * Not exported from the browser entry point.
153
+ */
154
+ export function withoutConsoleMirroring(fn) {
155
+ consoleMirroringSuppressed = true;
156
+ try {
157
+ fn();
158
+ }
159
+ finally {
160
+ consoleMirroringSuppressed = false;
161
+ }
162
+ }
163
+ function emit(output, logObject) {
164
+ const { level, msg, time } = logObject;
165
+ const pending = logObject[ENTRY] ?? {};
166
+ if (!consoleMirroringSuppressed && LEVEL_VALUES[level] >= output.consoleThreshold) {
167
+ mirrorToConsole(level, msg, pending);
168
+ }
169
+ if (!output.sender) {
170
+ return;
171
+ }
172
+ try {
173
+ const entry = { level, time };
174
+ if (msg !== undefined) {
175
+ entry.msg = String(msg);
176
+ }
177
+ if (pending.namespace) {
178
+ entry.namespace = pending.namespace;
179
+ }
180
+ if (pending.context) {
181
+ entry.context = toJSON(pending.context);
182
+ }
183
+ if (pending.err !== undefined) {
184
+ entry.err = toJSON(serializeError(pending.err));
185
+ }
186
+ output.sender.send(entry);
187
+ }
188
+ catch {
189
+ // Logging must never break the application
190
+ }
191
+ }
192
+ function mirrorToConsole(level, msg, pending) {
193
+ const method = CONSOLE_METHODS[level];
194
+ const args = [pending.namespace ? `[${pending.namespace}] ${msg ?? ''}` : (msg ?? '')];
195
+ if (pending.context) {
196
+ args.push(pending.context);
197
+ }
198
+ // The original error, so that devtools display a clickable stack
199
+ if (pending.err !== undefined) {
200
+ args.push(pending.err);
201
+ }
202
+ try {
203
+ globalThis.console?.[method]?.(...args);
204
+ }
205
+ catch {
206
+ // Logging must never break the application
207
+ }
208
+ }
209
+ /**
210
+ * Converts a value to plain JSON: errors are serialized, dates become ISO strings,
211
+ * bigints become strings, circular references become "[Circular]", and functions,
212
+ * symbols and undefined values are dropped.
213
+ */
214
+ function toJSON(value) {
215
+ // Objects being serialized, from the root to the current one: "value" is what was
216
+ // returned by the replacer (e.g. a serialized error), "original" what it replaced.
217
+ const ancestors = [];
218
+ /* eslint-disable no-invalid-this -- JSON.stringify binds "this" to the holder object */
219
+ const json = JSON.stringify(value, function replacer(_key, item) {
220
+ if (typeof item === 'bigint') {
221
+ return item.toString();
222
+ }
223
+ if (typeof item !== 'object' || item === null) {
224
+ return item;
225
+ }
226
+ // "this" is the object holding the current key: unwind the ancestors down to it
227
+ while (ancestors.length > 0 && ancestors[ancestors.length - 1].value !== this) {
228
+ ancestors.pop();
229
+ }
230
+ if (ancestors.some((ancestor) => ancestor.original === item || ancestor.value === item)) {
231
+ return '[Circular]';
232
+ }
233
+ const result = isErrorLike(item) ? serializeError(item) : item;
234
+ ancestors.push({ original: item, value: result });
235
+ return result;
236
+ });
237
+ /* eslint-enable no-invalid-this */
238
+ return json === undefined ? undefined : JSON.parse(json);
239
+ }
240
+ //# sourceMappingURL=KuzzleLogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KuzzleLogger.js","sourceRoot":"","sources":["../../../src/browser/KuzzleLogger.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,OAAO,IAAI,MAAM,iBAAiB,CAAC;AAEnC,OAAO,EAAE,kBAAkB,EAAoC,MAAM,wBAAwB,CAAC;AAC9F,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AA4EnE,MAAM,KAAK,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAE5C,6EAA6E;AAC7E,IAAI,0BAA0B,GAAG,KAAK,CAAC;AAEvC,MAAM,YAAY,GAAuC;IACvD,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,EAAE;IACR,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,EAAE;CACT,CAAC;AAEF,MAAM,eAAe,GAAiE;IACpF,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,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SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;YAC9E,SAAS,CAAC,GAAG,EAAE,CAAC;QAClB,CAAC;QAED,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,KAAK,IAAI,IAAI,QAAQ,CAAC,KAAK,KAAK,IAAI,CAAC,EAAE,CAAC;YACxF,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,cAAc,CAAC,IAAI,CAAY,CAAC,CAAC,CAAC,IAAI,CAAC;QAE3E,SAAS,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAElD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;IACH,mCAAmC;IAEnC,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { BrowserLogsApp, BrowserLogsPayload } from '../protocol/payload.js';
2
+ import { BrowserLogSender } from './KuzzleLogger.js';
3
+ export type TransportOptions = {
4
+ /**
5
+ * True when the page is being hidden or unloaded: the request must survive it
6
+ * (e.g. fetch with "keepalive").
7
+ */
8
+ keepalive: boolean;
9
+ };
10
+ /**
11
+ * Sends one batch. It rejects on failure: wrap the error in a NonRetryableError
12
+ * when retrying is pointless (e.g. 400, 403).
13
+ */
14
+ export type BatchTransport = (payload: BrowserLogsPayload, options: TransportOptions) => Promise<void>;
15
+ export type BatchingOptions = {
16
+ /**
17
+ * Informational description of the application, sent with each batch.
18
+ */
19
+ app?: BrowserLogsApp;
20
+ /**
21
+ * Delay before sending a non-full batch, in milliseconds.
22
+ * @default 5000
23
+ */
24
+ flushInterval?: number;
25
+ /**
26
+ * Maximum number of entries per batch.
27
+ * @default 20
28
+ */
29
+ maxBatchSize?: number;
30
+ /**
31
+ * Maximum number of entries kept in memory. Oldest entries are dropped first, and
32
+ * the number of dropped entries is sent with the next batch.
33
+ * @default 500
34
+ */
35
+ maxBufferSize?: number;
36
+ /**
37
+ * Retries of a failed batch before it is dropped.
38
+ * @default 3
39
+ */
40
+ maxRetries?: number;
41
+ /**
42
+ * First retry delay, in milliseconds. It doubles at each attempt (max 60 s).
43
+ * @default 1000
44
+ */
45
+ retryDelay?: number;
46
+ };
47
+ export type BatchingSender = BrowserLogSender & {
48
+ /**
49
+ * Stops the timers and removes the page lifecycle listeners. Pending entries are
50
+ * not sent: call flush() first.
51
+ */
52
+ close(): void;
53
+ flush(): Promise<void>;
54
+ };
55
+ /**
56
+ * A transport failure that must not be retried.
57
+ */
58
+ export declare class NonRetryableError extends Error {
59
+ constructor(message: string);
60
+ }
61
+ /**
62
+ * Creates a sender that buffers entries and sends them in batches (payload v1):
63
+ * - when "maxBatchSize" entries are pending, or "flushInterval" after the first one,
64
+ * - immediately on "error" and "fatal" entries,
65
+ * - with "keepalive" when the page is hidden ("pagehide", "visibilitychange").
66
+ *
67
+ * Failed batches are retried with an exponential backoff. The sender never throws,
68
+ * and never logs (no recursion through the logger it serves).
69
+ */
70
+ export declare function createBatchingSender(transport: BatchTransport, options?: BatchingOptions): BatchingSender;
@@ -0,0 +1,166 @@
1
+ import { PAYLOAD_VERSION, } from '../protocol/payload.js';
2
+ /**
3
+ * A transport failure that must not be retried.
4
+ */
5
+ export class NonRetryableError extends Error {
6
+ constructor(message) {
7
+ super(message);
8
+ this.name = 'NonRetryableError';
9
+ }
10
+ }
11
+ const IMMEDIATE_LEVELS = new Set(['error', 'fatal']);
12
+ const MAX_RETRY_DELAY = 60000;
13
+ /**
14
+ * Creates a sender that buffers entries and sends them in batches (payload v1):
15
+ * - when "maxBatchSize" entries are pending, or "flushInterval" after the first one,
16
+ * - immediately on "error" and "fatal" entries,
17
+ * - with "keepalive" when the page is hidden ("pagehide", "visibilitychange").
18
+ *
19
+ * Failed batches are retried with an exponential backoff. The sender never throws,
20
+ * and never logs (no recursion through the logger it serves).
21
+ */
22
+ export function createBatchingSender(transport, options = {}) {
23
+ const maxBatchSize = Math.max(1, options.maxBatchSize ?? 20);
24
+ const maxBufferSize = Math.max(maxBatchSize, options.maxBufferSize ?? 500);
25
+ const flushInterval = options.flushInterval ?? 5000;
26
+ const maxRetries = options.maxRetries ?? 3;
27
+ const retryDelay = options.retryDelay ?? 1000;
28
+ let buffer = [];
29
+ let dropped = 0;
30
+ let attempt = 0;
31
+ let timer = null;
32
+ let retrying = false;
33
+ let inflight = null;
34
+ let closed = false;
35
+ const push = (entries, front) => {
36
+ buffer = front ? [...entries, ...buffer] : [...buffer, ...entries];
37
+ if (buffer.length > maxBufferSize) {
38
+ dropped += buffer.length - maxBufferSize;
39
+ buffer = buffer.slice(buffer.length - maxBufferSize);
40
+ }
41
+ };
42
+ const clearTimer = () => {
43
+ if (timer !== null) {
44
+ clearTimeout(timer);
45
+ timer = null;
46
+ }
47
+ };
48
+ const schedule = (delay) => {
49
+ if (timer === null && !closed) {
50
+ timer = setTimeout(() => {
51
+ timer = null;
52
+ retrying = false;
53
+ void flush();
54
+ }, delay);
55
+ }
56
+ };
57
+ const sendBatch = async (keepalive) => {
58
+ const entries = buffer.slice(0, maxBatchSize);
59
+ buffer = buffer.slice(entries.length);
60
+ const payload = { entries, version: PAYLOAD_VERSION };
61
+ const droppedBefore = dropped;
62
+ if (options.app) {
63
+ payload.app = options.app;
64
+ }
65
+ if (dropped > 0) {
66
+ payload.dropped = dropped;
67
+ dropped = 0;
68
+ }
69
+ try {
70
+ await transport(payload, { keepalive });
71
+ attempt = 0;
72
+ return 'sent';
73
+ }
74
+ catch (error) {
75
+ if (error instanceof NonRetryableError || attempt >= maxRetries) {
76
+ attempt = 0;
77
+ dropped += droppedBefore + entries.length;
78
+ return 'dropped';
79
+ }
80
+ attempt++;
81
+ dropped += droppedBefore;
82
+ push(entries, true);
83
+ return 'retry';
84
+ }
85
+ };
86
+ const run = async (keepalive) => {
87
+ while (buffer.length > 0 || dropped > 0) {
88
+ const outcome = await sendBatch(keepalive);
89
+ if (outcome === 'retry') {
90
+ retrying = true;
91
+ clearTimer();
92
+ schedule(Math.min(retryDelay * 2 ** (attempt - 1), MAX_RETRY_DELAY));
93
+ return;
94
+ }
95
+ // The transport keeps failing: the remaining entries wait for the next trigger
96
+ if (outcome === 'dropped') {
97
+ if (buffer.length > 0) {
98
+ schedule(flushInterval);
99
+ }
100
+ return;
101
+ }
102
+ }
103
+ };
104
+ const flush = async (keepalive = false) => {
105
+ if (!keepalive && retrying) {
106
+ return;
107
+ }
108
+ clearTimer();
109
+ while (inflight) {
110
+ await inflight;
111
+ }
112
+ if (buffer.length === 0 && dropped === 0) {
113
+ return;
114
+ }
115
+ inflight = run(keepalive)
116
+ .catch(() => { })
117
+ .finally(() => {
118
+ inflight = null;
119
+ });
120
+ await inflight;
121
+ };
122
+ const onHide = () => {
123
+ retrying = false;
124
+ void flush(true);
125
+ };
126
+ const onVisibilityChange = () => {
127
+ if (typeof document !== 'undefined' && document.visibilityState === 'hidden') {
128
+ onHide();
129
+ }
130
+ };
131
+ if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
132
+ window.addEventListener('pagehide', onHide);
133
+ }
134
+ if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
135
+ document.addEventListener('visibilitychange', onVisibilityChange);
136
+ }
137
+ return {
138
+ close: () => {
139
+ closed = true;
140
+ clearTimer();
141
+ if (typeof window !== 'undefined' && typeof window.removeEventListener === 'function') {
142
+ window.removeEventListener('pagehide', onHide);
143
+ }
144
+ if (typeof document !== 'undefined' && typeof document.removeEventListener === 'function') {
145
+ document.removeEventListener('visibilitychange', onVisibilityChange);
146
+ }
147
+ },
148
+ flush: () => flush(false),
149
+ send: (entry) => {
150
+ if (closed) {
151
+ return;
152
+ }
153
+ push([entry], false);
154
+ if (retrying) {
155
+ return;
156
+ }
157
+ if (IMMEDIATE_LEVELS.has(entry.level) || buffer.length >= maxBatchSize) {
158
+ void flush();
159
+ }
160
+ else {
161
+ schedule(flushInterval);
162
+ }
163
+ },
164
+ };
165
+ }
166
+ //# sourceMappingURL=batchingSender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batchingSender.js","sourceRoot":"","sources":["../../../src/browser/batchingSender.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,eAAe,GAChB,MAAM,wBAAwB,CAAC;AA8DhC;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AAErD,MAAM,eAAe,GAAG,KAAK,CAAC;AAE9B;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAAyB,EACzB,UAA2B,EAAE;IAE7B,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;IAC7D,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,aAAa,IAAI,GAAG,CAAC,CAAC;IAC3E,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,IAAI,CAAC;IACpD,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;IAC3C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC;IAE9C,IAAI,MAAM,GAAsB,EAAE,CAAC;IACnC,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB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BACN,QAAQ,CAAC,aAAa,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { KuzzleLogger } from './KuzzleLogger.js';
2
+ export type CaptureGlobalErrorsOptions = {
3
+ /**
4
+ * Identical errors (same kind, name, message and location) received within this
5
+ * delay of the previous one are dropped, so that an error thrown in a loop or a
6
+ * timer is logged once per interval instead of flooding the backend.
7
+ *
8
+ * @default 5000
9
+ */
10
+ dedupeInterval?: number;
11
+ /**
12
+ * Object the listeners are added to.
13
+ *
14
+ * @default window
15
+ */
16
+ target?: Pick<EventTarget, 'addEventListener' | 'removeEventListener'>;
17
+ };
18
+ /**
19
+ * Error handler for Vue 3 (`app.config.errorHandler`) and Vue 2 (`Vue.config.errorHandler`).
20
+ */
21
+ export type VueErrorHandler = (err: unknown, instance: unknown, info: string) => void;
22
+ /**
23
+ * Logs uncaught errors and unhandled promise rejections (`window` `error` and
24
+ * `unhandledrejection` events) at the error level. Opt-in: errors should be pushed
25
+ * explicitly where they are handled.
26
+ *
27
+ * The events are not cancelled, so the browser still prints them to the console,
28
+ * and the logger does not print them a second time.
29
+ *
30
+ * Returns a function that removes the listeners.
31
+ *
32
+ * @example
33
+ * const stop = captureGlobalErrors(logger.child('global'));
34
+ */
35
+ export declare function captureGlobalErrors(logger: KuzzleLogger, options?: CaptureGlobalErrorsOptions): () => void;
36
+ /**
37
+ * Returns an error handler that logs Vue errors at the error level, with the
38
+ * component name and the Vue `info` string (e.g. "setup function", "render function").
39
+ *
40
+ * Vue no longer prints errors when an error handler is set: this handler prints
41
+ * them with `console.error`, like Vue does in production.
42
+ *
43
+ * It does not depend on `vue`.
44
+ *
45
+ * @example
46
+ * app.config.errorHandler = createVueErrorHandler(logger.child('vue'));
47
+ */
48
+ export declare function createVueErrorHandler(logger: KuzzleLogger): VueErrorHandler;