nexatrace-tracker 0.1.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 ADDED
@@ -0,0 +1,39 @@
1
+ # NexaTrace Tracker
2
+
3
+ Lightweight error tracking client for [NexaTrace](https://nexatrace.com). Works in browser, Node, and frameworks.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install nexatrace-tracker
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Browser / React / Next.js
14
+
15
+ ```js
16
+ import { initErrorTracker } from "nexatrace-tracker"
17
+
18
+ initErrorTracker({
19
+ apiKey: "et_your_api_key_here",
20
+ baseUrl: "https://nexatrace.com", // optional, defaults to script origin
21
+ })
22
+ ```
23
+
24
+ ### CDN (alternative)
25
+
26
+ ```html
27
+ <script src="https://nexatrace.com/cdn/tracker.js" data-key="et_your_api_key_here" crossorigin="anonymous"></script>
28
+ ```
29
+
30
+ ## Options
31
+
32
+ | Option | Type | Required | Description |
33
+ |-----------|--------|----------|--------------------------------------|
34
+ | `apiKey` | string | yes | Your project API key from NexaTrace |
35
+ | `baseUrl` | string | no | Custom server URL (default: auto) |
36
+
37
+ ## License
38
+
39
+ MIT
package/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ type InitOptions = {
2
+ apiKey: string
3
+ baseUrl?: string
4
+ }
5
+
6
+ declare function initErrorTracker(options: InitOptions): void
7
+
8
+ export { initErrorTracker, InitOptions }
package/index.js ADDED
@@ -0,0 +1,73 @@
1
+ (function (global, factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ module.exports = factory()
4
+ } else {
5
+ global.NexaTrace = factory()
6
+ }
7
+ })(typeof self !== "undefined" ? self : this, function () {
8
+ "use strict"
9
+
10
+ var scriptSrc =
11
+ (typeof document !== "undefined" &&
12
+ document.currentScript &&
13
+ document.currentScript.src) ||
14
+ ""
15
+ var scriptOrigin = scriptSrc
16
+ ? scriptSrc.substring(0, scriptSrc.indexOf("/nexatrace-tracker"))
17
+ : ""
18
+
19
+ function send(apiKey, baseUrl, data) {
20
+ var url = (baseUrl || scriptOrigin || "https://nexatrace.com") + "/api/webhook"
21
+ var body = JSON.stringify({
22
+ api_key: apiKey,
23
+ message: data.message || "",
24
+ stack: data.stack || "",
25
+ url: data.url || (typeof location !== "undefined" ? location.href : ""),
26
+ line: data.line || 0,
27
+ col: data.col || 0,
28
+ user_agent: typeof navigator !== "undefined" ? navigator.userAgent : "",
29
+ })
30
+ if (typeof fetch !== "undefined") {
31
+ fetch(url, {
32
+ method: "POST",
33
+ headers: { "Content-Type": "application/json" },
34
+ body: body,
35
+ }).catch(function () {})
36
+ }
37
+ }
38
+
39
+ function initErrorTracker(options) {
40
+ if (!options || !options.apiKey) {
41
+ if (typeof console !== "undefined")
42
+ console.error("[NexaTrace] apiKey is required")
43
+ return
44
+ }
45
+ var apiKey = options.apiKey
46
+ var baseUrl = options.baseUrl || ""
47
+
48
+ function onError(msg, source, line, col, err) {
49
+ send(apiKey, baseUrl, {
50
+ message: msg,
51
+ stack: err && err.stack,
52
+ url: source,
53
+ line: line,
54
+ col: col,
55
+ })
56
+ }
57
+
58
+ function onRejection(e) {
59
+ send(apiKey, baseUrl, {
60
+ message:
61
+ (e.reason && e.reason.message) || "Unhandled Promise Rejection",
62
+ stack: e.reason && e.reason.stack,
63
+ })
64
+ }
65
+
66
+ if (typeof window !== "undefined") {
67
+ window.onerror = onError
68
+ window.onunhandledrejection = onRejection
69
+ }
70
+ }
71
+
72
+ return { initErrorTracker: initErrorTracker }
73
+ })
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "nexatrace-tracker",
3
+ "version": "0.1.0",
4
+ "description": "NexaTrace error tracking client — lightweight, CDN-free, framework-friendly",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "keywords": ["error-tracking", "monitoring", "nexatrace", "nexagaze", "debugging"],
8
+ "license": "MIT",
9
+ "files": ["index.js", "index.d.ts", "README.md"],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/nexagaze/nexatrace-tracker"
13
+ }
14
+ }