@watchupltd/browser 1.0.2 → 1.0.3
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/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +80 -0
- package/dist/index.mjs +53 -0
- package/package.json +5 -1
- package/src/index.ts +0 -70
- package/tsconfig.json +0 -9
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IncidentConfig, IncidentClient } from '@watchupltd/core';
|
|
2
|
+
export { Breadcrumb, IncidentClient, IncidentConfig, SeverityLevel, User } from '@watchupltd/core';
|
|
3
|
+
|
|
4
|
+
interface BrowserConfig extends IncidentConfig {
|
|
5
|
+
captureConsoleErrors?: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare function init(config: BrowserConfig): IncidentClient;
|
|
8
|
+
declare function getClient(): IncidentClient | null;
|
|
9
|
+
|
|
10
|
+
export { BrowserConfig, getClient, init };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IncidentConfig, IncidentClient } from '@watchupltd/core';
|
|
2
|
+
export { Breadcrumb, IncidentClient, IncidentConfig, SeverityLevel, User } from '@watchupltd/core';
|
|
3
|
+
|
|
4
|
+
interface BrowserConfig extends IncidentConfig {
|
|
5
|
+
captureConsoleErrors?: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare function init(config: BrowserConfig): IncidentClient;
|
|
8
|
+
declare function getClient(): IncidentClient | null;
|
|
9
|
+
|
|
10
|
+
export { BrowserConfig, getClient, init };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
IncidentClient: () => import_core2.IncidentClient,
|
|
24
|
+
getClient: () => getClient,
|
|
25
|
+
init: () => init
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
28
|
+
var import_core = require("@watchupltd/core");
|
|
29
|
+
var import_core2 = require("@watchupltd/core");
|
|
30
|
+
var globalClient = null;
|
|
31
|
+
function init(config) {
|
|
32
|
+
if (globalClient) {
|
|
33
|
+
return globalClient;
|
|
34
|
+
}
|
|
35
|
+
globalClient = new import_core.IncidentClient(config);
|
|
36
|
+
if (typeof window !== "undefined") {
|
|
37
|
+
setupGlobalErrorHandlers(globalClient);
|
|
38
|
+
if (config.captureConsoleErrors) {
|
|
39
|
+
setupConsoleCapture(globalClient);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return globalClient;
|
|
43
|
+
}
|
|
44
|
+
function getClient() {
|
|
45
|
+
return globalClient;
|
|
46
|
+
}
|
|
47
|
+
function setupGlobalErrorHandlers(client) {
|
|
48
|
+
window.addEventListener("error", (event) => {
|
|
49
|
+
const error = event.error || new Error(event.message);
|
|
50
|
+
client.captureError(error, {
|
|
51
|
+
extra: {
|
|
52
|
+
filename: event.filename,
|
|
53
|
+
lineno: event.lineno,
|
|
54
|
+
colno: event.colno
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
59
|
+
const error = event.reason instanceof Error ? event.reason : new Error(String(event.reason));
|
|
60
|
+
client.captureError(error, {
|
|
61
|
+
tags: { type: "unhandledrejection" }
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function setupConsoleCapture(client) {
|
|
66
|
+
const originalError = console.error;
|
|
67
|
+
console.error = (...args) => {
|
|
68
|
+
originalError.apply(console, args);
|
|
69
|
+
const message = args.map(
|
|
70
|
+
(arg) => typeof arg === "object" ? JSON.stringify(arg) : String(arg)
|
|
71
|
+
).join(" ");
|
|
72
|
+
client.captureMessage(message, "error");
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
IncidentClient,
|
|
78
|
+
getClient,
|
|
79
|
+
init
|
|
80
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { IncidentClient } from "@watchupltd/core";
|
|
3
|
+
import { IncidentClient as IncidentClient2 } from "@watchupltd/core";
|
|
4
|
+
var globalClient = null;
|
|
5
|
+
function init(config) {
|
|
6
|
+
if (globalClient) {
|
|
7
|
+
return globalClient;
|
|
8
|
+
}
|
|
9
|
+
globalClient = new IncidentClient(config);
|
|
10
|
+
if (typeof window !== "undefined") {
|
|
11
|
+
setupGlobalErrorHandlers(globalClient);
|
|
12
|
+
if (config.captureConsoleErrors) {
|
|
13
|
+
setupConsoleCapture(globalClient);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return globalClient;
|
|
17
|
+
}
|
|
18
|
+
function getClient() {
|
|
19
|
+
return globalClient;
|
|
20
|
+
}
|
|
21
|
+
function setupGlobalErrorHandlers(client) {
|
|
22
|
+
window.addEventListener("error", (event) => {
|
|
23
|
+
const error = event.error || new Error(event.message);
|
|
24
|
+
client.captureError(error, {
|
|
25
|
+
extra: {
|
|
26
|
+
filename: event.filename,
|
|
27
|
+
lineno: event.lineno,
|
|
28
|
+
colno: event.colno
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
33
|
+
const error = event.reason instanceof Error ? event.reason : new Error(String(event.reason));
|
|
34
|
+
client.captureError(error, {
|
|
35
|
+
tags: { type: "unhandledrejection" }
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function setupConsoleCapture(client) {
|
|
40
|
+
const originalError = console.error;
|
|
41
|
+
console.error = (...args) => {
|
|
42
|
+
originalError.apply(console, args);
|
|
43
|
+
const message = args.map(
|
|
44
|
+
(arg) => typeof arg === "object" ? JSON.stringify(arg) : String(arg)
|
|
45
|
+
).join(" ");
|
|
46
|
+
client.captureMessage(message, "error");
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
IncidentClient2 as IncidentClient,
|
|
51
|
+
getClient,
|
|
52
|
+
init
|
|
53
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@watchupltd/browser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
7
11
|
"exports": {
|
|
8
12
|
".": {
|
|
9
13
|
"import": "./dist/index.mjs",
|
package/src/index.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { IncidentClient } from '@watchupltd/core';
|
|
2
|
-
import type { IncidentConfig } from '@watchupltd/core';
|
|
3
|
-
|
|
4
|
-
let globalClient: IncidentClient | null = null;
|
|
5
|
-
|
|
6
|
-
export interface BrowserConfig extends IncidentConfig {
|
|
7
|
-
captureConsoleErrors?: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function init(config: BrowserConfig): IncidentClient {
|
|
11
|
-
if (globalClient) {
|
|
12
|
-
return globalClient;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
globalClient = new IncidentClient(config);
|
|
16
|
-
|
|
17
|
-
if (typeof window !== 'undefined') {
|
|
18
|
-
setupGlobalErrorHandlers(globalClient);
|
|
19
|
-
|
|
20
|
-
if (config.captureConsoleErrors) {
|
|
21
|
-
setupConsoleCapture(globalClient);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return globalClient;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function getClient(): IncidentClient | null {
|
|
29
|
-
return globalClient;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function setupGlobalErrorHandlers(client: IncidentClient): void {
|
|
33
|
-
window.addEventListener('error', (event) => {
|
|
34
|
-
const error = event.error || new Error(event.message);
|
|
35
|
-
client.captureError(error, {
|
|
36
|
-
extra: {
|
|
37
|
-
filename: event.filename,
|
|
38
|
-
lineno: event.lineno,
|
|
39
|
-
colno: event.colno
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
window.addEventListener('unhandledrejection', (event) => {
|
|
45
|
-
const error = event.reason instanceof Error
|
|
46
|
-
? event.reason
|
|
47
|
-
: new Error(String(event.reason));
|
|
48
|
-
|
|
49
|
-
client.captureError(error, {
|
|
50
|
-
tags: { type: 'unhandledrejection' }
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function setupConsoleCapture(client: IncidentClient): void {
|
|
56
|
-
const originalError = console.error;
|
|
57
|
-
|
|
58
|
-
console.error = (...args: any[]) => {
|
|
59
|
-
originalError.apply(console, args);
|
|
60
|
-
|
|
61
|
-
const message = args.map(arg =>
|
|
62
|
-
typeof arg === 'object' ? JSON.stringify(arg) : String(arg)
|
|
63
|
-
).join(' ');
|
|
64
|
-
|
|
65
|
-
client.captureMessage(message, 'error');
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export { IncidentClient } from '@watchupltd/core';
|
|
70
|
-
export type { IncidentConfig, SeverityLevel, User, Breadcrumb } from '@watchupltd/core';
|