kuzzle-logger 1.4.0 → 1.5.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +142 -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,142 @@
1
+ import { isErrorLike } from '../serializeError.js';
2
+ import { withoutConsoleMirroring } from './KuzzleLogger.js';
3
+ // Above this many distinct errors, expired deduplication keys are pruned
4
+ const MAX_DEDUPE_KEYS = 100;
5
+ /**
6
+ * Logs uncaught errors and unhandled promise rejections (`window` `error` and
7
+ * `unhandledrejection` events) at the error level. Opt-in: errors should be pushed
8
+ * explicitly where they are handled.
9
+ *
10
+ * The events are not cancelled, so the browser still prints them to the console,
11
+ * and the logger does not print them a second time.
12
+ *
13
+ * Returns a function that removes the listeners.
14
+ *
15
+ * @example
16
+ * const stop = captureGlobalErrors(logger.child('global'));
17
+ */
18
+ export function captureGlobalErrors(logger, options = {}) {
19
+ const target = options.target ?? (typeof window === 'undefined' ? undefined : window);
20
+ if (!target || typeof target.addEventListener !== 'function') {
21
+ return () => { };
22
+ }
23
+ const dedupeInterval = options.dedupeInterval ?? 5000;
24
+ const lastSeen = new Map();
25
+ const isDuplicate = (key) => {
26
+ const now = Date.now();
27
+ const previous = lastSeen.get(key);
28
+ if (previous !== undefined && now - previous < dedupeInterval) {
29
+ return true;
30
+ }
31
+ if (lastSeen.size >= MAX_DEDUPE_KEYS) {
32
+ for (const [seenKey, time] of lastSeen) {
33
+ if (now - time >= dedupeInterval) {
34
+ lastSeen.delete(seenKey);
35
+ }
36
+ }
37
+ }
38
+ lastSeen.set(key, now);
39
+ return false;
40
+ };
41
+ const onError = (event) => {
42
+ const { colno, error, filename, lineno, message } = event;
43
+ // Safari gives "undefined" for code evaluated in the devtools console
44
+ const location = filename && filename !== 'undefined'
45
+ ? { column: colno, file: filename, line: lineno }
46
+ : undefined;
47
+ const text = isErrorLike(error) ? error.message : (message ?? String(error));
48
+ const key = [
49
+ 'error',
50
+ isErrorLike(error) ? error.name : '',
51
+ text,
52
+ location ? `${filename}:${lineno}:${colno}` : '',
53
+ ].join('\n');
54
+ if (isDuplicate(key)) {
55
+ return;
56
+ }
57
+ // Cross-origin scripts only give "Script error." and no error object
58
+ const fields = error === undefined || error === null ? {} : errorFields(error);
59
+ withoutConsoleMirroring(() => {
60
+ logger.error({ ...fields, event: 'error', ...(location && { location }) }, `Uncaught error: ${text}`);
61
+ });
62
+ };
63
+ const onRejection = (event) => {
64
+ const { reason } = event;
65
+ const text = isErrorLike(reason) ? reason.message : describe(reason);
66
+ const key = ['unhandledrejection', isErrorLike(reason) ? reason.name : '', text].join('\n');
67
+ if (isDuplicate(key)) {
68
+ return;
69
+ }
70
+ withoutConsoleMirroring(() => {
71
+ logger.error({ ...errorFields(reason), event: 'unhandledrejection' }, `Unhandled rejection: ${text}`);
72
+ });
73
+ };
74
+ target.addEventListener('error', onError);
75
+ target.addEventListener('unhandledrejection', onRejection);
76
+ return () => {
77
+ target.removeEventListener('error', onError);
78
+ target.removeEventListener('unhandledrejection', onRejection);
79
+ };
80
+ }
81
+ /**
82
+ * Returns an error handler that logs Vue errors at the error level, with the
83
+ * component name and the Vue `info` string (e.g. "setup function", "render function").
84
+ *
85
+ * Vue no longer prints errors when an error handler is set: this handler prints
86
+ * them with `console.error`, like Vue does in production.
87
+ *
88
+ * It does not depend on `vue`.
89
+ *
90
+ * @example
91
+ * app.config.errorHandler = createVueErrorHandler(logger.child('vue'));
92
+ */
93
+ export function createVueErrorHandler(logger) {
94
+ return (err, instance, info) => {
95
+ try {
96
+ const context = { ...errorFields(err), info };
97
+ const component = componentName(instance);
98
+ if (component) {
99
+ context.component = component;
100
+ }
101
+ const text = isErrorLike(err) ? err.message : describe(err);
102
+ withoutConsoleMirroring(() => {
103
+ logger.error(context, `Vue error in ${info}: ${text}`);
104
+ });
105
+ }
106
+ catch {
107
+ // Logging must never break the application
108
+ }
109
+ try {
110
+ globalThis.console?.error?.(err);
111
+ }
112
+ catch {
113
+ // Same as above
114
+ }
115
+ };
116
+ }
117
+ function errorFields(value) {
118
+ return isErrorLike(value) ? { err: value } : { reason: value };
119
+ }
120
+ function describe(value) {
121
+ if (typeof value === 'string') {
122
+ return value;
123
+ }
124
+ try {
125
+ return JSON.stringify(value) ?? String(value);
126
+ }
127
+ catch {
128
+ return String(value);
129
+ }
130
+ }
131
+ /**
132
+ * Name of a Vue 3 (options, `<script setup>`) or Vue 2 component instance.
133
+ */
134
+ function componentName(instance) {
135
+ if (typeof instance !== 'object' || instance === null) {
136
+ return undefined;
137
+ }
138
+ const options = instance.$options;
139
+ const name = options?.name ?? options?.__name ?? options?._componentTag;
140
+ return typeof name === 'string' && name.length > 0 ? name : undefined;
141
+ }
142
+ //# sourceMappingURL=capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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KAAK,CAAC,CAAC;IACvB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,QAAiB;IACtC,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,OAAO,GAAI,QAAmD,CAAC,QAAQ,CAAC;IAC9E,MAAM,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,aAAa,CAAC;IAExE,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AACxE,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Browser entry point: "kuzzle-logger/browser".
3
+ *
4
+ * ESM only. It must not import Node built-ins, pino transports, or any module
5
+ * outside src/browser, src/protocol and src/types.
6
+ */
7
+ export { BROWSER_LOG_LEVELS, PAYLOAD_VERSION } from '../protocol/payload.js';
8
+ export type { BrowserLogEntry, BrowserLogError, BrowserLogLevel, BrowserLogsApp, BrowserLogsPayload, } from '../protocol/payload.js';
9
+ export { KuzzleLogger } from './KuzzleLogger.js';
10
+ export type { BrowserKuzzleLoggerConfig, BrowserLoggerLevel, BrowserLogSender, } from './KuzzleLogger.js';
11
+ export { NonRetryableError, createBatchingSender } from './batchingSender.js';
12
+ export type { BatchTransport, BatchingOptions, BatchingSender, TransportOptions, } from './batchingSender.js';
13
+ export { createHttpSender, createKuzzleSender } from './senders.js';
14
+ export type { HttpSenderOptions, KuzzleSdkLike, KuzzleSenderOptions } from './senders.js';
15
+ export { captureGlobalErrors, createVueErrorHandler } from './capture.js';
16
+ export type { CaptureGlobalErrorsOptions, VueErrorHandler } from './capture.js';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Browser entry point: "kuzzle-logger/browser".
3
+ *
4
+ * ESM only. It must not import Node built-ins, pino transports, or any module
5
+ * outside src/browser, src/protocol and src/types.
6
+ */
7
+ export { BROWSER_LOG_LEVELS, PAYLOAD_VERSION } from '../protocol/payload.js';
8
+ export { KuzzleLogger } from './KuzzleLogger.js';
9
+ export { NonRetryableError, createBatchingSender } from './batchingSender.js';
10
+ export { createHttpSender, createKuzzleSender } from './senders.js';
11
+ export { captureGlobalErrors, createVueErrorHandler } from './capture.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAQ7E,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAMjD,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAO9E,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEpE,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { BrowserLogsPayload } from '../protocol/payload.js';
2
+ import { BatchingOptions, BatchingSender } from './batchingSender.js';
3
+ export type HttpSenderOptions = BatchingOptions & {
4
+ /**
5
+ * Extra request headers (e.g. "Authorization"), or a function returning them for
6
+ * each request.
7
+ */
8
+ headers?: Record<string, string> | (() => Record<string, string>);
9
+ /**
10
+ * Endpoint receiving the batches.
11
+ * @default "/_/browser-logs/_push" (the Kuzzle HTTP route, on the same origin)
12
+ */
13
+ url?: string;
14
+ };
15
+ /**
16
+ * Structural subset of a Kuzzle SDK instance (no dependency on "kuzzle-sdk").
17
+ */
18
+ export type KuzzleSdkLike = {
19
+ /**
20
+ * Authentication token, sent with keepalive requests (see "keepaliveUrl").
21
+ */
22
+ jwt?: string | null;
23
+ query(request: {
24
+ action: string;
25
+ body: BrowserLogsPayload;
26
+ controller: string;
27
+ }): Promise<unknown>;
28
+ };
29
+ export type KuzzleSenderOptions = BatchingOptions & {
30
+ /**
31
+ * @default "push"
32
+ */
33
+ action?: string;
34
+ /**
35
+ * @default "browser-logs"
36
+ */
37
+ controller?: string;
38
+ /**
39
+ * HTTP route of the action (e.g. "https://api.example.com/_/browser-logs/_push").
40
+ * When set, batches sent while the page is hidden use fetch with "keepalive" and
41
+ * the SDK token, since an SDK request may not survive the page unload.
42
+ */
43
+ keepaliveUrl?: string;
44
+ };
45
+ /**
46
+ * Batching sender posting payloads with fetch.
47
+ * 4xx responses (except 408 and 429) are not retried.
48
+ */
49
+ export declare function createHttpSender(options?: HttpSenderOptions): BatchingSender;
50
+ /**
51
+ * Batching sender using an existing Kuzzle SDK instance ("sdk.query"), which sends
52
+ * the SDK authentication token.
53
+ */
54
+ export declare function createKuzzleSender(sdk: KuzzleSdkLike, options?: KuzzleSenderOptions): BatchingSender;
@@ -0,0 +1,57 @@
1
+ import { NonRetryableError, createBatchingSender, } from './batchingSender.js';
2
+ /**
3
+ * Batching sender posting payloads with fetch.
4
+ * 4xx responses (except 408 and 429) are not retried.
5
+ */
6
+ export function createHttpSender(options = {}) {
7
+ const url = options.url ?? '/_/browser-logs/_push';
8
+ return createBatchingSender((payload, transportOptions) => post(url, payload, transportOptions, resolveHeaders(options.headers)), options);
9
+ }
10
+ /**
11
+ * Batching sender using an existing Kuzzle SDK instance ("sdk.query"), which sends
12
+ * the SDK authentication token.
13
+ */
14
+ export function createKuzzleSender(sdk, options = {}) {
15
+ const controller = options.controller ?? 'browser-logs';
16
+ const action = options.action ?? 'push';
17
+ return createBatchingSender(async (payload, transportOptions) => {
18
+ if (transportOptions.keepalive && options.keepaliveUrl) {
19
+ const headers = sdk.jwt ? { Authorization: `Bearer ${sdk.jwt}` } : {};
20
+ return post(options.keepaliveUrl, payload, transportOptions, headers);
21
+ }
22
+ try {
23
+ await sdk.query({ action, body: payload, controller });
24
+ }
25
+ catch (error) {
26
+ const status = error?.status;
27
+ if (typeof status === 'number' && !isRetryableStatus(status)) {
28
+ throw new NonRetryableError(`browser logs rejected (${status})`);
29
+ }
30
+ throw error;
31
+ }
32
+ }, options);
33
+ }
34
+ async function post(url, payload, { keepalive }, headers) {
35
+ const response = await fetch(url, {
36
+ body: JSON.stringify(payload),
37
+ headers: { ...headers, 'Content-Type': 'application/json' },
38
+ keepalive,
39
+ method: 'POST',
40
+ });
41
+ if (!response.ok) {
42
+ const message = `browser logs rejected (${response.status})`;
43
+ throw isRetryableStatus(response.status) ? new Error(message) : new NonRetryableError(message);
44
+ }
45
+ }
46
+ function resolveHeaders(headers) {
47
+ try {
48
+ return (typeof headers === 'function' ? headers() : headers) ?? {};
49
+ }
50
+ catch {
51
+ return {};
52
+ }
53
+ }
54
+ function isRetryableStatus(status) {
55
+ return status < 400 || status >= 500 || status === 408 || status === 429;
56
+ }
57
+ //# sourceMappingURL=senders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"senders.js","sourceRoot":"","sources":["../../../src/browser/senders.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,iBAAiB,EAEjB,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AA+C7B;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAA6B,EAAE;IAC9D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,uBAAuB,CAAC;IAEnD,OAAO,oBAAoB,CACzB,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,CAC5B,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,gBAAgB,EAAE,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EACvE,OAAO,CACR,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,GAAkB,EAClB,UAA+B,EAAE;IAEjC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,cAAc,CAAC;IACxD,MAAM,MAAM,GAAG,OAAO,CAA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,EAAE,CAAC;QACjB,MAAM,OAAO,GAAG,0BAA0B,QAAQ,CAAC,MAAM,GAAG,CAAC;QAE7D,MAAM,iBAAiB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACjG,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,OAAqC;IAC3D,IAAI,CAAC;QACH,OAAO,CAAC,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IACrE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAc;IACvC,OAAO,MAAM,GAAG,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,4 @@
1
+ {
2
+ "sideEffects": false,
3
+ "type": "module"
4
+ }
@@ -0,0 +1,60 @@
1
+ import { JSONObject } from '../types/JSONObject.js';
2
+ /**
3
+ * Version of the browser logs wire format.
4
+ */
5
+ export declare const PAYLOAD_VERSION = 1;
6
+ /**
7
+ * Levels a browser entry can be logged with.
8
+ */
9
+ export declare const BROWSER_LOG_LEVELS: readonly ["trace", "debug", "info", "warn", "error", "fatal"];
10
+ export type BrowserLogLevel = (typeof BROWSER_LOG_LEVELS)[number];
11
+ /**
12
+ * An error serialized by the browser logger.
13
+ */
14
+ export type BrowserLogError = {
15
+ [key: string]: unknown;
16
+ cause?: unknown;
17
+ message: string;
18
+ name: string;
19
+ stack?: string;
20
+ };
21
+ /**
22
+ * A single log entry, as sent by the browser.
23
+ */
24
+ export type BrowserLogEntry = {
25
+ /**
26
+ * Arbitrary data attached to the entry. Must be a plain JSON object.
27
+ */
28
+ context?: JSONObject;
29
+ err?: BrowserLogError;
30
+ level: BrowserLogLevel;
31
+ msg?: string;
32
+ /**
33
+ * Appended to the server-side namespace (e.g. "dashboard:map").
34
+ */
35
+ namespace?: string;
36
+ /**
37
+ * Client epoch, in milliseconds. Informational only: stored as "clientTime".
38
+ */
39
+ time?: number;
40
+ };
41
+ /**
42
+ * Optional, informational description of the frontend application.
43
+ */
44
+ export type BrowserLogsApp = {
45
+ name?: string;
46
+ version?: string;
47
+ };
48
+ /**
49
+ * A batch of browser log entries (payload v1).
50
+ */
51
+ export type BrowserLogsPayload = {
52
+ app?: BrowserLogsApp;
53
+ /**
54
+ * Number of entries dropped by the browser since the previous batch
55
+ * (bounded buffer overflow).
56
+ */
57
+ dropped?: number;
58
+ entries: BrowserLogEntry[];
59
+ version: typeof PAYLOAD_VERSION;
60
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Version of the browser logs wire format.
3
+ */
4
+ export const PAYLOAD_VERSION = 1;
5
+ /**
6
+ * Levels a browser entry can be logged with.
7
+ */
8
+ export const BROWSER_LOG_LEVELS = ['trace', 'debug', 'info', 'warn', 'error', 'fatal'];
9
+ //# sourceMappingURL=payload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payload.js","sourceRoot":"","sources":["../../../src/protocol/payload.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AAEjC;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAU,CAAC"}
@@ -0,0 +1,27 @@
1
+ export type SerializedError = {
2
+ [key: string]: unknown;
3
+ cause?: unknown;
4
+ errors?: unknown[];
5
+ message: string;
6
+ name: string;
7
+ stack?: string;
8
+ };
9
+ /**
10
+ * Returns true for Error instances, and for objects that look like errors
11
+ * (e.g. errors coming from another realm).
12
+ */
13
+ export declare function isErrorLike(value: unknown): value is Error;
14
+ /**
15
+ * Serializes an error into a plain JSON object: name, message, stack, cause,
16
+ * aggregated errors and custom enumerable properties (e.g. KuzzleError id, code, status).
17
+ *
18
+ * Non-error values are returned unchanged, so it can be used as a pino serializer.
19
+ */
20
+ export declare function serializeError(value: unknown): unknown;
21
+ /**
22
+ * pino serializers applied to the "err" and "error" keys of logged objects.
23
+ */
24
+ export declare const errorSerializers: {
25
+ err: typeof serializeError;
26
+ error: typeof serializeError;
27
+ };
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Returns true for Error instances, and for objects that look like errors
3
+ * (e.g. errors coming from another realm).
4
+ */
5
+ export function isErrorLike(value) {
6
+ if (value instanceof Error) {
7
+ return true;
8
+ }
9
+ return (typeof value === 'object' &&
10
+ value !== null &&
11
+ typeof value.message === 'string' &&
12
+ typeof value.stack === 'string');
13
+ }
14
+ /**
15
+ * Serializes an error into a plain JSON object: name, message, stack, cause,
16
+ * aggregated errors and custom enumerable properties (e.g. KuzzleError id, code, status).
17
+ *
18
+ * Non-error values are returned unchanged, so it can be used as a pino serializer.
19
+ */
20
+ export function serializeError(value) {
21
+ return serializeValue(value, new Set());
22
+ }
23
+ function serializeValue(value, ancestors) {
24
+ if (!isErrorLike(value)) {
25
+ return value;
26
+ }
27
+ if (ancestors.has(value)) {
28
+ return '[Circular]';
29
+ }
30
+ ancestors.add(value);
31
+ const serialized = {
32
+ message: value.message,
33
+ name: typeof value.name === 'string' ? value.name : 'Error',
34
+ };
35
+ if (typeof value.stack === 'string') {
36
+ serialized.stack = value.stack;
37
+ }
38
+ // "cause" and AggregateError "errors" are not enumerable
39
+ if (value.cause !== undefined) {
40
+ serialized.cause = serializeValue(value.cause, ancestors);
41
+ }
42
+ const errors = value.errors;
43
+ if (Array.isArray(errors)) {
44
+ serialized.errors = errors.map((err) => serializeValue(err, ancestors));
45
+ }
46
+ for (const key in value) {
47
+ if (!(key in serialized)) {
48
+ serialized[key] = serializeValue(value[key], ancestors);
49
+ }
50
+ }
51
+ ancestors.delete(value);
52
+ return serialized;
53
+ }
54
+ /**
55
+ * pino serializers applied to the "err" and "error" keys of logged objects.
56
+ */
57
+ export const errorSerializers = {
58
+ err: serializeError,
59
+ error: serializeError,
60
+ };
61
+ //# sourceMappingURL=serializeError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serializeError.js","sourceRoot":"","sources":["../../src/serializeError.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAQ,KAAe,CAAC,OAAO,KAAK,QAAQ;QAC5C,OAAQ,KAAe,CAAC,KAAK,KAAK,QAAQ,CAC3C,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,cAAc,CAAC,KAAK,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,cAAc,CAAC,KAAc,EAAE,SAAsB;IAC5D,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAErB,MAAM,UAAU,GAAoB;QAClC,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,IAAI,EAAE,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO;KAC5D,CAAC;IAEF,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QACpC,UAAU,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IACjC,CAAC;IAED,yDAAyD;IACzD,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC9B,UAAU,CAAC,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,MAAM,GAAI,KAA8B,CAAC,MAAM,CAAC;IACtD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,CAAC,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC;YACzB,UAAU,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,GAAkB,CAAC,EAAE,SAAS,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;IAED,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAExB,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,GAAG,EAAE,cAAc;IACnB,KAAK,EAAE,cAAc;CACtB,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * A plain JSON object.
3
+ */
4
+ export type JSONObject = {
5
+ [key: string]: any;
6
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=JSONObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JSONObject.js","sourceRoot":"","sources":["../../../src/types/JSONObject.ts"],"names":[],"mappings":""}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './KuzzleLogger';
2
2
  export * from './types/KuzzleLoggerConfig';
3
3
  export * from './types/KuzzleLoggerPresets';
4
+ export * from './types/JSONObject';
package/dist/index.js CHANGED
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./KuzzleLogger"), exports);
18
18
  __exportStar(require("./types/KuzzleLoggerConfig"), exports);
19
19
  __exportStar(require("./types/KuzzleLoggerPresets"), exports);
20
+ __exportStar(require("./types/JSONObject"), exports);
20
21
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,6DAA2C;AAC3C,8DAA4C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,6DAA2C;AAC3C,8DAA4C;AAC5C,qDAAmC"}
@@ -0,0 +1,111 @@
1
+ import { BrowserLogLevel } from '../protocol/payload';
2
+ import { SanitizeOptions } from '../protocol/sanitize';
3
+ import { BatchLimits, RejectedEntry } from '../protocol/validateBatch';
4
+ import { JSONObject } from '../types/JSONObject';
5
+ /**
6
+ * Logger the browser logs are forwarded to. Structurally typed:
7
+ * a KuzzleLogger, or Kuzzle's "app.log", fits.
8
+ */
9
+ export type BrowserLogsTargetLogger = {
10
+ [level in BrowserLogLevel]: (obj: object, msg?: string) => void;
11
+ } & {
12
+ child(namespace: string): BrowserLogsTargetLogger;
13
+ };
14
+ /**
15
+ * The subset of a KuzzleRequest used by the controller (no runtime import of "kuzzle").
16
+ */
17
+ export type BrowserLogsRequest = {
18
+ context?: {
19
+ connection?: {
20
+ misc?: {
21
+ headers?: JSONObject;
22
+ };
23
+ };
24
+ };
25
+ getKuid(): string | null;
26
+ input: {
27
+ body: unknown;
28
+ };
29
+ };
30
+ export type BrowserLogsControllerOptions = {
31
+ /**
32
+ * Name of the action.
33
+ * @default "push"
34
+ */
35
+ action?: string;
36
+ /**
37
+ * Builds the error thrown for an invalid batch. Kuzzle only answers with the error
38
+ * status when it is a KuzzleError, so pass `(message) => new BadRequestError(message)`
39
+ * (from "kuzzle") to answer with a 400 instead of a 500.
40
+ */
41
+ badRequest?: (message: string) => Error;
42
+ /**
43
+ * HTTP route of the action. Kuzzle prefixes relative paths with "/_/".
44
+ * `null` disables the HTTP route.
45
+ * @default "browser-logs/_push" (i.e. POST /_/browser-logs/_push)
46
+ */
47
+ httpPath?: string | null;
48
+ /**
49
+ * Batch limits, see validateBatch.
50
+ */
51
+ limits?: BatchLimits;
52
+ /**
53
+ * Maximum number of distinct client namespaces appended to the server-side
54
+ * namespace. Since the namespace can be a transport label (e.g. Loki), this bounds
55
+ * the cardinality a client can create: entries with other namespaces are logged
56
+ * under the base namespace, with their namespace in the "clientNamespace" field.
57
+ * @default 50
58
+ */
59
+ maxNamespaces?: number;
60
+ /**
61
+ * Namespace of the child logger the entries are forwarded to.
62
+ * @default "browser"
63
+ */
64
+ namespace?: string;
65
+ /**
66
+ * Sanitization options, see sanitize.
67
+ */
68
+ sanitize?: SanitizeOptions;
69
+ };
70
+ export type BrowserLogsPushResult = {
71
+ accepted: number;
72
+ rejected: RejectedEntry[];
73
+ };
74
+ /**
75
+ * Structural equivalent of Kuzzle's ControllerDefinition.
76
+ */
77
+ export type BrowserLogsControllerDefinition = {
78
+ actions: {
79
+ [action: string]: {
80
+ handler: (request: BrowserLogsRequest) => Promise<BrowserLogsPushResult>;
81
+ http?: {
82
+ path: string;
83
+ verb: 'post';
84
+ }[];
85
+ };
86
+ };
87
+ };
88
+ /**
89
+ * Creates a Kuzzle controller ingesting browser logs (payload v1) and forwarding them
90
+ * through a child of the given logger, i.e. with its transports and labels.
91
+ *
92
+ * Every entry is validated, sanitized and enriched server-side: "source", "userId",
93
+ * "userAgent", "origin", "clientTime" and "fingerprint". The client never sets labels.
94
+ *
95
+ * Rights: grant the action to the roles allowed to send browser logs, e.g.
96
+ * `{ controllers: { 'browser-logs': { actions: { push: true } } } }`. Add it to the
97
+ * "anonymous" role to accept logs from users who are not logged in, and rely on the
98
+ * profiles rate limits to protect the backend.
99
+ *
100
+ * @example
101
+ * import { BadRequestError } from 'kuzzle';
102
+ * import { createBrowserLogsController } from 'kuzzle-logger/kuzzle';
103
+ *
104
+ * app.controller.register(
105
+ * 'browser-logs',
106
+ * createBrowserLogsController(app.log, {
107
+ * badRequest: (message) => new BadRequestError(message),
108
+ * }),
109
+ * );
110
+ */
111
+ export declare function createBrowserLogsController(logger: BrowserLogsTargetLogger, options?: BrowserLogsControllerOptions): BrowserLogsControllerDefinition;