@iaportafolio/nextjs 0.1.0 → 0.1.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.
- package/dist/chunk-LFDO56A5.js +27 -0
- package/dist/chunk-TYH3TMKC.js +120 -0
- package/dist/client.cjs +144 -0
- package/dist/client.js +8 -0
- package/dist/index.cjs +184 -0
- package/dist/index.js +16 -0
- package/dist/server.cjs +62 -0
- package/dist/server.js +10 -0
- package/package.json +49 -11
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/server.ts
|
|
2
|
+
import * as faro from "@iaportafolio/node";
|
|
3
|
+
var installed = false;
|
|
4
|
+
function registerFaro(opts) {
|
|
5
|
+
if (installed) return;
|
|
6
|
+
if (process.env.NEXT_RUNTIME && process.env.NEXT_RUNTIME !== "nodejs") {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
faro.init(opts);
|
|
10
|
+
installed = true;
|
|
11
|
+
}
|
|
12
|
+
function captureRequestError(err, request) {
|
|
13
|
+
if (!installed) return;
|
|
14
|
+
faro.captureException(err, {
|
|
15
|
+
tags: {
|
|
16
|
+
"http.path": request.path ?? "",
|
|
17
|
+
"http.method": request.method ?? "",
|
|
18
|
+
"next.router": request.routerKind ?? ""
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
faro,
|
|
25
|
+
registerFaro,
|
|
26
|
+
captureRequestError
|
|
27
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
var client = null;
|
|
3
|
+
function newClient(opts) {
|
|
4
|
+
const endpoint = opts.endpoint.replace(/\/$/, "");
|
|
5
|
+
const queue = [];
|
|
6
|
+
const maxBatch = opts.maxBatchSize ?? 100;
|
|
7
|
+
let pendingTimer = null;
|
|
8
|
+
function scheduleFlush() {
|
|
9
|
+
if (pendingTimer) return;
|
|
10
|
+
pendingTimer = setTimeout(() => {
|
|
11
|
+
pendingTimer = null;
|
|
12
|
+
void flush();
|
|
13
|
+
}, opts.flushIntervalMs ?? 1500);
|
|
14
|
+
}
|
|
15
|
+
async function flush() {
|
|
16
|
+
if (queue.length === 0) return;
|
|
17
|
+
const batch = queue.splice(0, maxBatch);
|
|
18
|
+
try {
|
|
19
|
+
const body = JSON.stringify({ service: opts.service, logs: batch });
|
|
20
|
+
const ok = typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function" && document.visibilityState === "hidden" ? navigator.sendBeacon(
|
|
21
|
+
`${endpoint}/api/v1/ingest/logs?_token=${encodeURIComponent(opts.token)}`,
|
|
22
|
+
new Blob([body], { type: "application/json" })
|
|
23
|
+
) : false;
|
|
24
|
+
if (ok) return;
|
|
25
|
+
const res = await fetch(`${endpoint}/api/v1/ingest/logs`, {
|
|
26
|
+
method: "POST",
|
|
27
|
+
keepalive: true,
|
|
28
|
+
headers: {
|
|
29
|
+
"Authorization": `Bearer ${opts.token}`,
|
|
30
|
+
"Content-Type": "application/json"
|
|
31
|
+
},
|
|
32
|
+
body
|
|
33
|
+
});
|
|
34
|
+
if (!res.ok) {
|
|
35
|
+
if (res.status >= 500) queue.unshift(...batch);
|
|
36
|
+
}
|
|
37
|
+
} catch (_e) {
|
|
38
|
+
queue.unshift(...batch);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function enqueue(level, message, attributes) {
|
|
42
|
+
const attrs = {};
|
|
43
|
+
if (opts.attributes) {
|
|
44
|
+
for (const [k, v] of Object.entries(opts.attributes)) attrs[k] = String(v);
|
|
45
|
+
}
|
|
46
|
+
if (opts.environment) attrs["deployment.environment"] = opts.environment;
|
|
47
|
+
if (opts.release) attrs["service.version"] = opts.release;
|
|
48
|
+
if (typeof window !== "undefined") {
|
|
49
|
+
attrs["browser.url"] = window.location.href;
|
|
50
|
+
attrs["browser.userAgent"] = navigator.userAgent;
|
|
51
|
+
}
|
|
52
|
+
if (attributes) {
|
|
53
|
+
for (const [k, v] of Object.entries(attributes)) {
|
|
54
|
+
attrs[k] = typeof v === "string" ? v : JSON.stringify(v);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
queue.push({
|
|
58
|
+
level,
|
|
59
|
+
message,
|
|
60
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
61
|
+
attributes: attrs
|
|
62
|
+
});
|
|
63
|
+
if (queue.length >= maxBatch) void flush();
|
|
64
|
+
else scheduleFlush();
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
log: (e) => enqueue(e.level ?? "INFO", e.message, e.attributes),
|
|
68
|
+
info: (m, a) => enqueue("INFO", m, a),
|
|
69
|
+
warn: (m, a) => enqueue("WARN", m, a),
|
|
70
|
+
error: (m, a) => enqueue("ERROR", m, a),
|
|
71
|
+
captureException: (err, ctx) => {
|
|
72
|
+
const e = err instanceof Error ? err : new Error(typeof err === "string" ? err : JSON.stringify(err));
|
|
73
|
+
enqueue("ERROR", (ctx == null ? void 0 : ctx.message) ?? `${e.name}: ${e.message}`, {
|
|
74
|
+
"exception.type": e.name,
|
|
75
|
+
"exception.message": e.message,
|
|
76
|
+
"exception.stacktrace": e.stack ?? "",
|
|
77
|
+
...(ctx == null ? void 0 : ctx.tags) ?? {}
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
flush
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function initFaroClient(opts) {
|
|
84
|
+
if (typeof window === "undefined") {
|
|
85
|
+
return {
|
|
86
|
+
log() {
|
|
87
|
+
},
|
|
88
|
+
info() {
|
|
89
|
+
},
|
|
90
|
+
warn() {
|
|
91
|
+
},
|
|
92
|
+
error() {
|
|
93
|
+
},
|
|
94
|
+
captureException() {
|
|
95
|
+
},
|
|
96
|
+
flush: async () => void 0
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
client = newClient(opts);
|
|
100
|
+
window.addEventListener("error", (ev) => {
|
|
101
|
+
client == null ? void 0 : client.captureException(ev.error ?? ev.message, { tags: { origin: "window.error" } });
|
|
102
|
+
});
|
|
103
|
+
window.addEventListener("unhandledrejection", (ev) => {
|
|
104
|
+
client == null ? void 0 : client.captureException(ev.reason, { tags: { origin: "unhandledrejection" } });
|
|
105
|
+
});
|
|
106
|
+
document.addEventListener("visibilitychange", () => {
|
|
107
|
+
if (document.visibilityState === "hidden") void (client == null ? void 0 : client.flush());
|
|
108
|
+
});
|
|
109
|
+
window.addEventListener("pagehide", () => void (client == null ? void 0 : client.flush()));
|
|
110
|
+
return client;
|
|
111
|
+
}
|
|
112
|
+
function faroClient() {
|
|
113
|
+
if (!client) throw new Error("Hay que llamar a initFaroClient() antes de usarlo");
|
|
114
|
+
return client;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export {
|
|
118
|
+
initFaroClient,
|
|
119
|
+
faroClient
|
|
120
|
+
};
|
package/dist/client.cjs
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/client.ts
|
|
20
|
+
var client_exports = {};
|
|
21
|
+
__export(client_exports, {
|
|
22
|
+
faroClient: () => faroClient,
|
|
23
|
+
initFaroClient: () => initFaroClient
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(client_exports);
|
|
26
|
+
var client = null;
|
|
27
|
+
function newClient(opts) {
|
|
28
|
+
const endpoint = opts.endpoint.replace(/\/$/, "");
|
|
29
|
+
const queue = [];
|
|
30
|
+
const maxBatch = opts.maxBatchSize ?? 100;
|
|
31
|
+
let pendingTimer = null;
|
|
32
|
+
function scheduleFlush() {
|
|
33
|
+
if (pendingTimer) return;
|
|
34
|
+
pendingTimer = setTimeout(() => {
|
|
35
|
+
pendingTimer = null;
|
|
36
|
+
void flush();
|
|
37
|
+
}, opts.flushIntervalMs ?? 1500);
|
|
38
|
+
}
|
|
39
|
+
async function flush() {
|
|
40
|
+
if (queue.length === 0) return;
|
|
41
|
+
const batch = queue.splice(0, maxBatch);
|
|
42
|
+
try {
|
|
43
|
+
const body = JSON.stringify({ service: opts.service, logs: batch });
|
|
44
|
+
const ok = typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function" && document.visibilityState === "hidden" ? navigator.sendBeacon(
|
|
45
|
+
`${endpoint}/api/v1/ingest/logs?_token=${encodeURIComponent(opts.token)}`,
|
|
46
|
+
new Blob([body], { type: "application/json" })
|
|
47
|
+
) : false;
|
|
48
|
+
if (ok) return;
|
|
49
|
+
const res = await fetch(`${endpoint}/api/v1/ingest/logs`, {
|
|
50
|
+
method: "POST",
|
|
51
|
+
keepalive: true,
|
|
52
|
+
headers: {
|
|
53
|
+
"Authorization": `Bearer ${opts.token}`,
|
|
54
|
+
"Content-Type": "application/json"
|
|
55
|
+
},
|
|
56
|
+
body
|
|
57
|
+
});
|
|
58
|
+
if (!res.ok) {
|
|
59
|
+
if (res.status >= 500) queue.unshift(...batch);
|
|
60
|
+
}
|
|
61
|
+
} catch (_e) {
|
|
62
|
+
queue.unshift(...batch);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function enqueue(level, message, attributes) {
|
|
66
|
+
const attrs = {};
|
|
67
|
+
if (opts.attributes) {
|
|
68
|
+
for (const [k, v] of Object.entries(opts.attributes)) attrs[k] = String(v);
|
|
69
|
+
}
|
|
70
|
+
if (opts.environment) attrs["deployment.environment"] = opts.environment;
|
|
71
|
+
if (opts.release) attrs["service.version"] = opts.release;
|
|
72
|
+
if (typeof window !== "undefined") {
|
|
73
|
+
attrs["browser.url"] = window.location.href;
|
|
74
|
+
attrs["browser.userAgent"] = navigator.userAgent;
|
|
75
|
+
}
|
|
76
|
+
if (attributes) {
|
|
77
|
+
for (const [k, v] of Object.entries(attributes)) {
|
|
78
|
+
attrs[k] = typeof v === "string" ? v : JSON.stringify(v);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
queue.push({
|
|
82
|
+
level,
|
|
83
|
+
message,
|
|
84
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
85
|
+
attributes: attrs
|
|
86
|
+
});
|
|
87
|
+
if (queue.length >= maxBatch) void flush();
|
|
88
|
+
else scheduleFlush();
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
log: (e) => enqueue(e.level ?? "INFO", e.message, e.attributes),
|
|
92
|
+
info: (m, a) => enqueue("INFO", m, a),
|
|
93
|
+
warn: (m, a) => enqueue("WARN", m, a),
|
|
94
|
+
error: (m, a) => enqueue("ERROR", m, a),
|
|
95
|
+
captureException: (err, ctx) => {
|
|
96
|
+
const e = err instanceof Error ? err : new Error(typeof err === "string" ? err : JSON.stringify(err));
|
|
97
|
+
enqueue("ERROR", (ctx == null ? void 0 : ctx.message) ?? `${e.name}: ${e.message}`, {
|
|
98
|
+
"exception.type": e.name,
|
|
99
|
+
"exception.message": e.message,
|
|
100
|
+
"exception.stacktrace": e.stack ?? "",
|
|
101
|
+
...(ctx == null ? void 0 : ctx.tags) ?? {}
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
flush
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function initFaroClient(opts) {
|
|
108
|
+
if (typeof window === "undefined") {
|
|
109
|
+
return {
|
|
110
|
+
log() {
|
|
111
|
+
},
|
|
112
|
+
info() {
|
|
113
|
+
},
|
|
114
|
+
warn() {
|
|
115
|
+
},
|
|
116
|
+
error() {
|
|
117
|
+
},
|
|
118
|
+
captureException() {
|
|
119
|
+
},
|
|
120
|
+
flush: async () => void 0
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
client = newClient(opts);
|
|
124
|
+
window.addEventListener("error", (ev) => {
|
|
125
|
+
client == null ? void 0 : client.captureException(ev.error ?? ev.message, { tags: { origin: "window.error" } });
|
|
126
|
+
});
|
|
127
|
+
window.addEventListener("unhandledrejection", (ev) => {
|
|
128
|
+
client == null ? void 0 : client.captureException(ev.reason, { tags: { origin: "unhandledrejection" } });
|
|
129
|
+
});
|
|
130
|
+
document.addEventListener("visibilitychange", () => {
|
|
131
|
+
if (document.visibilityState === "hidden") void (client == null ? void 0 : client.flush());
|
|
132
|
+
});
|
|
133
|
+
window.addEventListener("pagehide", () => void (client == null ? void 0 : client.flush()));
|
|
134
|
+
return client;
|
|
135
|
+
}
|
|
136
|
+
function faroClient() {
|
|
137
|
+
if (!client) throw new Error("Hay que llamar a initFaroClient() antes de usarlo");
|
|
138
|
+
return client;
|
|
139
|
+
}
|
|
140
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
141
|
+
0 && (module.exports = {
|
|
142
|
+
faroClient,
|
|
143
|
+
initFaroClient
|
|
144
|
+
});
|
package/dist/client.js
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
captureRequestError: () => captureRequestError,
|
|
33
|
+
faro: () => faro,
|
|
34
|
+
faroClient: () => faroClient,
|
|
35
|
+
initFaroClient: () => initFaroClient,
|
|
36
|
+
registerFaro: () => registerFaro
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(index_exports);
|
|
39
|
+
|
|
40
|
+
// src/server.ts
|
|
41
|
+
var faro = __toESM(require("@iaportafolio/node"), 1);
|
|
42
|
+
var installed = false;
|
|
43
|
+
function registerFaro(opts) {
|
|
44
|
+
if (installed) return;
|
|
45
|
+
if (process.env.NEXT_RUNTIME && process.env.NEXT_RUNTIME !== "nodejs") {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
faro.init(opts);
|
|
49
|
+
installed = true;
|
|
50
|
+
}
|
|
51
|
+
function captureRequestError(err, request) {
|
|
52
|
+
if (!installed) return;
|
|
53
|
+
faro.captureException(err, {
|
|
54
|
+
tags: {
|
|
55
|
+
"http.path": request.path ?? "",
|
|
56
|
+
"http.method": request.method ?? "",
|
|
57
|
+
"next.router": request.routerKind ?? ""
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/client.ts
|
|
63
|
+
var client = null;
|
|
64
|
+
function newClient(opts) {
|
|
65
|
+
const endpoint = opts.endpoint.replace(/\/$/, "");
|
|
66
|
+
const queue = [];
|
|
67
|
+
const maxBatch = opts.maxBatchSize ?? 100;
|
|
68
|
+
let pendingTimer = null;
|
|
69
|
+
function scheduleFlush() {
|
|
70
|
+
if (pendingTimer) return;
|
|
71
|
+
pendingTimer = setTimeout(() => {
|
|
72
|
+
pendingTimer = null;
|
|
73
|
+
void flush();
|
|
74
|
+
}, opts.flushIntervalMs ?? 1500);
|
|
75
|
+
}
|
|
76
|
+
async function flush() {
|
|
77
|
+
if (queue.length === 0) return;
|
|
78
|
+
const batch = queue.splice(0, maxBatch);
|
|
79
|
+
try {
|
|
80
|
+
const body = JSON.stringify({ service: opts.service, logs: batch });
|
|
81
|
+
const ok = typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function" && document.visibilityState === "hidden" ? navigator.sendBeacon(
|
|
82
|
+
`${endpoint}/api/v1/ingest/logs?_token=${encodeURIComponent(opts.token)}`,
|
|
83
|
+
new Blob([body], { type: "application/json" })
|
|
84
|
+
) : false;
|
|
85
|
+
if (ok) return;
|
|
86
|
+
const res = await fetch(`${endpoint}/api/v1/ingest/logs`, {
|
|
87
|
+
method: "POST",
|
|
88
|
+
keepalive: true,
|
|
89
|
+
headers: {
|
|
90
|
+
"Authorization": `Bearer ${opts.token}`,
|
|
91
|
+
"Content-Type": "application/json"
|
|
92
|
+
},
|
|
93
|
+
body
|
|
94
|
+
});
|
|
95
|
+
if (!res.ok) {
|
|
96
|
+
if (res.status >= 500) queue.unshift(...batch);
|
|
97
|
+
}
|
|
98
|
+
} catch (_e) {
|
|
99
|
+
queue.unshift(...batch);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function enqueue(level, message, attributes) {
|
|
103
|
+
const attrs = {};
|
|
104
|
+
if (opts.attributes) {
|
|
105
|
+
for (const [k, v] of Object.entries(opts.attributes)) attrs[k] = String(v);
|
|
106
|
+
}
|
|
107
|
+
if (opts.environment) attrs["deployment.environment"] = opts.environment;
|
|
108
|
+
if (opts.release) attrs["service.version"] = opts.release;
|
|
109
|
+
if (typeof window !== "undefined") {
|
|
110
|
+
attrs["browser.url"] = window.location.href;
|
|
111
|
+
attrs["browser.userAgent"] = navigator.userAgent;
|
|
112
|
+
}
|
|
113
|
+
if (attributes) {
|
|
114
|
+
for (const [k, v] of Object.entries(attributes)) {
|
|
115
|
+
attrs[k] = typeof v === "string" ? v : JSON.stringify(v);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
queue.push({
|
|
119
|
+
level,
|
|
120
|
+
message,
|
|
121
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
122
|
+
attributes: attrs
|
|
123
|
+
});
|
|
124
|
+
if (queue.length >= maxBatch) void flush();
|
|
125
|
+
else scheduleFlush();
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
log: (e) => enqueue(e.level ?? "INFO", e.message, e.attributes),
|
|
129
|
+
info: (m, a) => enqueue("INFO", m, a),
|
|
130
|
+
warn: (m, a) => enqueue("WARN", m, a),
|
|
131
|
+
error: (m, a) => enqueue("ERROR", m, a),
|
|
132
|
+
captureException: (err, ctx) => {
|
|
133
|
+
const e = err instanceof Error ? err : new Error(typeof err === "string" ? err : JSON.stringify(err));
|
|
134
|
+
enqueue("ERROR", (ctx == null ? void 0 : ctx.message) ?? `${e.name}: ${e.message}`, {
|
|
135
|
+
"exception.type": e.name,
|
|
136
|
+
"exception.message": e.message,
|
|
137
|
+
"exception.stacktrace": e.stack ?? "",
|
|
138
|
+
...(ctx == null ? void 0 : ctx.tags) ?? {}
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
flush
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function initFaroClient(opts) {
|
|
145
|
+
if (typeof window === "undefined") {
|
|
146
|
+
return {
|
|
147
|
+
log() {
|
|
148
|
+
},
|
|
149
|
+
info() {
|
|
150
|
+
},
|
|
151
|
+
warn() {
|
|
152
|
+
},
|
|
153
|
+
error() {
|
|
154
|
+
},
|
|
155
|
+
captureException() {
|
|
156
|
+
},
|
|
157
|
+
flush: async () => void 0
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
client = newClient(opts);
|
|
161
|
+
window.addEventListener("error", (ev) => {
|
|
162
|
+
client == null ? void 0 : client.captureException(ev.error ?? ev.message, { tags: { origin: "window.error" } });
|
|
163
|
+
});
|
|
164
|
+
window.addEventListener("unhandledrejection", (ev) => {
|
|
165
|
+
client == null ? void 0 : client.captureException(ev.reason, { tags: { origin: "unhandledrejection" } });
|
|
166
|
+
});
|
|
167
|
+
document.addEventListener("visibilitychange", () => {
|
|
168
|
+
if (document.visibilityState === "hidden") void (client == null ? void 0 : client.flush());
|
|
169
|
+
});
|
|
170
|
+
window.addEventListener("pagehide", () => void (client == null ? void 0 : client.flush()));
|
|
171
|
+
return client;
|
|
172
|
+
}
|
|
173
|
+
function faroClient() {
|
|
174
|
+
if (!client) throw new Error("Hay que llamar a initFaroClient() antes de usarlo");
|
|
175
|
+
return client;
|
|
176
|
+
}
|
|
177
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
178
|
+
0 && (module.exports = {
|
|
179
|
+
captureRequestError,
|
|
180
|
+
faro,
|
|
181
|
+
faroClient,
|
|
182
|
+
initFaroClient,
|
|
183
|
+
registerFaro
|
|
184
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
faroClient,
|
|
3
|
+
initFaroClient
|
|
4
|
+
} from "./chunk-TYH3TMKC.js";
|
|
5
|
+
import {
|
|
6
|
+
captureRequestError,
|
|
7
|
+
faro,
|
|
8
|
+
registerFaro
|
|
9
|
+
} from "./chunk-LFDO56A5.js";
|
|
10
|
+
export {
|
|
11
|
+
captureRequestError,
|
|
12
|
+
faro,
|
|
13
|
+
faroClient,
|
|
14
|
+
initFaroClient,
|
|
15
|
+
registerFaro
|
|
16
|
+
};
|
package/dist/server.cjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/server.ts
|
|
30
|
+
var server_exports = {};
|
|
31
|
+
__export(server_exports, {
|
|
32
|
+
captureRequestError: () => captureRequestError,
|
|
33
|
+
faro: () => faro,
|
|
34
|
+
registerFaro: () => registerFaro
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(server_exports);
|
|
37
|
+
var faro = __toESM(require("@iaportafolio/node"), 1);
|
|
38
|
+
var installed = false;
|
|
39
|
+
function registerFaro(opts) {
|
|
40
|
+
if (installed) return;
|
|
41
|
+
if (process.env.NEXT_RUNTIME && process.env.NEXT_RUNTIME !== "nodejs") {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
faro.init(opts);
|
|
45
|
+
installed = true;
|
|
46
|
+
}
|
|
47
|
+
function captureRequestError(err, request) {
|
|
48
|
+
if (!installed) return;
|
|
49
|
+
faro.captureException(err, {
|
|
50
|
+
tags: {
|
|
51
|
+
"http.path": request.path ?? "",
|
|
52
|
+
"http.method": request.method ?? "",
|
|
53
|
+
"next.router": request.routerKind ?? ""
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
captureRequestError,
|
|
60
|
+
faro,
|
|
61
|
+
registerFaro
|
|
62
|
+
});
|
package/dist/server.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iaportafolio/nextjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Faro SDK for Next.js (App Router + Pages Router)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -8,17 +8,55 @@
|
|
|
8
8
|
"module": "./dist/index.js",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"exports": {
|
|
11
|
-
".": {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./client": {
|
|
17
|
+
"types": "./dist/client.d.ts",
|
|
18
|
+
"import": "./dist/client.js",
|
|
19
|
+
"require": "./dist/client.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./server": {
|
|
22
|
+
"types": "./dist/server.d.ts",
|
|
23
|
+
"import": "./dist/server.js",
|
|
24
|
+
"require": "./dist/server.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"src",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/IA-Portafolio/faro.git",
|
|
35
|
+
"directory": "sdks/nextjs"
|
|
14
36
|
},
|
|
15
|
-
"files": ["dist", "src", "README.md"],
|
|
16
|
-
"repository": { "type": "git", "url": "git+https://github.com/IA-Portafolio/faro.git", "directory": "sdks/nextjs" },
|
|
17
37
|
"homepage": "https://github.com/IA-Portafolio/faro/tree/main/sdks/nextjs#readme",
|
|
18
38
|
"bugs": "https://github.com/IA-Portafolio/faro/issues",
|
|
19
|
-
"keywords": [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
39
|
+
"keywords": [
|
|
40
|
+
"faro",
|
|
41
|
+
"nextjs",
|
|
42
|
+
"observability",
|
|
43
|
+
"logging",
|
|
44
|
+
"telemetry"
|
|
45
|
+
],
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public",
|
|
48
|
+
"provenance": true
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsup src/index.ts src/client.ts src/server.ts --format cjs,esm --dts --clean"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@iaportafolio/node": "^0.1.0",
|
|
55
|
+
"next": ">=13"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"tsup": "^8.0.0",
|
|
59
|
+
"typescript": "^5.4.0",
|
|
60
|
+
"@types/node": "^20.0.0"
|
|
61
|
+
}
|
|
24
62
|
}
|