@devbie/frontend-monitor-sdk 0.0.0-stage → 1.7.0

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/README.md CHANGED
@@ -1,3 +1,187 @@
1
- # Temporary Holding Version
1
+ # @devbie/frontend-monitor-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm version](https://img.shields.io/npm/v/@devbie/frontend-monitor-sdk?style=flat-square)](https://www.npmjs.com/package/@devbie/frontend-monitor-sdk)
4
+ [![license](https://img.shields.io/npm/l/@devbie/frontend-monitor-sdk?style=flat-square)](https://github.com/worldzhy/devbie/blob/dev/LICENSE)
5
+
6
+ Browser-side web monitoring SDK. It automatically collects page-view and page
7
+ performance data, AJAX calls (both `XMLHttpRequest` and `fetch`), resource
8
+ loading, JavaScript errors and custom events, and reports them to a collector
9
+ endpoint. The SDK handles monitoring only — no heartbeat and no credential
10
+ logic.
11
+
12
+ ## Features
13
+
14
+ - **Page performance** — load timing, first-entry metadata, screen size,
15
+ referrer and performance entries.
16
+ - **AJAX monitoring** — transparently instruments `XMLHttpRequest` and
17
+ `fetch`, recording method, URL, status, response size, timing and optional
18
+ trace ID.
19
+ - **Resource monitoring** — slow and failed resource loads via
20
+ `PerformanceObserver` and resource `error` events.
21
+ - **Error monitoring** — `window.onerror`, `unhandledrejection`, resource load
22
+ failures and `console.error`, with parsed stack traces.
23
+ - **Custom events** — report business events with throttled batching.
24
+ - **Business error codes** — plug in an `errcodeReport` resolver to flag
25
+ business-level failures inside HTTP 200 responses.
26
+ - **Anonymous identity** — per-user, per-page, unique-visitor and device marks
27
+ generated in the browser.
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ npm install @devbie/frontend-monitor-sdk
33
+ ```
34
+
35
+ ## Quick start
36
+
37
+ Initialize the SDK as early as possible in your application — for example in
38
+ your root layout or application entry:
39
+
40
+ ```ts
41
+ import init from "@devbie/frontend-monitor-sdk";
42
+
43
+ init({
44
+ api: "https://collector.example.com/api/web-monitor/report",
45
+ token: "<report token>",
46
+ });
47
+ ```
48
+
49
+ The `init` call returns helper functions for manual reporting:
50
+
51
+ ```ts
52
+ const monitor = init({
53
+ api: "https://collector.example.com/api/web-monitor/report",
54
+ token: "<report token>",
55
+ });
56
+
57
+ monitor.addCustom({
58
+ customName: "checkout",
59
+ customContent: { orderId: "1001", amount: 99 },
60
+ });
61
+ ```
62
+
63
+ ### Use with Next.js
64
+
65
+ The Fewbie framework ships a ready-made registry wrapper:
66
+
67
+ ```bash
68
+ npx @devbie/fewbie-cli add frontend-monitor-sdk
69
+ ```
70
+
71
+ Then add the scaffolded `<WebMonitor />` component to your root layout and
72
+ configure `NEXT_PUBLIC_WEB_MONITOR_ENDPOINT` and `NEXT_PUBLIC_WEB_MONITOR_TOKEN`.
73
+ The component is a no-op until both environment variables are present.
74
+
75
+ ## Init options
76
+
77
+ | Option | Type | Default | Required | Description |
78
+ | ------------------- | ---------- | ------------ | -------- | --------------------------------------------------------------------------------------------------------------------------------- |
79
+ | `api` | `string` | — | Yes | Collector endpoint that receives report payloads. |
80
+ | `token` | `string` | — | Yes | Report token issued for the deployment; the collector resolves it to the application partition. |
81
+ | `isPage` | `boolean` | `true` | No | Collect page-view / page performance data. |
82
+ | `isAjax` | `boolean` | `true` | No | Instrument XHR and `fetch` requests. |
83
+ | `isResource` | `boolean` | `true` | No | Collect resource timing and slow/failed resources. |
84
+ | `isError` | `boolean` | `true` | No | Collect JS errors, rejections, resource errors and console errors. |
85
+ | `filterUrls` | `string[]` | `[]` | No | URLs excluded from AJAX/resource collection. The collector endpoint (`/api/web-monitor/report`) is always filtered automatically. |
86
+ | `user` | `object` | `{}` | No | Initial user identity: `{ uid?, p? }` (`p` should be pre-encrypted). |
87
+ | `isTraceId` | `boolean` | `false` | No | Capture the trace ID response header from AJAX calls. |
88
+ | `traceIdHeaderName` | `string` | `x-trace-id` | No | Response header name to read when `isTraceId` is enabled. |
89
+ | `customsThrottleMs` | `number` | `1000` | No | Throttle window for batching custom events, in milliseconds. |
90
+ | `errcodeReport` | `function` | — | No | Business error resolver, see below. |
91
+
92
+ ## Returned API
93
+
94
+ `init()` returns an object with the following members:
95
+
96
+ ### `addError(error)`
97
+
98
+ Manually push a script error for immediate reporting:
99
+
100
+ ```ts
101
+ monitor.addError({
102
+ msg: "Something went wrong",
103
+ line: 42,
104
+ col: 10,
105
+ resourceUrl: "https://example.com/app.js",
106
+ });
107
+ ```
108
+
109
+ ### `addCustom(event)`
110
+
111
+ Queue a custom event. Object content is serialized to JSON; queued events are
112
+ flushed (and batched) after `customsThrottleMs`:
113
+
114
+ ```ts
115
+ monitor.addCustom({
116
+ customName: "button-click",
117
+ customContent: "pay-now",
118
+ customFilter: { page: "checkout" }, // optional, must be an object
119
+ });
120
+ ```
121
+
122
+ ### `setConfig(config)`
123
+
124
+ Update the user identity after initialization. When `p` is supplied it is
125
+ encrypted before storage:
126
+
127
+ ```ts
128
+ monitor.setConfig({ uid: "10086", p: "plain-text-secret" });
129
+ ```
130
+
131
+ ## Business error reporting
132
+
133
+ HTTP 200 responses can still represent business failures. Provide an
134
+ `errcodeReport` resolver to inspect parsed response data and decide whether to
135
+ report an error:
136
+
137
+ ```ts
138
+ init({
139
+ api: "https://collector.example.com/api/web-monitor/report",
140
+ token: "<report token>",
141
+ errcodeReport: (responseData) => {
142
+ return {
143
+ isReport: responseData.code !== 0,
144
+ errMsg: responseData.message,
145
+ code: responseData.code,
146
+ };
147
+ },
148
+ });
149
+ ```
150
+
151
+ ## Report types and transport
152
+
153
+ Reports carry one of the following types:
154
+
155
+ | Type | Content |
156
+ | ---------- | ----------------------------------------------------- |
157
+ | `PagePerf` | Page performance, resources and errors on navigation. |
158
+ | `AjaxPerf` | AJAX activity and errors between page reports. |
159
+ | `Error` | Errors captured immediately (debounced). |
160
+ | `Custom` | Batched custom events. |
161
+ | `Unload` | Final report on page unload. |
162
+ | `SdkError` | Errors thrown inside the SDK itself. |
163
+
164
+ Payloads are POSTed with `Content-Type: text/plain` via `fetch` (so monitoring
165
+ requests are never re-instrumented), and the final `Unload` report uses
166
+ `navigator.sendBeacon` when available. If the collector becomes unreachable,
167
+ reporting is paused to avoid request storms.
168
+
169
+ ## Global access
170
+
171
+ For integrations that cannot import the module directly, the default
172
+ initializer is also exposed on the browser as `window._frontendMonitor`.
173
+
174
+ ## Related packages
175
+
176
+ - [`@devbie/heartbeat-sdk`](https://www.npmjs.com/package/@devbie/heartbeat-sdk)
177
+ — server-side installation liveness reporting.
178
+ - [`@devbie/newbie`](https://www.npmjs.com/package/@devbie/newbie) — Newbie
179
+ backend framework runtime.
180
+ - [`@devbie/newbie-cli`](https://www.npmjs.com/package/@devbie/newbie-cli) —
181
+ Newbie framework command-line tool.
182
+ - [`@devbie/fewbie-cli`](https://www.npmjs.com/package/@devbie/fewbie-cli) —
183
+ install the web-monitor wrapper component in Next.js projects.
184
+
185
+ ## License
186
+
187
+ [MIT](https://github.com/worldzhy/devbie/blob/dev/LICENSE)
@@ -0,0 +1,15 @@
1
+ export interface StackFrame {
2
+ url: string;
3
+ func: string;
4
+ args: string[];
5
+ line: number | null;
6
+ column: number | null;
7
+ }
8
+ export interface StackTrace {
9
+ name: string;
10
+ message: string;
11
+ mechanism?: string;
12
+ stack: StackFrame[];
13
+ failed?: boolean;
14
+ }
15
+ export declare function computeStackTrace(ex: any): StackTrace;
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeStackTrace = computeStackTrace;
4
+ const UNKNOWN_FUNCTION = "?";
5
+ const chrome = /^\s*at (?:(.*?) ?\()?((?:file|https?|blob|chrome-extension|address|native|eval|webpack|<anonymous>|[-a-z]+:|.*bundle|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
6
+ const gecko = /^\s*(?:(.*?)(?:\((.*?)\))?@|)((?:file|https?|blob|webpack|resource|moz-extension|capacitor).*?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. /=]+)(?::(\d+))?(?::(\d+))?\s*$/i;
7
+ const winjs = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
8
+ const geckoEval = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
9
+ const chromeEval = /\((\S*)(?::(\d+))(?::(\d+))\)/;
10
+ const reactMinifiedRegexp = /Minified React error #\d+;/i;
11
+ function computeStackTrace(ex) {
12
+ let stack = null;
13
+ let popSize = 0;
14
+ if (ex) {
15
+ if (typeof ex.framesToPop === "number") {
16
+ popSize = ex.framesToPop;
17
+ }
18
+ else if (reactMinifiedRegexp.test(ex.message)) {
19
+ popSize = 1;
20
+ }
21
+ }
22
+ try {
23
+ stack = computeStackTraceFromStacktraceProp(ex);
24
+ if (stack) {
25
+ return popFrames(stack, popSize);
26
+ }
27
+ }
28
+ catch {
29
+ }
30
+ try {
31
+ stack = computeStackTraceFromStackProp(ex);
32
+ if (stack) {
33
+ return popFrames(stack, popSize);
34
+ }
35
+ }
36
+ catch {
37
+ }
38
+ return {
39
+ message: extractMessage(ex),
40
+ name: ex && ex.name,
41
+ stack: [],
42
+ failed: true,
43
+ };
44
+ }
45
+ function computeStackTraceFromStackProp(ex) {
46
+ if (!ex || !ex.stack) {
47
+ return null;
48
+ }
49
+ const stack = [];
50
+ const lines = ex.stack.split("\n");
51
+ let isEval;
52
+ let submatch;
53
+ let parts;
54
+ let element;
55
+ for (let i = 0; i < lines.length; ++i) {
56
+ if ((parts = chrome.exec(lines[i]))) {
57
+ const isNative = parts[2] && parts[2].indexOf("native") === 0;
58
+ isEval = parts[2] && parts[2].indexOf("eval") === 0;
59
+ if (isEval && (submatch = chromeEval.exec(parts[2]))) {
60
+ parts[2] = submatch[1];
61
+ parts[3] = submatch[2];
62
+ parts[4] = submatch[3];
63
+ }
64
+ element = {
65
+ url: parts[2] && parts[2].indexOf("address at ") === 0 ? parts[2].substr("address at ".length) : parts[2],
66
+ func: parts[1] || UNKNOWN_FUNCTION,
67
+ args: isNative ? [parts[2]] : [],
68
+ line: parts[3] ? +parts[3] : null,
69
+ column: parts[4] ? +parts[4] : null,
70
+ };
71
+ }
72
+ else if ((parts = winjs.exec(lines[i]))) {
73
+ element = {
74
+ url: parts[2],
75
+ func: parts[1] || UNKNOWN_FUNCTION,
76
+ args: [],
77
+ line: +parts[3],
78
+ column: parts[4] ? +parts[4] : null,
79
+ };
80
+ }
81
+ else if ((parts = gecko.exec(lines[i]))) {
82
+ isEval = parts[3] && parts[3].indexOf(" > eval") > -1;
83
+ if (isEval && (submatch = geckoEval.exec(parts[3]))) {
84
+ parts[1] = parts[1] || `eval`;
85
+ parts[3] = submatch[1];
86
+ parts[4] = submatch[2];
87
+ parts[5] = "";
88
+ }
89
+ else if (i === 0 && !parts[5] && ex.columnNumber !== void 0) {
90
+ stack[0].column = ex.columnNumber + 1;
91
+ }
92
+ element = {
93
+ url: parts[3],
94
+ func: parts[1] || UNKNOWN_FUNCTION,
95
+ args: parts[2] ? parts[2].split(",") : [],
96
+ line: parts[4] ? +parts[4] : null,
97
+ column: parts[5] ? +parts[5] : null,
98
+ };
99
+ }
100
+ else {
101
+ continue;
102
+ }
103
+ if (!element.func && element.line) {
104
+ element.func = UNKNOWN_FUNCTION;
105
+ }
106
+ stack.push(element);
107
+ }
108
+ if (!stack.length) {
109
+ return null;
110
+ }
111
+ return {
112
+ message: extractMessage(ex),
113
+ name: ex.name,
114
+ stack,
115
+ };
116
+ }
117
+ function computeStackTraceFromStacktraceProp(ex) {
118
+ if (!ex || !ex.stacktrace) {
119
+ return null;
120
+ }
121
+ const stacktrace = ex.stacktrace;
122
+ const opera10Regex = / line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i;
123
+ const opera11Regex = / line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^)]+))\((.*)\))? in (.*):\s*$/i;
124
+ const lines = stacktrace.split("\n");
125
+ const stack = [];
126
+ let parts;
127
+ for (let line = 0; line < lines.length; line += 2) {
128
+ let element = null;
129
+ if ((parts = opera10Regex.exec(lines[line]))) {
130
+ element = {
131
+ url: parts[2],
132
+ func: parts[3],
133
+ args: [],
134
+ line: +parts[1],
135
+ column: null,
136
+ };
137
+ }
138
+ else if ((parts = opera11Regex.exec(lines[line]))) {
139
+ element = {
140
+ url: parts[6],
141
+ func: parts[3] || parts[4],
142
+ args: parts[5] ? parts[5].split(",") : [],
143
+ line: +parts[1],
144
+ column: +parts[2],
145
+ };
146
+ }
147
+ if (element) {
148
+ if (!element.func && element.line) {
149
+ element.func = UNKNOWN_FUNCTION;
150
+ }
151
+ stack.push(element);
152
+ }
153
+ }
154
+ if (!stack.length) {
155
+ return null;
156
+ }
157
+ return {
158
+ message: extractMessage(ex),
159
+ name: ex.name,
160
+ stack,
161
+ };
162
+ }
163
+ function popFrames(stacktrace, popSize) {
164
+ try {
165
+ return {
166
+ ...stacktrace,
167
+ stack: stacktrace.stack.slice(popSize),
168
+ };
169
+ }
170
+ catch {
171
+ return stacktrace;
172
+ }
173
+ }
174
+ function extractMessage(ex) {
175
+ const message = ex && ex.message;
176
+ if (!message) {
177
+ return "No error message";
178
+ }
179
+ if (message.error && typeof message.error.message === "string") {
180
+ return message.error.message;
181
+ }
182
+ return message;
183
+ }
184
+ //# sourceMappingURL=tracekit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracekit.js","sourceRoot":"","sources":["../../src/common/tracekit.ts"],"names":[],"mappings":";;AAgDA,8CAuCC;AA/DD,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAG7B,MAAM,MAAM,GACV,4JAA4J,CAAC;AAS/J,MAAM,KAAK,GACT,wLAAwL,CAAC;AAC3L,MAAM,KAAK,GACT,+GAA+G,CAAC;AAClH,MAAM,SAAS,GAAG,+CAA+C,CAAC;AAClE,MAAM,UAAU,GAAG,+BAA+B,CAAC;AAEnD,MAAM,mBAAmB,GAAG,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 +1,20 @@
1
+ export declare function isObject(value: unknown): value is Record<string, unknown>;
2
+ export declare function encryptP(value: string | number): string;
3
+ export declare function isIgnore(url: string, filterUrls: string[]): boolean;
4
+ export declare function endsWith(str: string, endStr: string): boolean;
5
+ export declare function getConsoleErrorMsg(args: any[]): string;
6
+ export declare const ERRORTYPES: {
7
+ readonly log: "log";
8
+ readonly script: "script";
9
+ readonly ajax: "ajax";
10
+ readonly fetch: "fetch";
11
+ readonly bussinessAjax: "bussiness-ajax";
12
+ readonly bussinessFetch: "bussiness-fetch";
13
+ readonly resource: "resource";
14
+ };
15
+ export declare const ERROR_APIS: {
16
+ readonly consoleError: "console-error";
17
+ readonly onerror: "onerror";
18
+ readonly unhandledRejection: "unhandled-rejection";
19
+ readonly resourceError: "resource-error";
20
+ };
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERROR_APIS = exports.ERRORTYPES = void 0;
4
+ exports.isObject = isObject;
5
+ exports.encryptP = encryptP;
6
+ exports.isIgnore = isIgnore;
7
+ exports.endsWith = endsWith;
8
+ exports.getConsoleErrorMsg = getConsoleErrorMsg;
9
+ function isObject(value) {
10
+ return Object.prototype.toString.apply(value) === "[object Object]";
11
+ }
12
+ const middle = {
13
+ 0: "QR",
14
+ 1: "xa",
15
+ 2: "cL",
16
+ 3: "pF",
17
+ 4: "Oe",
18
+ 5: "bn",
19
+ 6: "sM",
20
+ 7: "yt",
21
+ 8: "Uv",
22
+ 9: "ik",
23
+ };
24
+ function encryptP(value) {
25
+ const str = typeof value === "number" ? String(value) : value;
26
+ if (typeof str !== "string")
27
+ throw new Error("Invalid p field format: only a number or a numeric string is allowed");
28
+ return str
29
+ .split("")
30
+ .map((item) => {
31
+ const n = Number(item);
32
+ return Number.isInteger(n) && middle[n] ? middle[n] : "";
33
+ })
34
+ .join("");
35
+ }
36
+ function isIgnore(url, filterUrls) {
37
+ let ignore = false;
38
+ if (url && filterUrls && filterUrls.length) {
39
+ filterUrls.find((item) => {
40
+ if (url.indexOf(item) !== -1) {
41
+ ignore = true;
42
+ return true;
43
+ }
44
+ return false;
45
+ });
46
+ }
47
+ return ignore;
48
+ }
49
+ function endsWith(str, endStr) {
50
+ const reg = new RegExp(endStr + "$");
51
+ return reg.test(str);
52
+ }
53
+ function ifGetReasonOrStr(err) {
54
+ if (Object.prototype.toString.apply(err) === "[object PromiseRejectionEvent]") {
55
+ return "PromiseRejectionEvent: " + err.reason;
56
+ }
57
+ else if (isObject(err)) {
58
+ return JSON.stringify(err);
59
+ }
60
+ return String(err);
61
+ }
62
+ function getConsoleErrorMsg(args) {
63
+ let msg = "";
64
+ try {
65
+ if (args.length === 1) {
66
+ msg = "" + ifGetReasonOrStr(args[0]);
67
+ }
68
+ else if (args.length > 1) {
69
+ const arr = [];
70
+ for (const i in args) {
71
+ arr.push("" + ifGetReasonOrStr(args[i]));
72
+ }
73
+ msg = arr.toString();
74
+ }
75
+ }
76
+ catch {
77
+ }
78
+ return msg;
79
+ }
80
+ exports.ERRORTYPES = {
81
+ log: "log",
82
+ script: "script",
83
+ ajax: "ajax",
84
+ fetch: "fetch",
85
+ bussinessAjax: "bussiness-ajax",
86
+ bussinessFetch: "bussiness-fetch",
87
+ resource: "resource",
88
+ };
89
+ exports.ERROR_APIS = {
90
+ consoleError: "console-error",
91
+ onerror: "onerror",
92
+ unhandledRejection: "unhandled-rejection",
93
+ resourceError: "resource-error",
94
+ };
95
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/common/utils.ts"],"names":[],"mappings":";;;AAAA,4BAEC;AAeD,4BAUC;AAED,4BAYC;AAED,4BAGC;AAWD,gDAgBC;AAzED,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,iBAAiB,CAAC;AACtE,CAAC;AAED,MAAM,MAAM,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AA,UAAU,GAAG;IACxB,GAAG,EAAE,KAAK;IACV,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,aAAa,EAAE,gBAAgB;IAC/B,cAAc,EAAE,iBAAiB;IACjC,QAAQ,EAAE,UAAU;CACZ,CAAC;AAQE,QAAA,UAAU,GAAG;IAExB,YAAY,EAAE,eAAe;IAE7B,OAAO,EAAE,SAAS;IAElB,kBAAkB,EAAE,qBAAqB;IAEzC,aAAa,EAAE,gBAAgB;CACvB,CAAC"}
package/dist/core.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { StackTrace } from "./common/tracekit";
2
+ import { InitOptions, ReportType } from "./types";
3
+ declare let reportData: (type?: ReportType) => void;
4
+ declare let reportCustomsNow: () => void;
5
+ declare let reportCustomsSoon: () => void;
6
+ declare let _conf: any;
7
+ declare let reportSdkError: (error: any) => void;
8
+ declare const ErrorInstanceReport: (error: StackTrace, api: string, type: string) => void;
9
+ declare function Performance(options: InitOptions): void;
10
+ export { reportData, reportCustomsNow, reportCustomsSoon, _conf, ErrorInstanceReport, reportSdkError };
11
+ export default Performance;