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