@starko-one/sdk 0.0.0-stage → 0.1.0-beta.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/CHANGELOG.md +124 -0
- package/LICENSE +17 -0
- package/NOTICE +58 -0
- package/README.md +81 -2
- package/dist/api-B5IHeINe.d.ts +558 -0
- package/dist/api-DR4HazCu.d.cts +558 -0
- package/dist/browser/index.cjs +168 -0
- package/dist/browser/index.d.cts +131 -0
- package/dist/browser/index.d.ts +131 -0
- package/dist/browser/index.js +7 -0
- package/dist/build/rollup.cjs +22 -0
- package/dist/build/rollup.d.cts +34 -0
- package/dist/build/rollup.d.ts +34 -0
- package/dist/build/rollup.js +3 -0
- package/dist/build/vite.cjs +51 -0
- package/dist/build/vite.d.cts +23 -0
- package/dist/build/vite.d.ts +23 -0
- package/dist/build/vite.js +46 -0
- package/dist/build/webpack.cjs +18 -0
- package/dist/build/webpack.d.cts +39 -0
- package/dist/build/webpack.d.ts +39 -0
- package/dist/build/webpack.js +3 -0
- package/dist/chunk-7HYGODU6.cjs +583 -0
- package/dist/chunk-A5M4NOVT.js +413 -0
- package/dist/chunk-A7MYYWMP.cjs +15 -0
- package/dist/chunk-BAQA47FM.js +1113 -0
- package/dist/chunk-CM7HM6CC.js +563 -0
- package/dist/chunk-DFYNIWUN.js +608 -0
- package/dist/chunk-DMVVCGKO.cjs +96 -0
- package/dist/chunk-FARGXYJ4.cjs +56 -0
- package/dist/chunk-G3MYIAX2.js +1226 -0
- package/dist/chunk-G4NAVZQ4.js +249 -0
- package/dist/chunk-GH7RYPKS.js +96 -0
- package/dist/chunk-HADYYQNL.cjs +134 -0
- package/dist/chunk-HOQPAB4X.js +178 -0
- package/dist/chunk-J5RU73SW.js +214 -0
- package/dist/chunk-JNAJ3YZB.cjs +223 -0
- package/dist/chunk-KN7H22EQ.cjs +659 -0
- package/dist/chunk-LDQ4I7FZ.cjs +1151 -0
- package/dist/chunk-NPGESRVQ.js +1212 -0
- package/dist/chunk-OPWM5V7A.cjs +258 -0
- package/dist/chunk-PYYWPIFL.cjs +1230 -0
- package/dist/chunk-R7JLZ4WO.cjs +115 -0
- package/dist/chunk-SC6VQSES.js +213 -0
- package/dist/chunk-TPSJGLR3.cjs +220 -0
- package/dist/chunk-UKBY6HPC.js +131 -0
- package/dist/chunk-VRSEHRBX.cjs +185 -0
- package/dist/chunk-X74AONZA.js +90 -0
- package/dist/chunk-XW3I5CJN.js +12 -0
- package/dist/chunk-XW56FKKJ.js +53 -0
- package/dist/chunk-Z3G5SW7R.cjs +1251 -0
- package/dist/chunk-ZVMAN7OO.cjs +431 -0
- package/dist/cli/index.cjs +1487 -0
- package/dist/common-ARWXbeS3.d.ts +36 -0
- package/dist/common-CwIFh2hK.d.cts +36 -0
- package/dist/dedupe-eHBIfUUD.d.cts +13 -0
- package/dist/dedupe-fw8aNtt4.d.ts +13 -0
- package/dist/handler-DTZ4Rzcf.d.ts +82 -0
- package/dist/handler-_00lctTI.d.cts +82 -0
- package/dist/index.cjs +277 -0
- package/dist/index.d.cts +187 -0
- package/dist/index.d.ts +187 -0
- package/dist/index.js +4 -0
- package/dist/next/client.cjs +113 -0
- package/dist/next/client.d.cts +26 -0
- package/dist/next/client.d.ts +26 -0
- package/dist/next/client.js +41 -0
- package/dist/next/config.cjs +275 -0
- package/dist/next/config.d.cts +193 -0
- package/dist/next/config.d.ts +193 -0
- package/dist/next/config.js +261 -0
- package/dist/next/index.cjs +148 -0
- package/dist/next/index.d.cts +32 -0
- package/dist/next/index.d.ts +32 -0
- package/dist/next/index.js +59 -0
- package/dist/node/index.cjs +257 -0
- package/dist/node/index.d.cts +145 -0
- package/dist/node/index.d.ts +145 -0
- package/dist/node/index.js +83 -0
- package/dist/options-0BhybO54.d.cts +47 -0
- package/dist/options-0BhybO54.d.ts +47 -0
- package/dist/react/index.cjs +107 -0
- package/dist/react/index.d.cts +84 -0
- package/dist/react/index.d.ts +84 -0
- package/dist/react/index.js +103 -0
- package/dist/scope-Bvh45bOf.d.cts +404 -0
- package/dist/scope-Bvh45bOf.d.ts +404 -0
- package/dist/server-edge-BPOGA3GH.cjs +51 -0
- package/dist/server-edge-GYKAJREU.js +48 -0
- package/dist/server-node-HYK2OB2J.js +24 -0
- package/dist/server-node-J2DBAHDV.cjs +27 -0
- package/dist/session-C_WzbEN2.d.cts +4 -0
- package/dist/session-C_WzbEN2.d.ts +4 -0
- package/dist/session-propagation-B7REA7uy.d.cts +30 -0
- package/dist/session-propagation-BnJjKJbR.d.ts +30 -0
- package/dist/starko.min.js +6 -0
- package/docs/browser.md +381 -0
- package/docs/configuration.md +269 -0
- package/docs/nextjs.md +312 -0
- package/docs/node.md +376 -0
- package/docs/other-backends.md +232 -0
- package/docs/privacy.md +112 -0
- package/docs/react.md +187 -0
- package/docs/source-maps.md +332 -0
- package/docs/troubleshooting.md +171 -0
- package/docs/widget.md +84 -0
- package/docs/wire-format.md +367 -0
- package/package.json +98 -4
|
@@ -0,0 +1,1151 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkTPSJGLR3_cjs = require('./chunk-TPSJGLR3.cjs');
|
|
4
|
+
var chunkZVMAN7OO_cjs = require('./chunk-ZVMAN7OO.cjs');
|
|
5
|
+
var chunkHADYYQNL_cjs = require('./chunk-HADYYQNL.cjs');
|
|
6
|
+
var chunkPYYWPIFL_cjs = require('./chunk-PYYWPIFL.cjs');
|
|
7
|
+
var chunkKN7H22EQ_cjs = require('./chunk-KN7H22EQ.cjs');
|
|
8
|
+
var chunkR7JLZ4WO_cjs = require('./chunk-R7JLZ4WO.cjs');
|
|
9
|
+
var util = require('util');
|
|
10
|
+
var fs = require('fs');
|
|
11
|
+
var path = require('path');
|
|
12
|
+
var url = require('url');
|
|
13
|
+
var dc = require('diagnostics_channel');
|
|
14
|
+
var http = require('http');
|
|
15
|
+
var https = require('https');
|
|
16
|
+
var os = require('os');
|
|
17
|
+
var worker_threads = require('worker_threads');
|
|
18
|
+
var zlib = require('zlib');
|
|
19
|
+
var async_hooks = require('async_hooks');
|
|
20
|
+
|
|
21
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
|
+
|
|
23
|
+
function _interopNamespace(e) {
|
|
24
|
+
if (e && e.__esModule) return e;
|
|
25
|
+
var n = Object.create(null);
|
|
26
|
+
if (e) {
|
|
27
|
+
Object.keys(e).forEach(function (k) {
|
|
28
|
+
if (k !== 'default') {
|
|
29
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
30
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () { return e[k]; }
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
n.default = e;
|
|
38
|
+
return Object.freeze(n);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var dc__namespace = /*#__PURE__*/_interopNamespace(dc);
|
|
42
|
+
var http__namespace = /*#__PURE__*/_interopNamespace(http);
|
|
43
|
+
var https__namespace = /*#__PURE__*/_interopNamespace(https);
|
|
44
|
+
var os__default = /*#__PURE__*/_interopDefault(os);
|
|
45
|
+
|
|
46
|
+
var LEVELS = { warn: "warning", error: "error" };
|
|
47
|
+
var MAX = 200;
|
|
48
|
+
var OPTS = { depth: 1, breakLength: Infinity, colors: false, customInspect: false, showProxy: true, getters: false, maxArrayLength: 10, maxStringLength: MAX };
|
|
49
|
+
function consoleText(args) {
|
|
50
|
+
if (!args.length) return "";
|
|
51
|
+
if (typeof args[0] === "string" && args[0].includes("%")) return chunkKN7H22EQ_cjs.truncate(util.formatWithOptions(OPTS, ...args.slice(0, 10)), MAX);
|
|
52
|
+
let out = "";
|
|
53
|
+
for (const a of args) {
|
|
54
|
+
out += (out ? " " : "") + (typeof a === "string" ? a : util.formatWithOptions(OPTS, a));
|
|
55
|
+
if (out.length >= MAX) break;
|
|
56
|
+
}
|
|
57
|
+
return chunkKN7H22EQ_cjs.truncate(out, MAX);
|
|
58
|
+
}
|
|
59
|
+
function consoleBreadcrumbsIntegration() {
|
|
60
|
+
const undo = [];
|
|
61
|
+
let active = false;
|
|
62
|
+
return {
|
|
63
|
+
name: "ConsoleBreadcrumbs",
|
|
64
|
+
setup(client) {
|
|
65
|
+
if (typeof console === "undefined") return;
|
|
66
|
+
active = true;
|
|
67
|
+
const con = console;
|
|
68
|
+
let inside2 = false;
|
|
69
|
+
for (const level of Object.keys(LEVELS)) {
|
|
70
|
+
const original = con[level];
|
|
71
|
+
if (typeof original !== "function") continue;
|
|
72
|
+
const wrapper = function(...args) {
|
|
73
|
+
if (active && !inside2 && client.isEnabled()) {
|
|
74
|
+
inside2 = true;
|
|
75
|
+
try {
|
|
76
|
+
const message = consoleText(args);
|
|
77
|
+
client.addBreadcrumb({ timestamp: Date.now(), type: "console", category: "console", level: LEVELS[level], message });
|
|
78
|
+
} catch {
|
|
79
|
+
} finally {
|
|
80
|
+
inside2 = false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return original.apply(this, args);
|
|
84
|
+
};
|
|
85
|
+
con[level] = wrapper;
|
|
86
|
+
undo.push(() => {
|
|
87
|
+
if (con[level] === wrapper) con[level] = original;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
teardown() {
|
|
92
|
+
active = false;
|
|
93
|
+
for (const u of undo.splice(0)) {
|
|
94
|
+
try {
|
|
95
|
+
u();
|
|
96
|
+
} catch {
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
var SOURCE_EXTENSION = /\.(?:[cm]?js|jsx|[cm]?ts|tsx)$/i;
|
|
103
|
+
function toPath(filename) {
|
|
104
|
+
try {
|
|
105
|
+
if (filename.startsWith("file://")) return url.fileURLToPath(filename);
|
|
106
|
+
} catch {
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
return filename.startsWith("/") || /^[A-Za-z]:[\\/]/.test(filename) ? filename : void 0;
|
|
110
|
+
}
|
|
111
|
+
var isFilesystemRoot = (p) => path.dirname(p) === p;
|
|
112
|
+
function resolveRoots(extra = []) {
|
|
113
|
+
const out = [];
|
|
114
|
+
const add = (r) => {
|
|
115
|
+
if (typeof r !== "string" || !r) return false;
|
|
116
|
+
try {
|
|
117
|
+
const real = fs.realpathSync(path.resolve(r));
|
|
118
|
+
if (isFilesystemRoot(real)) return false;
|
|
119
|
+
out.push(real);
|
|
120
|
+
return true;
|
|
121
|
+
} catch {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
if (!add(safeCwd())) add(mainModuleDir());
|
|
126
|
+
for (const r of extra) add(r);
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
function safeCwd() {
|
|
130
|
+
try {
|
|
131
|
+
return process.cwd();
|
|
132
|
+
} catch {
|
|
133
|
+
return void 0;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function mainModuleDir() {
|
|
137
|
+
try {
|
|
138
|
+
const main = typeof chunkR7JLZ4WO_cjs.__require === "function" ? chunkR7JLZ4WO_cjs.__require.main : void 0;
|
|
139
|
+
const file = main && main.filename || process.argv && process.argv[1];
|
|
140
|
+
return typeof file === "string" && file ? path.dirname(path.resolve(file)) : void 0;
|
|
141
|
+
} catch {
|
|
142
|
+
return void 0;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
var inside = (file, root) => {
|
|
146
|
+
const rel = path.relative(root, file);
|
|
147
|
+
return rel !== "" && !rel.startsWith("..") && !path.isAbsolute(rel);
|
|
148
|
+
};
|
|
149
|
+
function plausibleSource(path$1) {
|
|
150
|
+
return SOURCE_EXTENSION.test(path$1) && !path.basename(path$1).startsWith(".");
|
|
151
|
+
}
|
|
152
|
+
var allowedReal = (real, roots) => plausibleSource(real) && roots.some((r) => inside(real, r));
|
|
153
|
+
async function allowedSource(path, roots) {
|
|
154
|
+
if (!plausibleSource(path)) return void 0;
|
|
155
|
+
try {
|
|
156
|
+
const real = await fs.promises.realpath(path);
|
|
157
|
+
return allowedReal(real, roots) ? real : void 0;
|
|
158
|
+
} catch {
|
|
159
|
+
return void 0;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function allowedSourceSync(path, roots) {
|
|
163
|
+
if (!plausibleSource(path)) return void 0;
|
|
164
|
+
try {
|
|
165
|
+
const real = fs.realpathSync(path);
|
|
166
|
+
return allowedReal(real, roots) ? real : void 0;
|
|
167
|
+
} catch {
|
|
168
|
+
return void 0;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// src/node/integrations/context-lines.ts
|
|
173
|
+
var MINIFIED_LINE = 1e3;
|
|
174
|
+
var NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
175
|
+
var Lru = class {
|
|
176
|
+
constructor(maxItems, maxBytes) {
|
|
177
|
+
this.maxItems = maxItems;
|
|
178
|
+
this.maxBytes = maxBytes;
|
|
179
|
+
this.map = /* @__PURE__ */ new Map();
|
|
180
|
+
this.bytes = 0;
|
|
181
|
+
}
|
|
182
|
+
get(k) {
|
|
183
|
+
const e = this.map.get(k);
|
|
184
|
+
if (!e) return void 0;
|
|
185
|
+
this.map.delete(k);
|
|
186
|
+
this.map.set(k, e);
|
|
187
|
+
return e.v;
|
|
188
|
+
}
|
|
189
|
+
set(k, v, bytes) {
|
|
190
|
+
this.delete(k);
|
|
191
|
+
if (bytes > this.maxBytes) return;
|
|
192
|
+
this.map.set(k, { v, bytes });
|
|
193
|
+
this.bytes += bytes;
|
|
194
|
+
while (this.map.size > this.maxItems || this.bytes > this.maxBytes) this.delete(this.map.keys().next().value);
|
|
195
|
+
}
|
|
196
|
+
delete(k) {
|
|
197
|
+
const e = this.map.get(k);
|
|
198
|
+
if (!e) return;
|
|
199
|
+
this.map.delete(k);
|
|
200
|
+
this.bytes -= e.bytes;
|
|
201
|
+
}
|
|
202
|
+
clear() {
|
|
203
|
+
this.map.clear();
|
|
204
|
+
this.bytes = 0;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
function contextLinesIntegration(opts = {}) {
|
|
208
|
+
const around = Math.max(0, Math.min(chunkR7JLZ4WO_cjs.LIMITS.MAX_CONTEXT_LINES, Math.floor(opts.lines ?? chunkR7JLZ4WO_cjs.LIMITS.MAX_CONTEXT_LINES)));
|
|
209
|
+
const maxFileBytes = opts.maxFileBytes ?? 1024 * 1024;
|
|
210
|
+
const maxFiles = opts.maxFiles ?? 10;
|
|
211
|
+
const cache = new Lru(Math.max(0, opts.cacheSize ?? 100), Math.max(0, opts.cacheBytes ?? 8 * 1024 * 1024));
|
|
212
|
+
const reading = /* @__PURE__ */ new Map();
|
|
213
|
+
let roots;
|
|
214
|
+
const load = async (path) => {
|
|
215
|
+
if (/\.min\.[cm]?[jt]s$/i.test(path)) return { lines: null, bytes: 64 };
|
|
216
|
+
roots = roots || resolveRoots(opts.roots);
|
|
217
|
+
const real = await allowedSource(path, roots);
|
|
218
|
+
if (!real) return { lines: null, bytes: 64 };
|
|
219
|
+
const stat = await fs.promises.stat(real);
|
|
220
|
+
if (!stat.isFile() || stat.size > maxFileBytes) return { lines: null, bytes: 64 };
|
|
221
|
+
const text = await fs.promises.readFile(real, "utf8");
|
|
222
|
+
const all = text.split(/\r?\n/);
|
|
223
|
+
if (all.some((l) => l.length > MINIFIED_LINE)) return { lines: null, bytes: 64 };
|
|
224
|
+
return { lines: all, bytes: text.length * 2 };
|
|
225
|
+
};
|
|
226
|
+
const read = (path) => {
|
|
227
|
+
const hit = cache.get(path);
|
|
228
|
+
if (hit !== void 0) return Promise.resolve(hit);
|
|
229
|
+
const running = reading.get(path);
|
|
230
|
+
if (running) return running;
|
|
231
|
+
const p = load(path).catch(() => ({ lines: null, bytes: 64 })).then(({ lines, bytes }) => {
|
|
232
|
+
cache.set(path, lines, bytes);
|
|
233
|
+
reading.delete(path);
|
|
234
|
+
return lines;
|
|
235
|
+
});
|
|
236
|
+
reading.set(path, p);
|
|
237
|
+
return p;
|
|
238
|
+
};
|
|
239
|
+
const fill = (f, lines) => {
|
|
240
|
+
const i = f.lineno - 1;
|
|
241
|
+
if (i < 0 || i >= lines.length) return;
|
|
242
|
+
const cut = (l) => chunkKN7H22EQ_cjs.truncate(l, chunkR7JLZ4WO_cjs.LIMITS.MAX_CONTEXT_LINE);
|
|
243
|
+
f.pre_context = lines.slice(Math.max(0, i - around), i).map(cut);
|
|
244
|
+
f.context_line = cut(lines[i]);
|
|
245
|
+
f.post_context = lines.slice(i + 1, i + 1 + around).map(cut);
|
|
246
|
+
};
|
|
247
|
+
return {
|
|
248
|
+
name: "ContextLines",
|
|
249
|
+
setup() {
|
|
250
|
+
try {
|
|
251
|
+
roots = resolveRoots(opts.roots);
|
|
252
|
+
} catch {
|
|
253
|
+
roots = [];
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
clearCache: () => cache.clear(),
|
|
257
|
+
async addContextLines(event) {
|
|
258
|
+
try {
|
|
259
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
260
|
+
for (const ex of event.exception_list || []) {
|
|
261
|
+
for (const f of ex.stacktrace?.frames || []) {
|
|
262
|
+
if (f.in_app === false || !f.filename || !f.lineno || f.context_line !== void 0) continue;
|
|
263
|
+
if (!opts.includeNodeModules && NODE_MODULES.test(f.filename)) continue;
|
|
264
|
+
const path = toPath(f.filename);
|
|
265
|
+
if (!path) continue;
|
|
266
|
+
const list = byFile.get(path);
|
|
267
|
+
if (list) list.push(f);
|
|
268
|
+
else if (byFile.size < maxFiles) byFile.set(path, [f]);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
await Promise.all(
|
|
272
|
+
[...byFile].map(async ([path, frames]) => {
|
|
273
|
+
const lines = await read(path);
|
|
274
|
+
if (lines) for (const f of frames) fill(f, lines);
|
|
275
|
+
})
|
|
276
|
+
);
|
|
277
|
+
} catch {
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
var MODES = /* @__PURE__ */ new Set(["throw", "strict", "warn", "warn-with-error-code", "none"]);
|
|
283
|
+
var FLAGS = ["--unhandled-rejections", "--unhandled_rejections"];
|
|
284
|
+
function splitNodeOptions(s) {
|
|
285
|
+
const out = [];
|
|
286
|
+
let cur = "";
|
|
287
|
+
let quoted = false;
|
|
288
|
+
for (let i = 0; i < s.length; i++) {
|
|
289
|
+
const c = s[i];
|
|
290
|
+
if (c === "\\" && quoted && i + 1 < s.length) cur += s[++i];
|
|
291
|
+
else if (c === '"') quoted = !quoted;
|
|
292
|
+
else if (c === " " && !quoted) {
|
|
293
|
+
if (cur) out.push(cur);
|
|
294
|
+
cur = "";
|
|
295
|
+
} else cur += c;
|
|
296
|
+
}
|
|
297
|
+
if (cur) out.push(cur);
|
|
298
|
+
return out;
|
|
299
|
+
}
|
|
300
|
+
function findMode(args) {
|
|
301
|
+
let mode;
|
|
302
|
+
for (let i = 0; i < args.length; i++) {
|
|
303
|
+
const a = args[i];
|
|
304
|
+
const flag = FLAGS.find((f) => a === f || a.startsWith(`${f}=`));
|
|
305
|
+
if (!flag) continue;
|
|
306
|
+
const v = a === flag ? args[++i] : a.slice(flag.length + 1);
|
|
307
|
+
if (MODES.has(v)) mode = v;
|
|
308
|
+
}
|
|
309
|
+
return mode;
|
|
310
|
+
}
|
|
311
|
+
function getUnhandledRejectionMode(execArgv = process.execArgv || [], nodeOptions = process.env.NODE_OPTIONS) {
|
|
312
|
+
try {
|
|
313
|
+
return findMode(execArgv) ?? findMode(splitNodeOptions(nodeOptions || "")) ?? "throw";
|
|
314
|
+
} catch {
|
|
315
|
+
return "throw";
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
var SDK_LISTENER = /* @__PURE__ */ Symbol.for("starko.sdk.listener");
|
|
319
|
+
function markListener(fn) {
|
|
320
|
+
try {
|
|
321
|
+
fn[SDK_LISTENER] = true;
|
|
322
|
+
} catch {
|
|
323
|
+
}
|
|
324
|
+
return fn;
|
|
325
|
+
}
|
|
326
|
+
var isSdkListener = (fn) => typeof fn === "function" && fn[SDK_LISTENER] === true;
|
|
327
|
+
function isOtherSdkListener(fn) {
|
|
328
|
+
try {
|
|
329
|
+
if (typeof fn !== "function") return false;
|
|
330
|
+
const f = fn;
|
|
331
|
+
return f._errorHandler === true || f._posthogErrorHandler === true;
|
|
332
|
+
} catch {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
var isNextRejectionFilter = (fn) => typeof fn === "function" && fn.name === "filteringUnhandledRejectionHandler";
|
|
337
|
+
function hostListeners(event, opts = {}) {
|
|
338
|
+
try {
|
|
339
|
+
return process.listeners(event).filter(
|
|
340
|
+
(l) => !isSdkListener(l) && l.name !== "domainUncaughtExceptionClear" && (opts.otherSdks !== false || !isOtherSdkListener(l))
|
|
341
|
+
).length;
|
|
342
|
+
} catch {
|
|
343
|
+
return 0;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
var FATAL_KEY = /* @__PURE__ */ Symbol.for("starko.sdk.fatal.v1");
|
|
347
|
+
function fatal() {
|
|
348
|
+
const g = globalThis;
|
|
349
|
+
return g[FATAL_KEY] || (g[FATAL_KEY] = { exiting: false });
|
|
350
|
+
}
|
|
351
|
+
var isExiting = () => fatal().exiting;
|
|
352
|
+
function fatalTimeout(client) {
|
|
353
|
+
const v = client.options.fatalFlushTimeout;
|
|
354
|
+
return typeof v === "number" && isFinite(v) && v >= 0 ? v : 1e3;
|
|
355
|
+
}
|
|
356
|
+
function shutdownTimeout(client, fallback = 2e3) {
|
|
357
|
+
const v = client.options.shutdownTimeout;
|
|
358
|
+
return typeof v === "number" && isFinite(v) && v >= 0 ? v : fallback;
|
|
359
|
+
}
|
|
360
|
+
function exitAfterFatal(client, error, viaRejection, timeoutMs) {
|
|
361
|
+
const st = fatal();
|
|
362
|
+
if (st.exiting) {
|
|
363
|
+
printFatal(error, viaRejection);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
st.exiting = true;
|
|
367
|
+
printFatal(error, viaRejection);
|
|
368
|
+
let done = false;
|
|
369
|
+
const exit = () => {
|
|
370
|
+
if (done) return;
|
|
371
|
+
done = true;
|
|
372
|
+
clearTimeout(hold);
|
|
373
|
+
try {
|
|
374
|
+
if (abortOnUncaught()) process.abort();
|
|
375
|
+
} catch {
|
|
376
|
+
}
|
|
377
|
+
process.exit(1);
|
|
378
|
+
};
|
|
379
|
+
const hold = setTimeout(exit, Math.max(0, timeoutMs) + 100);
|
|
380
|
+
try {
|
|
381
|
+
const skip = client.skipRemoteConfig;
|
|
382
|
+
if (typeof skip === "function") skip.call(client);
|
|
383
|
+
client.flush(timeoutMs).then(exit, exit);
|
|
384
|
+
} catch {
|
|
385
|
+
exit();
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
function abortOnUncaught() {
|
|
389
|
+
try {
|
|
390
|
+
return (process.execArgv || []).includes("--abort-on-uncaught-exception") || /(?:^|\s)--abort[-_]on[-_]uncaught[-_]exception(?:\s|$)/.test(process.env.NODE_OPTIONS || "");
|
|
391
|
+
} catch {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
function printFatal(error, viaRejection) {
|
|
396
|
+
let text;
|
|
397
|
+
try {
|
|
398
|
+
text = formatFatal(error, viaRejection);
|
|
399
|
+
} catch {
|
|
400
|
+
text = "\nUncaught exception (it could not be printed)\n";
|
|
401
|
+
}
|
|
402
|
+
try {
|
|
403
|
+
fs.writeSync(2, text);
|
|
404
|
+
} catch {
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
function formatFatal(error, viaRejection) {
|
|
408
|
+
const node = `
|
|
409
|
+
Node.js ${process.version}
|
|
410
|
+
`;
|
|
411
|
+
const errorLike = isNativeError(error);
|
|
412
|
+
const arrow = excerpt(errorLike ? error : void 0, viaRejection);
|
|
413
|
+
if (errorLike) return `${arrow}
|
|
414
|
+
${inspectSafe(error)}
|
|
415
|
+
${node}`;
|
|
416
|
+
const isObject = error !== null && (typeof error === "object" || typeof error === "function");
|
|
417
|
+
if (isObject) return `
|
|
418
|
+
${arrow}${inspectSafe(error)}
|
|
419
|
+
${node}`;
|
|
420
|
+
return `
|
|
421
|
+
${arrow}${chunkKN7H22EQ_cjs.safeString(error)}
|
|
422
|
+
(Use \`${argv0()} --trace-uncaught ...\` to show where the exception was thrown)
|
|
423
|
+
${node}`;
|
|
424
|
+
}
|
|
425
|
+
function isNativeError(v) {
|
|
426
|
+
try {
|
|
427
|
+
const t = util.types.isNativeError;
|
|
428
|
+
return typeof t === "function" ? t(v) : v instanceof Error;
|
|
429
|
+
} catch {
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
function argv0() {
|
|
434
|
+
try {
|
|
435
|
+
return path.basename(process.argv0 || "node").replace(/\.exe$/i, "") || "node";
|
|
436
|
+
} catch {
|
|
437
|
+
return "node";
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
function inspectSafe(v) {
|
|
441
|
+
try {
|
|
442
|
+
return util.inspect(v, { colors: stderrColors(), customInspect: false, depth: Math.max(Number(util.inspect.defaultOptions.depth) || 2, 5) });
|
|
443
|
+
} catch {
|
|
444
|
+
try {
|
|
445
|
+
return String(v.stack ?? v);
|
|
446
|
+
} catch {
|
|
447
|
+
return "[uninspectable]";
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function stderrColors() {
|
|
452
|
+
try {
|
|
453
|
+
const s = process.stderr;
|
|
454
|
+
return !!s.isTTY && (typeof s.hasColors === "function" ? s.hasColors() : true);
|
|
455
|
+
} catch {
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function excerpt(error, viaRejection) {
|
|
460
|
+
try {
|
|
461
|
+
if (!error) return "";
|
|
462
|
+
const stack = error.stack;
|
|
463
|
+
if (typeof stack !== "string") return "";
|
|
464
|
+
const top = chunkPYYWPIFL_cjs.nodeStackParser(stack)[0];
|
|
465
|
+
if (!top || !top.filename || !top.lineno) return "";
|
|
466
|
+
const path = toPath(top.filename);
|
|
467
|
+
const real = path && allowedSourceSync(path, resolveRoots());
|
|
468
|
+
if (!real) return "";
|
|
469
|
+
const st = fs.statSync(real);
|
|
470
|
+
if (!st.isFile() || st.size > 1024 * 1024) return "";
|
|
471
|
+
const line = fs.readFileSync(real, "utf8").split(/\r?\n/)[top.lineno - 1];
|
|
472
|
+
if (line === void 0 || line.length > 1e3) return "";
|
|
473
|
+
let col = Math.max(0, (top.colno || 1) - 1);
|
|
474
|
+
if (!viaRejection) {
|
|
475
|
+
const t = line.lastIndexOf("throw", col);
|
|
476
|
+
if (t >= 0 && /\bthrow\b/.test(line.slice(t, t + 6))) col = t;
|
|
477
|
+
}
|
|
478
|
+
return `${top.filename}:${top.lineno}
|
|
479
|
+
${line}
|
|
480
|
+
${" ".repeat(col)}^
|
|
481
|
+
`;
|
|
482
|
+
} catch {
|
|
483
|
+
return "";
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// src/node/integrations/flush-on-exit.ts
|
|
488
|
+
var SIGNALS = ["SIGTERM", "SIGINT"];
|
|
489
|
+
function flushOnExitIntegration(opts = {}) {
|
|
490
|
+
const off = [];
|
|
491
|
+
return {
|
|
492
|
+
name: "FlushOnExit",
|
|
493
|
+
setup(client) {
|
|
494
|
+
if (typeof process === "undefined" || typeof process.on !== "function") return;
|
|
495
|
+
const hasPending = () => {
|
|
496
|
+
const f = chunkKN7H22EQ_cjs.clientMethod(client, "hasPending");
|
|
497
|
+
return f ? f() : true;
|
|
498
|
+
};
|
|
499
|
+
const flushHeld = (ms) => {
|
|
500
|
+
const hold = setTimeout(() => void 0, ms + 50);
|
|
501
|
+
const skip = chunkKN7H22EQ_cjs.clientMethod(client, "skipRemoteConfig");
|
|
502
|
+
if (skip) skip();
|
|
503
|
+
const flush = chunkKN7H22EQ_cjs.clientMethod(client, "flush");
|
|
504
|
+
const p = flush ? flush(ms).catch(() => false) : Promise.resolve(false);
|
|
505
|
+
return p.then((ok) => {
|
|
506
|
+
clearTimeout(hold);
|
|
507
|
+
if (!ok) {
|
|
508
|
+
const abort = chunkKN7H22EQ_cjs.clientMethod(client, "abortRequests");
|
|
509
|
+
if (abort) abort();
|
|
510
|
+
}
|
|
511
|
+
return ok;
|
|
512
|
+
});
|
|
513
|
+
};
|
|
514
|
+
let busy = false;
|
|
515
|
+
let tries = 0;
|
|
516
|
+
const onBeforeExit = markListener(() => {
|
|
517
|
+
try {
|
|
518
|
+
if (busy || tries >= 1 || !hasPending()) return;
|
|
519
|
+
busy = true;
|
|
520
|
+
tries++;
|
|
521
|
+
flushHeld(shutdownTimeout(client)).then(
|
|
522
|
+
(ok) => {
|
|
523
|
+
busy = false;
|
|
524
|
+
if (ok) tries = 0;
|
|
525
|
+
},
|
|
526
|
+
() => {
|
|
527
|
+
busy = false;
|
|
528
|
+
}
|
|
529
|
+
);
|
|
530
|
+
} catch {
|
|
531
|
+
busy = false;
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
process.on("beforeExit", onBeforeExit);
|
|
535
|
+
off.push(() => process.removeListener("beforeExit", onBeforeExit));
|
|
536
|
+
if (opts.signals === false || typeof process.kill !== "function") return;
|
|
537
|
+
for (const sig of SIGNALS) {
|
|
538
|
+
let handling = false;
|
|
539
|
+
const raise = () => {
|
|
540
|
+
process.removeListener(sig, onSignal);
|
|
541
|
+
try {
|
|
542
|
+
process.kill(process.pid, sig);
|
|
543
|
+
} catch {
|
|
544
|
+
process.exit(sig === "SIGINT" ? 130 : 143);
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
const onSignal = markListener(() => {
|
|
548
|
+
try {
|
|
549
|
+
if (process.listeners(sig).some((l) => !isSdkListener(l))) return;
|
|
550
|
+
if (handling) return;
|
|
551
|
+
handling = true;
|
|
552
|
+
if (!hasPending()) return raise();
|
|
553
|
+
flushHeld(shutdownTimeout(client)).then(raise, raise);
|
|
554
|
+
} catch {
|
|
555
|
+
raise();
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
process.on(sig, onSignal);
|
|
559
|
+
off.push(() => process.removeListener(sig, onSignal));
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
teardown() {
|
|
563
|
+
for (const f of off.splice(0)) {
|
|
564
|
+
try {
|
|
565
|
+
f();
|
|
566
|
+
} catch {
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
var REQUEST_START = "http.server.request.start";
|
|
573
|
+
var HTTP2_STREAM_START = "http2.server.stream.start";
|
|
574
|
+
var SERVER_SOCKET = "net.server.socket";
|
|
575
|
+
var WRAPPED = /* @__PURE__ */ Symbol.for("starko.sdk.http.emit");
|
|
576
|
+
var SCOPED = /* @__PURE__ */ Symbol.for("starko.sdk.http.scoped");
|
|
577
|
+
var ENTRY = {
|
|
578
|
+
request: "req",
|
|
579
|
+
checkContinue: "req",
|
|
580
|
+
checkExpectation: "req",
|
|
581
|
+
upgrade: "req",
|
|
582
|
+
connect: "req",
|
|
583
|
+
stream: "stream"
|
|
584
|
+
};
|
|
585
|
+
var STATE_KEY = /* @__PURE__ */ Symbol.for("starko.sdk.http.state.v2");
|
|
586
|
+
function state() {
|
|
587
|
+
const g = globalThis;
|
|
588
|
+
return g[STATE_KEY] || (g[STATE_KEY] = { active: 0, subscribed: false });
|
|
589
|
+
}
|
|
590
|
+
function markOnce(obj, key) {
|
|
591
|
+
if (obj[key]) return false;
|
|
592
|
+
Object.defineProperty(obj, key, { value: true, enumerable: false, configurable: true });
|
|
593
|
+
return true;
|
|
594
|
+
}
|
|
595
|
+
function refuse(target) {
|
|
596
|
+
try {
|
|
597
|
+
const r = target;
|
|
598
|
+
const t = r.stream || r.socket || r;
|
|
599
|
+
if (t && typeof t.destroy === "function") t.destroy();
|
|
600
|
+
} catch {
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
function streamData(headers) {
|
|
604
|
+
const h = headers && typeof headers === "object" ? headers : {};
|
|
605
|
+
return chunkZVMAN7OO_cjs.requestDataFrom({ method: h[":method"], url: h[":path"], headers: h });
|
|
606
|
+
}
|
|
607
|
+
function scoped(original, self, event, args) {
|
|
608
|
+
let entered = false;
|
|
609
|
+
try {
|
|
610
|
+
const kind = ENTRY[event];
|
|
611
|
+
const target = args[0];
|
|
612
|
+
if (!state().active || !target || typeof target !== "object") return original.apply(self, [event, ...args]);
|
|
613
|
+
if (kind === "req") {
|
|
614
|
+
const stream = target.stream;
|
|
615
|
+
const current = chunkZVMAN7OO_cjs.getCurrentStore();
|
|
616
|
+
if (stream && current && current.source === stream) {
|
|
617
|
+
if (markOnce(target, SCOPED)) {
|
|
618
|
+
chunkZVMAN7OO_cjs.linkRequest(target, current);
|
|
619
|
+
current.source = target;
|
|
620
|
+
current.request = () => chunkZVMAN7OO_cjs.requestDataFrom(target);
|
|
621
|
+
}
|
|
622
|
+
return original.apply(self, [event, ...args]);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
if (!markOnce(target, SCOPED)) return original.apply(self, [event, ...args]);
|
|
626
|
+
if (isExiting()) {
|
|
627
|
+
refuse(target);
|
|
628
|
+
return true;
|
|
629
|
+
}
|
|
630
|
+
const headers = args[1];
|
|
631
|
+
return chunkZVMAN7OO_cjs.openRequestScope(
|
|
632
|
+
() => {
|
|
633
|
+
entered = true;
|
|
634
|
+
return original.apply(self, [event, ...args]);
|
|
635
|
+
},
|
|
636
|
+
kind === "stream" ? () => streamData(headers) : () => chunkZVMAN7OO_cjs.requestDataFrom(target),
|
|
637
|
+
target
|
|
638
|
+
);
|
|
639
|
+
} catch (err) {
|
|
640
|
+
if (entered) throw err;
|
|
641
|
+
return original.apply(self, [event, ...args]);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
function instrumentServer(server) {
|
|
645
|
+
try {
|
|
646
|
+
if (!server || typeof server !== "object") return;
|
|
647
|
+
const s = server;
|
|
648
|
+
const original = s.emit;
|
|
649
|
+
if (typeof original !== "function" || original[WRAPPED]) return;
|
|
650
|
+
const wrapped = function(event, ...args) {
|
|
651
|
+
if (typeof event !== "string" || !(event in ENTRY)) return original.apply(this, [event, ...args]);
|
|
652
|
+
return scoped(original, this, event, args);
|
|
653
|
+
};
|
|
654
|
+
Object.defineProperty(wrapped, WRAPPED, { value: true });
|
|
655
|
+
s.emit = wrapped;
|
|
656
|
+
} catch {
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
function isHttpServer(server) {
|
|
660
|
+
try {
|
|
661
|
+
if (!server || typeof server !== "object") return false;
|
|
662
|
+
if (server instanceof http.Server || server instanceof https.Server) return true;
|
|
663
|
+
const name = server.constructor?.name;
|
|
664
|
+
return name === "Http2Server" || name === "Http2SecureServer";
|
|
665
|
+
} catch {
|
|
666
|
+
return false;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
function onServerSocket(message) {
|
|
670
|
+
try {
|
|
671
|
+
if (!state().active) return;
|
|
672
|
+
const socket = message.socket;
|
|
673
|
+
const server = socket && (socket.server || socket._server);
|
|
674
|
+
if (!isHttpServer(server)) return;
|
|
675
|
+
chunkZVMAN7OO_cjs.markServing();
|
|
676
|
+
instrumentServer(server);
|
|
677
|
+
} catch {
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
function onRequestStart(message) {
|
|
681
|
+
try {
|
|
682
|
+
if (!state().active) return;
|
|
683
|
+
chunkZVMAN7OO_cjs.markServing();
|
|
684
|
+
instrumentServer(message.server);
|
|
685
|
+
} catch {
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
function onHttp2Stream(message) {
|
|
689
|
+
try {
|
|
690
|
+
if (!state().active) return;
|
|
691
|
+
const stream = message.stream;
|
|
692
|
+
chunkZVMAN7OO_cjs.markServing();
|
|
693
|
+
instrumentServer(stream && stream.session && stream.session.server);
|
|
694
|
+
} catch {
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
function subscribe2(name, fn) {
|
|
698
|
+
if (typeof dc__namespace.subscribe === "function") dc__namespace.subscribe(name, fn);
|
|
699
|
+
else dc__namespace.channel(name).subscribe(fn);
|
|
700
|
+
}
|
|
701
|
+
function httpServerIntegration() {
|
|
702
|
+
let on = false;
|
|
703
|
+
return {
|
|
704
|
+
name: "HttpServer",
|
|
705
|
+
setup() {
|
|
706
|
+
try {
|
|
707
|
+
const st = state();
|
|
708
|
+
if (!st.subscribed) {
|
|
709
|
+
subscribe2(SERVER_SOCKET, onServerSocket);
|
|
710
|
+
subscribe2(REQUEST_START, onRequestStart);
|
|
711
|
+
subscribe2(HTTP2_STREAM_START, onHttp2Stream);
|
|
712
|
+
st.subscribed = true;
|
|
713
|
+
}
|
|
714
|
+
st.active++;
|
|
715
|
+
on = true;
|
|
716
|
+
} catch {
|
|
717
|
+
}
|
|
718
|
+
},
|
|
719
|
+
teardown() {
|
|
720
|
+
if (on) state().active = Math.max(0, state().active - 1);
|
|
721
|
+
on = false;
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
var OS_NAMES = { darwin: "macOS", linux: "Linux", win32: "Windows", freebsd: "FreeBSD", openbsd: "OpenBSD", sunos: "SunOS", aix: "AIX" };
|
|
726
|
+
function nodeContextIntegration() {
|
|
727
|
+
let runtime;
|
|
728
|
+
let osCtx;
|
|
729
|
+
let serverName;
|
|
730
|
+
return {
|
|
731
|
+
name: "NodeContext",
|
|
732
|
+
setup(client) {
|
|
733
|
+
try {
|
|
734
|
+
runtime = { name: "node", version: process.version };
|
|
735
|
+
osCtx = { name: OS_NAMES[process.platform] || process.platform, version: os__default.default.release(), kernel_version: os__default.default.release(), arch: process.arch };
|
|
736
|
+
const configured = client.options.serverName;
|
|
737
|
+
serverName = typeof configured === "string" && configured ? configured : os__default.default.hostname();
|
|
738
|
+
} catch {
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
processEvent(event) {
|
|
742
|
+
const contexts = { ...event.contexts };
|
|
743
|
+
if (runtime && !contexts.runtime) contexts.runtime = runtime;
|
|
744
|
+
if (osCtx && !contexts.os) contexts.os = osCtx;
|
|
745
|
+
event.contexts = contexts;
|
|
746
|
+
if (serverName && !event.server_name) event.server_name = serverName;
|
|
747
|
+
return event;
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
function propagateInWorker(client, error, removeListener, timeoutMs) {
|
|
752
|
+
let done = false;
|
|
753
|
+
const rethrow = () => {
|
|
754
|
+
if (done) return;
|
|
755
|
+
done = true;
|
|
756
|
+
clearTimeout(hold);
|
|
757
|
+
removeListener();
|
|
758
|
+
setImmediate(() => {
|
|
759
|
+
throw error;
|
|
760
|
+
});
|
|
761
|
+
};
|
|
762
|
+
const hold = setTimeout(rethrow, Math.max(0, timeoutMs) + 100);
|
|
763
|
+
try {
|
|
764
|
+
const skip = client.skipRemoteConfig;
|
|
765
|
+
if (typeof skip === "function") skip.call(client);
|
|
766
|
+
client.flush(timeoutMs).then(rethrow, rethrow);
|
|
767
|
+
} catch {
|
|
768
|
+
rethrow();
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
function safeCapture(client, error, fromRejection, level) {
|
|
772
|
+
try {
|
|
773
|
+
client.captureException(error, { mechanism: { type: fromRejection ? "onunhandledrejection" : "onuncaughtexception", handled: false }, level });
|
|
774
|
+
} catch (err) {
|
|
775
|
+
client.logger.warn("uncaughtException capture failed", err);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
function onUncaughtExceptionIntegration() {
|
|
779
|
+
const off = [];
|
|
780
|
+
return {
|
|
781
|
+
name: "OnUncaughtException",
|
|
782
|
+
setup(client) {
|
|
783
|
+
if (typeof process === "undefined" || typeof process.on !== "function") return;
|
|
784
|
+
const mode = getUnhandledRejectionMode();
|
|
785
|
+
const worker = !worker_threads.isMainThread;
|
|
786
|
+
let propagating = false;
|
|
787
|
+
const handler = markListener((error, origin) => {
|
|
788
|
+
const fromRejection = origin === "unhandledRejection";
|
|
789
|
+
if (worker) {
|
|
790
|
+
if (propagating) return;
|
|
791
|
+
if (hostListeners("uncaughtException", { otherSdks: false }) > 0) {
|
|
792
|
+
safeCapture(client, error, fromRejection, "error");
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
propagating = true;
|
|
796
|
+
safeCapture(client, error, fromRejection, "fatal");
|
|
797
|
+
propagateInWorker(client, error, () => process.removeListener("uncaughtException", handler), fatalTimeout(client));
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
const already = isExiting();
|
|
801
|
+
const fatal2 = already || hostListeners("uncaughtException", { otherSdks: false }) === 0;
|
|
802
|
+
try {
|
|
803
|
+
client.captureException(error, {
|
|
804
|
+
mechanism: { type: fromRejection ? "onunhandledrejection" : "onuncaughtexception", handled: false },
|
|
805
|
+
level: fatal2 ? "fatal" : "error"
|
|
806
|
+
});
|
|
807
|
+
} catch (err) {
|
|
808
|
+
client.logger.warn("uncaughtException capture failed", err);
|
|
809
|
+
}
|
|
810
|
+
if (!fatal2) return;
|
|
811
|
+
if (fromRejection && mode === "strict" && !already) {
|
|
812
|
+
try {
|
|
813
|
+
const absorb = markListener(() => void 0);
|
|
814
|
+
process.once("unhandledRejection", absorb);
|
|
815
|
+
setImmediate(() => process.removeListener("unhandledRejection", absorb));
|
|
816
|
+
} catch {
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
try {
|
|
820
|
+
exitAfterFatal(client, error, fromRejection, fatalTimeout(client));
|
|
821
|
+
} catch {
|
|
822
|
+
try {
|
|
823
|
+
process.exit(1);
|
|
824
|
+
} catch {
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
process.on("uncaughtException", handler);
|
|
829
|
+
off.push(() => process.removeListener("uncaughtException", handler));
|
|
830
|
+
},
|
|
831
|
+
teardown() {
|
|
832
|
+
if (isExiting()) return;
|
|
833
|
+
for (const f of off.splice(0)) f();
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
// src/node/integrations/unhandled-rejection.ts
|
|
839
|
+
var NEXT_FILTER = /* @__PURE__ */ Symbol.for("next.unhandledRejectionFilter");
|
|
840
|
+
function aloneBehindNextFilter() {
|
|
841
|
+
try {
|
|
842
|
+
if (!globalThis[NEXT_FILTER]) return false;
|
|
843
|
+
const all = process.listeners("unhandledRejection");
|
|
844
|
+
return all.some(isNextRejectionFilter) && all.every((l) => isNextRejectionFilter(l) || isSdkListener(l)) && !all.some(isOtherSdkListener);
|
|
845
|
+
} catch {
|
|
846
|
+
return false;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
function onUnhandledRejectionIntegration(opts = {}) {
|
|
850
|
+
const off = [];
|
|
851
|
+
return {
|
|
852
|
+
name: "OnUnhandledRejection",
|
|
853
|
+
setup(client) {
|
|
854
|
+
if (typeof process === "undefined" || typeof process.on !== "function") return;
|
|
855
|
+
const mode = opts.mode || getUnhandledRejectionMode();
|
|
856
|
+
if (mode === "strict") return;
|
|
857
|
+
const capture = (reason) => {
|
|
858
|
+
try {
|
|
859
|
+
client.captureException(reason, { mechanism: { type: "onunhandledrejection", handled: false }, level: "error" });
|
|
860
|
+
} catch (err) {
|
|
861
|
+
client.logger.warn("unhandledRejection capture failed", err);
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
const listener = markListener((reason) => {
|
|
865
|
+
capture(reason);
|
|
866
|
+
if (mode === "throw" && aloneBehindNextFilter()) {
|
|
867
|
+
try {
|
|
868
|
+
console.error("Unhandled Rejection:", reason);
|
|
869
|
+
} catch {
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
if (mode === "warn-with-error-code" && hostListeners("unhandledRejection") === 0) {
|
|
873
|
+
try {
|
|
874
|
+
process.emitWarning(isErrorLikeStack(reason), "UnhandledPromiseRejectionWarning");
|
|
875
|
+
process.emitWarning(
|
|
876
|
+
"Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().",
|
|
877
|
+
"UnhandledPromiseRejectionWarning"
|
|
878
|
+
);
|
|
879
|
+
process.exitCode = 1;
|
|
880
|
+
} catch {
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
const installed = () => process.listeners("unhandledRejection").includes(listener);
|
|
885
|
+
const add = () => {
|
|
886
|
+
if (!installed()) process.prependListener("unhandledRejection", listener);
|
|
887
|
+
};
|
|
888
|
+
const remove = () => process.removeListener("unhandledRejection", listener);
|
|
889
|
+
off.push(remove);
|
|
890
|
+
if (mode !== "throw") {
|
|
891
|
+
add();
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
const onNew = markListener((event, fn) => {
|
|
895
|
+
if (event === "unhandledRejection" && !isSdkListener(fn)) add();
|
|
896
|
+
});
|
|
897
|
+
const onRemoved = markListener((event) => {
|
|
898
|
+
if (event === "unhandledRejection" && hostListeners("unhandledRejection") === 0) remove();
|
|
899
|
+
});
|
|
900
|
+
process.on("newListener", onNew);
|
|
901
|
+
process.on("removeListener", onRemoved);
|
|
902
|
+
off.push(
|
|
903
|
+
() => process.removeListener("newListener", onNew),
|
|
904
|
+
() => process.removeListener("removeListener", onRemoved)
|
|
905
|
+
);
|
|
906
|
+
if (hostListeners("unhandledRejection") > 0) add();
|
|
907
|
+
},
|
|
908
|
+
teardown() {
|
|
909
|
+
for (const f of off.splice(0)) {
|
|
910
|
+
try {
|
|
911
|
+
f();
|
|
912
|
+
} catch {
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
function isErrorLikeStack(reason) {
|
|
919
|
+
try {
|
|
920
|
+
const stack = reason && typeof reason === "object" ? reason.stack : void 0;
|
|
921
|
+
return typeof stack === "string" ? stack : chunkKN7H22EQ_cjs.safeString(reason);
|
|
922
|
+
} catch {
|
|
923
|
+
return "[unhandled rejection]";
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
var CONNECT_TIMEOUT_MS = 3e3;
|
|
927
|
+
var SEND_TIMEOUT_MS = 1e4;
|
|
928
|
+
var CONFIG_TIMEOUT_MS = 3e3;
|
|
929
|
+
var MAX_RESPONSE = 64 * 1024;
|
|
930
|
+
function gzipAsync(text) {
|
|
931
|
+
return new Promise((resolve2) => {
|
|
932
|
+
try {
|
|
933
|
+
zlib.gzip(Buffer.from(text, "utf8"), (err, out) => resolve2(err ? void 0 : out));
|
|
934
|
+
} catch {
|
|
935
|
+
resolve2(void 0);
|
|
936
|
+
}
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
function request(inflight, url, method, headers, body, timeoutMs) {
|
|
940
|
+
return new Promise((resolve2) => {
|
|
941
|
+
let settled = false;
|
|
942
|
+
let req;
|
|
943
|
+
const timers = [];
|
|
944
|
+
const finish = (a) => {
|
|
945
|
+
if (settled) return;
|
|
946
|
+
settled = true;
|
|
947
|
+
if (req) inflight.delete(req);
|
|
948
|
+
for (const t of timers) clearTimeout(t);
|
|
949
|
+
resolve2(a);
|
|
950
|
+
};
|
|
951
|
+
const later = (ms, fn) => {
|
|
952
|
+
const t = setTimeout(fn, ms);
|
|
953
|
+
t.unref();
|
|
954
|
+
timers.push(t);
|
|
955
|
+
};
|
|
956
|
+
try {
|
|
957
|
+
const mod = url.protocol === "https:" ? https__namespace : url.protocol === "http:" ? http__namespace : void 0;
|
|
958
|
+
if (!mod) return finish(void 0);
|
|
959
|
+
req = mod.request(url, { method, headers });
|
|
960
|
+
inflight.add(req);
|
|
961
|
+
req.on("socket", (socket) => {
|
|
962
|
+
socket.unref();
|
|
963
|
+
if (socket.connecting) {
|
|
964
|
+
later(CONNECT_TIMEOUT_MS, () => {
|
|
965
|
+
if (socket.connecting) req.destroy(new Error("connect timeout"));
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
req.on("error", () => finish(void 0));
|
|
970
|
+
req.on("response", (res) => {
|
|
971
|
+
const chunks = [];
|
|
972
|
+
let size = 0;
|
|
973
|
+
res.on("data", (c) => {
|
|
974
|
+
if (size < MAX_RESPONSE) chunks.push(c);
|
|
975
|
+
size += c.length;
|
|
976
|
+
});
|
|
977
|
+
res.on("error", () => finish({ status: res.statusCode || 0, headers: res.headers, body: Buffer.alloc(0) }));
|
|
978
|
+
res.on("end", () => finish({ status: res.statusCode || 0, headers: res.headers, body: Buffer.concat(chunks) }));
|
|
979
|
+
});
|
|
980
|
+
later(timeoutMs, () => {
|
|
981
|
+
req.destroy(new Error("timeout"));
|
|
982
|
+
finish(void 0);
|
|
983
|
+
});
|
|
984
|
+
req.end(body);
|
|
985
|
+
} catch {
|
|
986
|
+
finish(void 0);
|
|
987
|
+
}
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
var header = (h, name) => {
|
|
991
|
+
const v = h[name];
|
|
992
|
+
return Array.isArray(v) ? v[0] : v;
|
|
993
|
+
};
|
|
994
|
+
function reasonOf(body) {
|
|
995
|
+
try {
|
|
996
|
+
const r = JSON.parse(body.toString("utf8"))?.data?.reason;
|
|
997
|
+
return typeof r === "string" ? r : void 0;
|
|
998
|
+
} catch {
|
|
999
|
+
return void 0;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
function makeNodeTransport(options) {
|
|
1003
|
+
if (options.fetchImpl) return chunkTPSJGLR3_cjs.makeServerFetchTransport(options);
|
|
1004
|
+
const host = options.host.replace(/\/+$/, "");
|
|
1005
|
+
const apiKey = typeof options.apiKey === "string" && options.apiKey ? options.apiKey : void 0;
|
|
1006
|
+
const sendTimeout = Math.max(1, chunkKN7H22EQ_cjs.num(options.timeoutMs, SEND_TIMEOUT_MS));
|
|
1007
|
+
const inflight = /* @__PURE__ */ new Set();
|
|
1008
|
+
const url = (path) => {
|
|
1009
|
+
try {
|
|
1010
|
+
return new URL(host + path);
|
|
1011
|
+
} catch {
|
|
1012
|
+
return void 0;
|
|
1013
|
+
}
|
|
1014
|
+
};
|
|
1015
|
+
return {
|
|
1016
|
+
async send(envelope) {
|
|
1017
|
+
try {
|
|
1018
|
+
const target = url(chunkR7JLZ4WO_cjs.PATHS.INGEST);
|
|
1019
|
+
if (!target) return { status: 0 };
|
|
1020
|
+
const json = chunkKN7H22EQ_cjs.safeStringify(envelope);
|
|
1021
|
+
const headers = { ...options.headers, "Content-Type": "application/json" };
|
|
1022
|
+
for (const k of Object.keys(headers)) if (k.toLowerCase() === "authorization" || k.toLowerCase() === "content-length") delete headers[k];
|
|
1023
|
+
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
|
|
1024
|
+
let body = Buffer.from(json, "utf8");
|
|
1025
|
+
if (body.length > chunkTPSJGLR3_cjs.GZIP_THRESHOLD) {
|
|
1026
|
+
const zipped = await gzipAsync(json);
|
|
1027
|
+
if (zipped) {
|
|
1028
|
+
body = zipped;
|
|
1029
|
+
headers["Content-Encoding"] = "gzip";
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
headers["Content-Length"] = String(body.length);
|
|
1033
|
+
const a = await request(inflight, target, "POST", headers, body, sendTimeout);
|
|
1034
|
+
if (!a) return { status: 0 };
|
|
1035
|
+
const out = { status: a.status };
|
|
1036
|
+
const retryAfter = chunkHADYYQNL_cjs.parseRetryAfter(header(a.headers, "retry-after"));
|
|
1037
|
+
if (retryAfter !== void 0) out.retryAfter = retryAfter;
|
|
1038
|
+
if (a.status >= 300 && a.status < 400) {
|
|
1039
|
+
const location = header(a.headers, "location");
|
|
1040
|
+
if (location) out.location = location;
|
|
1041
|
+
} else if (a.status >= 400) {
|
|
1042
|
+
const reason = reasonOf(a.body);
|
|
1043
|
+
if (reason) out.reason = reason;
|
|
1044
|
+
}
|
|
1045
|
+
return out;
|
|
1046
|
+
} catch {
|
|
1047
|
+
return { status: 0 };
|
|
1048
|
+
}
|
|
1049
|
+
},
|
|
1050
|
+
async fetchConfig() {
|
|
1051
|
+
try {
|
|
1052
|
+
const target = url(`${chunkR7JLZ4WO_cjs.PATHS.CONFIG}?workspace=${encodeURIComponent(options.workspaceKey)}`);
|
|
1053
|
+
if (!target) return null;
|
|
1054
|
+
const a = await request(inflight, target, "GET", { Accept: "application/json" }, void 0, CONFIG_TIMEOUT_MS);
|
|
1055
|
+
if (!a || a.status >= 300 && a.status < 400) return null;
|
|
1056
|
+
const json = JSON.parse(a.body.toString("utf8"));
|
|
1057
|
+
const data = json && typeof json === "object" ? json.data : null;
|
|
1058
|
+
return data && typeof data === "object" ? data : null;
|
|
1059
|
+
} catch {
|
|
1060
|
+
return null;
|
|
1061
|
+
}
|
|
1062
|
+
},
|
|
1063
|
+
abort() {
|
|
1064
|
+
for (const req of [...inflight]) {
|
|
1065
|
+
try {
|
|
1066
|
+
req.destroy(new Error("aborted"));
|
|
1067
|
+
} catch {
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
function getDefaultIntegrations() {
|
|
1074
|
+
return [
|
|
1075
|
+
// Events of different requests (or users) are never duplicates of each other.
|
|
1076
|
+
chunkPYYWPIFL_cjs.dedupeIntegration({ requestKey: chunkZVMAN7OO_cjs.currentRequestKey }),
|
|
1077
|
+
httpServerIntegration(),
|
|
1078
|
+
onUncaughtExceptionIntegration(),
|
|
1079
|
+
onUnhandledRejectionIntegration(),
|
|
1080
|
+
chunkTPSJGLR3_cjs.requestDataIntegration(),
|
|
1081
|
+
nodeContextIntegration(),
|
|
1082
|
+
consoleBreadcrumbsIntegration(),
|
|
1083
|
+
contextLinesIntegration(),
|
|
1084
|
+
flushOnExitIntegration()
|
|
1085
|
+
];
|
|
1086
|
+
}
|
|
1087
|
+
function envRelease() {
|
|
1088
|
+
try {
|
|
1089
|
+
const v = typeof process !== "undefined" && process.env ? process.env.STARKO_RELEASE : void 0;
|
|
1090
|
+
return v || void 0;
|
|
1091
|
+
} catch {
|
|
1092
|
+
return void 0;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
function initNode(options, sdkName) {
|
|
1096
|
+
try {
|
|
1097
|
+
const previous = chunkKN7H22EQ_cjs.getClient();
|
|
1098
|
+
if (previous) void previous.close(0);
|
|
1099
|
+
chunkZVMAN7OO_cjs.installAsyncScopeManager(async_hooks.AsyncLocalStorage, async_hooks.executionAsyncResource);
|
|
1100
|
+
const defaults = options.defaultIntegrations === false ? [] : Array.isArray(options.defaultIntegrations) ? options.defaultIntegrations : getDefaultIntegrations();
|
|
1101
|
+
const integrations = typeof options.integrations === "function" ? options.integrations(defaults) : [...defaults, ...options.integrations || []];
|
|
1102
|
+
const { apiKey, fetch: fetchImpl, beforeSend: userBeforeSend, ...rest } = options;
|
|
1103
|
+
let client;
|
|
1104
|
+
const beforeSend = async (event, hint) => {
|
|
1105
|
+
const lines = client.getIntegration("ContextLines");
|
|
1106
|
+
if (lines && typeof lines.addContextLines === "function") await lines.addContextLines(event);
|
|
1107
|
+
return userBeforeSend ? userBeforeSend(event, hint) : event;
|
|
1108
|
+
};
|
|
1109
|
+
client = new chunkTPSJGLR3_cjs.ServerClient({
|
|
1110
|
+
...rest,
|
|
1111
|
+
release: options.release || envRelease(),
|
|
1112
|
+
beforeSend,
|
|
1113
|
+
platform: "node",
|
|
1114
|
+
framePlatform: "node:javascript",
|
|
1115
|
+
sdkName,
|
|
1116
|
+
stackParser: chunkPYYWPIFL_cjs.nodeStackParser,
|
|
1117
|
+
isInApp: chunkTPSJGLR3_cjs.nodeIsInApp,
|
|
1118
|
+
getSessionId: () => chunkZVMAN7OO_cjs.getRequestData()?.sessionId,
|
|
1119
|
+
...chunkTPSJGLR3_cjs.SERVER_DEFAULTS,
|
|
1120
|
+
transport: options.transport || ((o) => makeNodeTransport({ ...o, apiKey, fetchImpl: typeof fetchImpl === "function" ? fetchImpl : void 0 }))
|
|
1121
|
+
});
|
|
1122
|
+
chunkKN7H22EQ_cjs.setCurrentClient(client);
|
|
1123
|
+
client.init(integrations);
|
|
1124
|
+
chunkZVMAN7OO_cjs.noteInit(options.user ? chunkKN7H22EQ_cjs.getGlobalScope().user : null);
|
|
1125
|
+
return client;
|
|
1126
|
+
} catch (err) {
|
|
1127
|
+
try {
|
|
1128
|
+
if (options && options.debug) console.warn("[starko] init failed", err);
|
|
1129
|
+
} catch {
|
|
1130
|
+
}
|
|
1131
|
+
return void 0;
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
function init(options) {
|
|
1135
|
+
return initNode(options, "starko.node");
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
exports.CONNECT_TIMEOUT_MS = CONNECT_TIMEOUT_MS;
|
|
1139
|
+
exports.consoleBreadcrumbsIntegration = consoleBreadcrumbsIntegration;
|
|
1140
|
+
exports.contextLinesIntegration = contextLinesIntegration;
|
|
1141
|
+
exports.flushOnExitIntegration = flushOnExitIntegration;
|
|
1142
|
+
exports.getDefaultIntegrations = getDefaultIntegrations;
|
|
1143
|
+
exports.getUnhandledRejectionMode = getUnhandledRejectionMode;
|
|
1144
|
+
exports.httpServerIntegration = httpServerIntegration;
|
|
1145
|
+
exports.init = init;
|
|
1146
|
+
exports.initNode = initNode;
|
|
1147
|
+
exports.instrumentServer = instrumentServer;
|
|
1148
|
+
exports.makeNodeTransport = makeNodeTransport;
|
|
1149
|
+
exports.nodeContextIntegration = nodeContextIntegration;
|
|
1150
|
+
exports.onUncaughtExceptionIntegration = onUncaughtExceptionIntegration;
|
|
1151
|
+
exports.onUnhandledRejectionIntegration = onUnhandledRejectionIntegration;
|