@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.
- package/CHANGELOG.md +248 -0
- package/LICENSE +17 -0
- package/NOTICE +58 -0
- package/README.md +81 -2
- package/dist/api-BAFm4Lxj.d.ts +558 -0
- package/dist/api-DNrctwJu.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-2PM4FRM5.cjs +431 -0
- package/dist/chunk-335HNCOJ.js +249 -0
- package/dist/chunk-3AW5B2WW.js +115 -0
- package/dist/chunk-3R5TQAWD.js +216 -0
- package/dist/chunk-6H5MOPTQ.cjs +1230 -0
- package/dist/chunk-7TKNT3QJ.cjs +2487 -0
- package/dist/chunk-A4WLNFMU.cjs +220 -0
- package/dist/chunk-ALYFFOPR.cjs +134 -0
- package/dist/chunk-BVVFVRMO.js +1113 -0
- package/dist/chunk-CIHNKN62.cjs +15 -0
- package/dist/chunk-CMGCH6HD.js +1212 -0
- package/dist/chunk-D6QAPQ7L.cjs +56 -0
- package/dist/chunk-DUO5V6WZ.js +213 -0
- package/dist/chunk-EC2WZ6PG.js +90 -0
- package/dist/chunk-EFURLFJT.cjs +187 -0
- package/dist/chunk-EROUORMY.js +53 -0
- package/dist/chunk-LXBXFOAP.cjs +96 -0
- package/dist/chunk-MF6SA6DB.js +563 -0
- package/dist/chunk-N5R6ORIB.js +413 -0
- package/dist/chunk-N6R6BWHK.cjs +142 -0
- package/dist/chunk-QAGGN2T7.cjs +225 -0
- package/dist/chunk-QV4HRIDD.cjs +659 -0
- package/dist/chunk-TKNDYQB3.cjs +583 -0
- package/dist/chunk-UI5YC4TH.js +131 -0
- package/dist/chunk-VEHZYLK6.cjs +1151 -0
- package/dist/chunk-VNCWOGTI.js +12 -0
- package/dist/chunk-VWNIOGE6.js +180 -0
- package/dist/chunk-WDKRKGYF.js +608 -0
- package/dist/chunk-XOZIXBUK.js +2462 -0
- package/dist/chunk-ZS3K3SDR.cjs +258 -0
- package/dist/cli/index.cjs +2780 -0
- package/dist/common-DLFAqL2d.d.cts +36 -0
- package/dist/common-DbSXkaw6.d.ts +36 -0
- package/dist/dedupe-Bh5riD8Z.d.cts +13 -0
- package/dist/dedupe-DoYiSx-9.d.ts +13 -0
- package/dist/handler-BcnsnvhF.d.cts +82 -0
- package/dist/handler-qHzilC9T.d.ts +82 -0
- package/dist/index.cjs +309 -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 +277 -0
- package/dist/next/config.d.cts +193 -0
- package/dist/next/config.d.ts +193 -0
- package/dist/next/config.js +263 -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-BUhWuWJX.d.cts +79 -0
- package/dist/options-BUhWuWJX.d.ts +79 -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-D1ouJm2h.d.cts +628 -0
- package/dist/scope-D1ouJm2h.d.ts +628 -0
- package/dist/server-edge-7624N3WF.cjs +51 -0
- package/dist/server-edge-BEEXWL7T.js +48 -0
- package/dist/server-node-ET4LIPEC.cjs +27 -0
- package/dist/server-node-TQUVMZUC.js +24 -0
- package/dist/session-C_WzbEN2.d.cts +4 -0
- package/dist/session-C_WzbEN2.d.ts +4 -0
- package/dist/session-propagation-Pr0Zb9Zn.d.cts +30 -0
- package/dist/session-propagation-RM5py1bp.d.ts +30 -0
- package/dist/starko.min.js +6 -0
- package/docs/browser.md +386 -0
- package/docs/configuration.md +310 -0
- package/docs/nextjs.md +488 -0
- package/docs/node.md +427 -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 +482 -0
- package/docs/troubleshooting.md +263 -0
- package/docs/widget.md +84 -0
- package/docs/wire-format.md +547 -0
- package/package.json +191 -4
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk2PM4FRM5_cjs = require('./chunk-2PM4FRM5.cjs');
|
|
4
|
+
var chunkLXBXFOAP_cjs = require('./chunk-LXBXFOAP.cjs');
|
|
5
|
+
var chunkQV4HRIDD_cjs = require('./chunk-QV4HRIDD.cjs');
|
|
6
|
+
|
|
7
|
+
// src/next/server-common.ts
|
|
8
|
+
var LAST_RESORT_FLUSH_MS = 500;
|
|
9
|
+
function isServerless() {
|
|
10
|
+
try {
|
|
11
|
+
const env = typeof process !== "undefined" && process.env ? process.env : {};
|
|
12
|
+
return !!(env.VERCEL || env.AWS_LAMBDA_FUNCTION_NAME || env.NETLIFY || env.FUNCTION_TARGET || env.FUNCTIONS_WORKER_RUNTIME);
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function scheduleFlush(flushTimeout, runtime) {
|
|
18
|
+
try {
|
|
19
|
+
const waitUntil = chunk2PM4FRM5_cjs.platformWaitUntil();
|
|
20
|
+
if (waitUntil) {
|
|
21
|
+
waitUntil(chunk2PM4FRM5_cjs.flushIfPending(flushTimeout, true));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (runtime === "nodejs" && !isServerless()) return;
|
|
25
|
+
await chunk2PM4FRM5_cjs.flushIfPending(Math.min(flushTimeout, LAST_RESORT_FLUSH_MS), true);
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function captureNextRequestError(error, request, context, flushTimeout, runtime) {
|
|
30
|
+
if (chunkLXBXFOAP_cjs.isNextControlFlow(error)) return;
|
|
31
|
+
const d = chunkLXBXFOAP_cjs.describeRequestError(error, request, context);
|
|
32
|
+
chunk2PM4FRM5_cjs.openRequestScope(
|
|
33
|
+
() => {
|
|
34
|
+
chunkQV4HRIDD_cjs.captureException(error, d.hint);
|
|
35
|
+
},
|
|
36
|
+
d.request,
|
|
37
|
+
void 0,
|
|
38
|
+
chunk2PM4FRM5_cjs.readScope(),
|
|
39
|
+
chunk2PM4FRM5_cjs.currentRequestKey()
|
|
40
|
+
);
|
|
41
|
+
await scheduleFlush(flushTimeout, runtime);
|
|
42
|
+
}
|
|
43
|
+
function withNextDefaults(options) {
|
|
44
|
+
if (!options || options.defaultIntegrations === false) return options;
|
|
45
|
+
const user = options.integrations;
|
|
46
|
+
return {
|
|
47
|
+
...options,
|
|
48
|
+
integrations: (defaults) => {
|
|
49
|
+
const withNext = [...defaults, chunkLXBXFOAP_cjs.nextControlFlowIntegration()];
|
|
50
|
+
return typeof user === "function" ? user(withNext) : [...withNext, ...user || []];
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
exports.captureNextRequestError = captureNextRequestError;
|
|
56
|
+
exports.withNextDefaults = withNextDefaults;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { getRequestData } from './chunk-N5R6ORIB.js';
|
|
2
|
+
import { parseRetryAfter } from './chunk-UI5YC4TH.js';
|
|
3
|
+
import { nodeStackParser, Client, DEFAULT_REMOTE_CONFIG, isSuppressed } from './chunk-CMGCH6HD.js';
|
|
4
|
+
import { safeStringify, safely } from './chunk-WDKRKGYF.js';
|
|
5
|
+
import { PATHS } from './chunk-3AW5B2WW.js';
|
|
6
|
+
|
|
7
|
+
// src/node/in-app.ts
|
|
8
|
+
var NOT_APP_FILE = /^(?:node:|internal[\\/]|<anonymous>$|native$|\[native code\]$|wasm:\/\/|evalmachine\.)/;
|
|
9
|
+
var NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
10
|
+
function ownRoot() {
|
|
11
|
+
try {
|
|
12
|
+
const file = nodeStackParser(new Error().stack || "")[0]?.filename;
|
|
13
|
+
if (!file) return void 0;
|
|
14
|
+
const path = file.replace(/^file:\/\//, "");
|
|
15
|
+
const dist = /^(.*[\\/]@starko-one[\\/]sdk[\\/]dist[\\/])/.exec(path);
|
|
16
|
+
if (dist) return dist[1];
|
|
17
|
+
const src = /^(.*[\\/]src[\\/])node[\\/]in-app\.[cm]?[jt]s$/.exec(path);
|
|
18
|
+
if (src) return src[1];
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
var OWN_ROOT = ownRoot();
|
|
24
|
+
function nodeIsInApp(filename) {
|
|
25
|
+
if (!filename) return false;
|
|
26
|
+
if (NOT_APP_FILE.test(filename) || NODE_MODULES.test(filename)) return false;
|
|
27
|
+
if (OWN_ROOT && filename.replace(/^file:\/\//, "").startsWith(OWN_ROOT)) return false;
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/node/integrations/request-data.ts
|
|
32
|
+
function requestDataIntegration() {
|
|
33
|
+
return {
|
|
34
|
+
name: "RequestData",
|
|
35
|
+
processEvent(event) {
|
|
36
|
+
const r = getRequestData();
|
|
37
|
+
if (!r) return event;
|
|
38
|
+
const request = { ...event.request };
|
|
39
|
+
if (r.method && !request.method) request.method = r.method;
|
|
40
|
+
if (r.url && !request.url) request.url = r.url;
|
|
41
|
+
if (r.route && !request.route) request.route = r.route;
|
|
42
|
+
if (Object.keys(request).length) event.request = request;
|
|
43
|
+
return event;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/node/transport.ts
|
|
49
|
+
var GZIP_THRESHOLD = 4 * 1024;
|
|
50
|
+
var SEND_TIMEOUT_MS = 1e4;
|
|
51
|
+
var CONFIG_TIMEOUT_MS = 5e3;
|
|
52
|
+
function deadline(ms) {
|
|
53
|
+
try {
|
|
54
|
+
return typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function" ? AbortSignal.timeout(ms) : void 0;
|
|
55
|
+
} catch {
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function gzip(body) {
|
|
60
|
+
try {
|
|
61
|
+
if (typeof CompressionStream !== "function" || typeof Blob !== "function") return void 0;
|
|
62
|
+
const stream = new Blob([body]).stream().pipeThrough(new CompressionStream("gzip"));
|
|
63
|
+
return new Uint8Array(await new Response(stream).arrayBuffer());
|
|
64
|
+
} catch {
|
|
65
|
+
return void 0;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function makeServerFetchTransport(options) {
|
|
69
|
+
const host = options.host.replace(/\/+$/, "");
|
|
70
|
+
const apiKey = typeof options.apiKey === "string" && options.apiKey ? options.apiKey : void 0;
|
|
71
|
+
const getFetch = () => options.fetchImpl ?? (typeof fetch === "function" ? fetch : void 0);
|
|
72
|
+
return {
|
|
73
|
+
async send(envelope) {
|
|
74
|
+
const f = getFetch();
|
|
75
|
+
if (!f) return { status: 0 };
|
|
76
|
+
try {
|
|
77
|
+
const json = safeStringify(envelope);
|
|
78
|
+
const headers = { ...options.headers, "Content-Type": "application/json" };
|
|
79
|
+
delete headers.Authorization;
|
|
80
|
+
delete headers.authorization;
|
|
81
|
+
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
|
|
82
|
+
let body = json;
|
|
83
|
+
if (json.length > GZIP_THRESHOLD) {
|
|
84
|
+
const zipped = await gzip(json);
|
|
85
|
+
if (zipped) {
|
|
86
|
+
body = zipped;
|
|
87
|
+
headers["Content-Encoding"] = "gzip";
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const res = await f(host + PATHS.INGEST, { method: "POST", body, headers, redirect: "manual", signal: deadline(SEND_TIMEOUT_MS) });
|
|
91
|
+
const out = { status: res.type === "opaqueredirect" ? 302 : res.status };
|
|
92
|
+
try {
|
|
93
|
+
out.retryAfter = parseRetryAfter(res.headers.get("Retry-After"));
|
|
94
|
+
} catch {
|
|
95
|
+
}
|
|
96
|
+
if (out.status >= 300 && out.status < 400) {
|
|
97
|
+
try {
|
|
98
|
+
const location = res.headers.get("Location");
|
|
99
|
+
if (location) out.location = location;
|
|
100
|
+
} catch {
|
|
101
|
+
}
|
|
102
|
+
} else if (out.status >= 400) {
|
|
103
|
+
try {
|
|
104
|
+
const reason = (await res.json())?.data?.reason;
|
|
105
|
+
if (typeof reason === "string") out.reason = reason;
|
|
106
|
+
} catch {
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
try {
|
|
110
|
+
await res.arrayBuffer();
|
|
111
|
+
} catch {
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
} catch {
|
|
116
|
+
return { status: 0 };
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
async fetchConfig() {
|
|
120
|
+
const f = getFetch();
|
|
121
|
+
if (!f) return null;
|
|
122
|
+
try {
|
|
123
|
+
const res = await f(`${host}${PATHS.CONFIG}?workspace=${encodeURIComponent(options.workspaceKey)}`, { method: "GET", redirect: "manual", signal: deadline(CONFIG_TIMEOUT_MS) });
|
|
124
|
+
if (res.status >= 300 && res.status < 400 || res.type === "opaqueredirect") return null;
|
|
125
|
+
const json = await res.json();
|
|
126
|
+
const data = json && typeof json === "object" ? json.data : null;
|
|
127
|
+
return data && typeof data === "object" ? data : null;
|
|
128
|
+
} catch {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/node/server-defaults.ts
|
|
136
|
+
var SERVER_DEFAULTS = {
|
|
137
|
+
defaultMaxEventsPerLifetime: Infinity,
|
|
138
|
+
defaultMaxEventsPerMinute: 300,
|
|
139
|
+
// A burst at start-up (the database is down) must not lose events while the first batches go out.
|
|
140
|
+
defaultMaxQueueSize: 500,
|
|
141
|
+
// After repeated failed batches sending pauses for this long (a browser pauses for the page load).
|
|
142
|
+
failurePauseMs: 5 * 6e4
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// src/node/server-client.ts
|
|
146
|
+
var LAZY_CONFIG_TIMEOUT_MS = 5e3;
|
|
147
|
+
var ServerClient = class extends Client {
|
|
148
|
+
constructor(options) {
|
|
149
|
+
super(options);
|
|
150
|
+
/** The config has not been read yet (`remote` is the default until it is). */
|
|
151
|
+
this.provisional = false;
|
|
152
|
+
this.skipped = new Promise((r) => this.skip = r);
|
|
153
|
+
}
|
|
154
|
+
configGate() {
|
|
155
|
+
return () => this.readLazyConfig();
|
|
156
|
+
}
|
|
157
|
+
loadRemoteConfig() {
|
|
158
|
+
if (this.options.remoteConfig === false || !this.transport.fetchConfig) return super.loadRemoteConfig();
|
|
159
|
+
this.remote = DEFAULT_REMOTE_CONFIG;
|
|
160
|
+
this.provisional = true;
|
|
161
|
+
}
|
|
162
|
+
/** Read the config once, when the queue is about to send for the first time. Never rejects. */
|
|
163
|
+
readLazyConfig() {
|
|
164
|
+
if (!this.provisional) return Promise.resolve();
|
|
165
|
+
this.lazyConfig || (this.lazyConfig = this.readConfig(LAZY_CONFIG_TIMEOUT_MS, (rc) => {
|
|
166
|
+
this.provisional = false;
|
|
167
|
+
this.applyLateConfig(rc);
|
|
168
|
+
}));
|
|
169
|
+
return Promise.race([this.lazyConfig, this.skipped]);
|
|
170
|
+
}
|
|
171
|
+
/** A config read after events were queued: it applies to what is still unsent. */
|
|
172
|
+
applyLateConfig(rc) {
|
|
173
|
+
this.remote = rc;
|
|
174
|
+
if (!rc.enabled) {
|
|
175
|
+
this.logger.log("config: disabled");
|
|
176
|
+
this.shutdown("config");
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (rc.suppress.length || rc.sample_rate < 1) this.queue.filter((e) => !isSuppressed(e, rc.suppress) && (rc.sample_rate >= 1 || Math.random() < rc.sample_rate));
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* True while a flush now would only wait: a request is already in flight,
|
|
183
|
+
* or sending waits out a back-off, a 429 or a failure pause. Server hooks
|
|
184
|
+
* skip their flush then (the queue sends on its own).
|
|
185
|
+
*/
|
|
186
|
+
isSendBusy() {
|
|
187
|
+
return this.queue.isSending || this.queue.isBlocked;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* A shutdown deadline passed: abort the requests in flight and start no
|
|
191
|
+
* new one for 30 s (the queue keeps its events; a process that goes on
|
|
192
|
+
* after all sends them then). Never throws.
|
|
193
|
+
*/
|
|
194
|
+
abortRequests() {
|
|
195
|
+
safely(this.logger, "abort", () => {
|
|
196
|
+
this.queue.holdOff(3e4);
|
|
197
|
+
const t = this.transport;
|
|
198
|
+
if (typeof t.abort === "function") t.abort();
|
|
199
|
+
}, void 0);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Send without waiting for the remote config (the process is about to end:
|
|
203
|
+
* the fatal path, `beforeExit`, SIGTERM / SIGINT), also when a send is
|
|
204
|
+
* already waiting for it. A config read already under way still applies
|
|
205
|
+
* to what is unsent when it arrives.
|
|
206
|
+
*/
|
|
207
|
+
skipRemoteConfig() {
|
|
208
|
+
this.provisional = false;
|
|
209
|
+
this.skip();
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export { GZIP_THRESHOLD, SERVER_DEFAULTS, ServerClient, makeServerFetchTransport, nodeIsInApp, requestDataIntegration };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { parseSessionHeader, SESSION_HEADER } from './chunk-VNCWOGTI.js';
|
|
2
|
+
import { unwrapThrown } from './chunk-335HNCOJ.js';
|
|
3
|
+
|
|
4
|
+
// src/next/common.ts
|
|
5
|
+
function buildTimeRelease() {
|
|
6
|
+
try {
|
|
7
|
+
const v = process.env.STARKO_BUILD_RELEASE;
|
|
8
|
+
return typeof v === "string" && v ? v : void 0;
|
|
9
|
+
} catch {
|
|
10
|
+
return void 0;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
var CONTROL_FLOW = ["NEXT_REDIRECT", "NEXT_HTTP_ERROR_FALLBACK", "NEXT_NOT_FOUND", "BAILOUT_TO_CLIENT_SIDE_RENDERING", "DYNAMIC_SERVER_USAGE", "NEXT_STATIC_GEN_BAILOUT", "HANGING_PROMISE_REJECTION", "NEXT_PRERENDER_INTERRUPTED"];
|
|
14
|
+
var REACT_POSTPONE = typeof Symbol === "function" ? /* @__PURE__ */ Symbol.for("react.postpone") : void 0;
|
|
15
|
+
var isControlCode = (s) => typeof s === "string" && CONTROL_FLOW.some((c) => s === c || s.startsWith(`${c};`));
|
|
16
|
+
function isNextControlFlow(error, depth = 0) {
|
|
17
|
+
try {
|
|
18
|
+
if (!error || typeof error !== "object") return false;
|
|
19
|
+
const e = error;
|
|
20
|
+
if (REACT_POSTPONE && e.$$typeof === REACT_POSTPONE) return true;
|
|
21
|
+
if (isControlCode(e.digest)) return true;
|
|
22
|
+
if (e.digest === void 0 && isControlCode(e.message)) return true;
|
|
23
|
+
return depth < 5 && isNextControlFlow(e.cause, depth + 1);
|
|
24
|
+
} catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function nextControlFlowIntegration() {
|
|
29
|
+
return {
|
|
30
|
+
name: "NextControlFlow",
|
|
31
|
+
processEvent(event, hint) {
|
|
32
|
+
const thrown = unwrapThrown(hint.originalException);
|
|
33
|
+
if (isNextControlFlow(thrown)) return null;
|
|
34
|
+
const first = event.exception_list[0];
|
|
35
|
+
if (thrown === hint.originalException && first && /^(?:Uncaught )?(?:Error: )?NEXT_(?:REDIRECT|HTTP_ERROR_FALLBACK|NOT_FOUND)\b/.test(first.value || "")) return null;
|
|
36
|
+
return event;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function digestOf(error) {
|
|
41
|
+
try {
|
|
42
|
+
const d = error && typeof error === "object" ? error.digest : void 0;
|
|
43
|
+
return typeof d === "string" && d ? d : void 0;
|
|
44
|
+
} catch {
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function header(headers, name) {
|
|
49
|
+
if (!headers || typeof headers !== "object") return void 0;
|
|
50
|
+
try {
|
|
51
|
+
const h = headers;
|
|
52
|
+
if (name in h) return h[name];
|
|
53
|
+
for (const k of Object.keys(h)) if (k.toLowerCase() === name) return h[k];
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
58
|
+
function describeRequestError(error, request, context) {
|
|
59
|
+
const r = request || {};
|
|
60
|
+
const c = context || {};
|
|
61
|
+
const tags = {};
|
|
62
|
+
if (c.routerKind) tags["next.router_kind"] = String(c.routerKind);
|
|
63
|
+
if (c.routeType) tags["next.route_type"] = String(c.routeType);
|
|
64
|
+
if (c.renderSource) tags["next.render_source"] = String(c.renderSource);
|
|
65
|
+
if (typeof r.method === "string" && r.method) tags["next.method"] = r.method.toUpperCase();
|
|
66
|
+
const digest = digestOf(error);
|
|
67
|
+
if (digest) tags["next.digest"] = digest;
|
|
68
|
+
const nextjs = {};
|
|
69
|
+
for (const [k, v] of [
|
|
70
|
+
["router_kind", c.routerKind],
|
|
71
|
+
["route_path", c.routePath],
|
|
72
|
+
["route_type", c.routeType],
|
|
73
|
+
["render_source", c.renderSource],
|
|
74
|
+
["revalidate_reason", c.revalidateReason],
|
|
75
|
+
["render_type", c.renderType]
|
|
76
|
+
]) {
|
|
77
|
+
if (v !== void 0) nextjs[k] = v;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
hint: { mechanism: { type: "next.onRequestError", handled: false }, tags, contexts: { nextjs } },
|
|
81
|
+
request: {
|
|
82
|
+
method: typeof r.method === "string" && r.method ? r.method.toUpperCase() : void 0,
|
|
83
|
+
url: typeof r.path === "string" && r.path ? r.path : void 0,
|
|
84
|
+
route: typeof c.routePath === "string" && c.routePath ? c.routePath : void 0,
|
|
85
|
+
sessionId: parseSessionHeader(header(r.headers, SESSION_HEADER))
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { buildTimeRelease, describeRequestError, digestOf, isNextControlFlow, nextControlFlowIntegration };
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk7TKNT3QJ_cjs = require('./chunk-7TKNT3QJ.cjs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
9
|
+
|
|
10
|
+
var PLUGIN_NAME = "StarkoWebpackPlugin";
|
|
11
|
+
var INFO_KEY = "starkoDebugId";
|
|
12
|
+
function relatedSourceMaps(info) {
|
|
13
|
+
const related = info.related?.sourceMap;
|
|
14
|
+
return related === void 0 ? [] : Array.isArray(related) ? related : [related];
|
|
15
|
+
}
|
|
16
|
+
var StarkoWebpackPlugin = class {
|
|
17
|
+
constructor(options = {}, internals = {}) {
|
|
18
|
+
this.options = options;
|
|
19
|
+
this.internals = internals;
|
|
20
|
+
this.logger = chunk7TKNT3QJ_cjs.createLogger({ silent: options.silent, secrets: [chunk7TKNT3QJ_cjs.resolveConnection(options).apiKey] });
|
|
21
|
+
}
|
|
22
|
+
apply(compiler) {
|
|
23
|
+
const options = this.options;
|
|
24
|
+
const logger = this.logger;
|
|
25
|
+
const enabled = options.enabled ?? compiler.options.mode === "production";
|
|
26
|
+
if (!enabled) return;
|
|
27
|
+
const connection = chunk7TKNT3QJ_cjs.resolveConnection(options);
|
|
28
|
+
if (!connection.apiKey) {
|
|
29
|
+
logger.warn(chunk7TKNT3QJ_cjs.NO_API_KEY_MESSAGE);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const devtool = compiler.options.devtool;
|
|
33
|
+
const userPlugin = findSourceMapPlugin(compiler);
|
|
34
|
+
let owner = this.internals.sourcemapOwner ?? "user";
|
|
35
|
+
let addedMaps = false;
|
|
36
|
+
if (userPlugin === "eval") {
|
|
37
|
+
logger.warn('an EvalSourceMapDevToolPlugin puts the source maps inside the bundle; use SourceMapDevToolPlugin or devtool "source-map". Nothing is injected or uploaded.');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!devtool && !userPlugin) {
|
|
41
|
+
new compiler.webpack.SourceMapDevToolPlugin({ filename: "[file].map", append: false }).apply(compiler);
|
|
42
|
+
owner = "starko";
|
|
43
|
+
addedMaps = true;
|
|
44
|
+
} else if (typeof devtool === "string" && /eval|inline/.test(devtool)) {
|
|
45
|
+
logger.warn(`devtool "${devtool}" puts the source map inside the bundle; use "source-map" or "hidden-source-map". Nothing is injected or uploaded.`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const filter = chunk7TKNT3QJ_cjs.createFileFilter(options);
|
|
49
|
+
const releases = /* @__PURE__ */ new WeakMap();
|
|
50
|
+
const releaseFor = (compilation) => {
|
|
51
|
+
if (!releases.has(compilation)) releases.set(compilation, chunk7TKNT3QJ_cjs.resolveReleaseInfo(options.release));
|
|
52
|
+
return releases.get(compilation);
|
|
53
|
+
};
|
|
54
|
+
const { Compilation: CompilationClass, sources, WebpackError } = compiler.webpack;
|
|
55
|
+
const before = /* @__PURE__ */ new WeakMap();
|
|
56
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
57
|
+
compilation.hooks.processAssets.tap({ name: PLUGIN_NAME, stage: CompilationClass.PROCESS_ASSETS_STAGE_DEV_TOOLING - 1 }, () => {
|
|
58
|
+
before.set(compilation, new Set(compilation.getAssets().map((a) => a.name).filter((name) => name.endsWith(".map"))));
|
|
59
|
+
});
|
|
60
|
+
compilation.hooks.processAssets.tap(
|
|
61
|
+
{ name: PLUGIN_NAME, stage: CompilationClass.PROCESS_ASSETS_STAGE_DEV_TOOLING + 1 },
|
|
62
|
+
() => {
|
|
63
|
+
for (const chunk of compilation.chunks) {
|
|
64
|
+
for (const file of chunk.files) {
|
|
65
|
+
if (!filter(file)) continue;
|
|
66
|
+
try {
|
|
67
|
+
const asset = compilation.getAsset(file);
|
|
68
|
+
if (!asset || typeof asset.info[INFO_KEY] === "string") continue;
|
|
69
|
+
const mapName = relatedSourceMaps(asset.info)[0] ?? `${file}.map`;
|
|
70
|
+
const mapAsset = compilation.getAsset(mapName);
|
|
71
|
+
if (!mapAsset) continue;
|
|
72
|
+
const code = asset.source.source().toString();
|
|
73
|
+
const map = JSON.parse(mapAsset.source.source().toString());
|
|
74
|
+
const out = chunk7TKNT3QJ_cjs.injectDebugId(code, map, { release: releaseFor(compilation)?.version });
|
|
75
|
+
if (out.injected) compilation.updateAsset(file, new sources.RawSource(out.code), { ...asset.info, [INFO_KEY]: out.debugId });
|
|
76
|
+
else compilation.updateAsset(file, asset.source, { ...asset.info, [INFO_KEY]: out.debugId });
|
|
77
|
+
compilation.updateAsset(mapName, new sources.RawSource(JSON.stringify(out.map)));
|
|
78
|
+
} catch (error) {
|
|
79
|
+
logger.warn(`could not inject ${file}: ${chunk7TKNT3QJ_cjs.errorMessage(error)}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
if (options.upload === false) return;
|
|
87
|
+
const removeMapAssets = (compilation) => {
|
|
88
|
+
const preexisting = addedMaps ? before.get(compilation) : void 0;
|
|
89
|
+
const removed = new Set(
|
|
90
|
+
compilation.getAssets().map((a) => a.name).filter((name) => name.endsWith(".map") && !(preexisting && preexisting.has(name)))
|
|
91
|
+
);
|
|
92
|
+
for (const name of removed) compilation.deleteAsset(name);
|
|
93
|
+
if (removed.size === 0) return 0;
|
|
94
|
+
const pointsAtRemoved = (fileName, url) => {
|
|
95
|
+
const local = chunk7TKNT3QJ_cjs.localMapReference(url);
|
|
96
|
+
return local !== void 0 && removed.has(path__default.default.posix.normalize(path__default.default.posix.join(path__default.default.posix.dirname(fileName), local)));
|
|
97
|
+
};
|
|
98
|
+
for (const asset of compilation.getAssets()) {
|
|
99
|
+
const js = /\.(?:m|c)?js$/.test(asset.name);
|
|
100
|
+
if (!js && !asset.name.endsWith(".css")) continue;
|
|
101
|
+
const code = asset.source.source().toString();
|
|
102
|
+
let next = code;
|
|
103
|
+
if (js) {
|
|
104
|
+
const ref = chunk7TKNT3QJ_cjs.findSourceMappingUrl(code);
|
|
105
|
+
if (ref && pointsAtRemoved(asset.name, ref.url)) next = chunk7TKNT3QJ_cjs.stripSourceMappingUrl(code, ref);
|
|
106
|
+
} else {
|
|
107
|
+
next = chunk7TKNT3QJ_cjs.stripCssSourceMappingUrl(code, (url) => pointsAtRemoved(asset.name, url));
|
|
108
|
+
}
|
|
109
|
+
if (next !== code) compilation.updateAsset(asset.name, new sources.RawSource(next));
|
|
110
|
+
}
|
|
111
|
+
return removed.size;
|
|
112
|
+
};
|
|
113
|
+
compiler.hooks.emit.tapPromise(PLUGIN_NAME, async (compilation) => {
|
|
114
|
+
let failure;
|
|
115
|
+
try {
|
|
116
|
+
if (compilation.errors.length > 0) {
|
|
117
|
+
logger.warn("the compilation has errors; source maps are not uploaded");
|
|
118
|
+
} else {
|
|
119
|
+
const entries = [];
|
|
120
|
+
for (const asset of compilation.getAssets()) {
|
|
121
|
+
const chunkId = asset.info[INFO_KEY];
|
|
122
|
+
if (typeof chunkId !== "string") continue;
|
|
123
|
+
const mapName = relatedSourceMaps(asset.info)[0] ?? `${asset.name}.map`;
|
|
124
|
+
if (!compilation.getAsset(mapName)) continue;
|
|
125
|
+
entries.push({
|
|
126
|
+
chunkId,
|
|
127
|
+
fileName: asset.name,
|
|
128
|
+
// Read from the compilation when it is sent, not held here.
|
|
129
|
+
load: async () => {
|
|
130
|
+
const source = compilation.getAsset(mapName)?.source.source();
|
|
131
|
+
if (source === void 0) throw new Error(`${mapName} is no longer in the compilation`);
|
|
132
|
+
return typeof source === "string" ? source : Buffer.from(source);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
const outcome = await chunk7TKNT3QJ_cjs.runUpload(entries, {
|
|
137
|
+
apiKey: connection.apiKey,
|
|
138
|
+
host: connection.host,
|
|
139
|
+
release: releaseFor(compilation),
|
|
140
|
+
dryRun: options.dryRun,
|
|
141
|
+
uploadTimeoutMs: options.uploadTimeoutMs,
|
|
142
|
+
uploadConcurrency: options.uploadConcurrency,
|
|
143
|
+
uploadProtocol: options.uploadProtocol,
|
|
144
|
+
logger
|
|
145
|
+
});
|
|
146
|
+
if (!outcome.ok) failure = outcome.error ?? "source map upload failed";
|
|
147
|
+
}
|
|
148
|
+
} catch (error) {
|
|
149
|
+
failure = chunk7TKNT3QJ_cjs.errorMessage(error);
|
|
150
|
+
logger.error(`source maps: ${failure}`);
|
|
151
|
+
} finally {
|
|
152
|
+
if (chunk7TKNT3QJ_cjs.shouldDeleteSourcemaps(owner, options)) {
|
|
153
|
+
try {
|
|
154
|
+
const removed = removeMapAssets(compilation);
|
|
155
|
+
if (removed > 0) {
|
|
156
|
+
logger.info(
|
|
157
|
+
owner === "starko" ? `removed ${removed} source map(s) from the output (switched on for the upload only)` : `removed ${removed} source map(s) from the output`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
} catch (error) {
|
|
161
|
+
logger.error(`could not remove the source maps from the output: ${chunk7TKNT3QJ_cjs.errorMessage(error)}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (failure && options.failOnError) compilation.errors.push(new WebpackError(`[starko] ${failure}`));
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
function findSourceMapPlugin(compiler) {
|
|
170
|
+
try {
|
|
171
|
+
const { SourceMapDevToolPlugin, EvalSourceMapDevToolPlugin } = compiler.webpack;
|
|
172
|
+
let found;
|
|
173
|
+
for (const p of compiler.options.plugins || []) {
|
|
174
|
+
if (!p || typeof p !== "object") continue;
|
|
175
|
+
const name = p.constructor?.name;
|
|
176
|
+
if (EvalSourceMapDevToolPlugin && p instanceof EvalSourceMapDevToolPlugin || name === "EvalSourceMapDevToolPlugin") return "eval";
|
|
177
|
+
if (SourceMapDevToolPlugin && p instanceof SourceMapDevToolPlugin || name === "SourceMapDevToolPlugin") found = "maps";
|
|
178
|
+
}
|
|
179
|
+
return found;
|
|
180
|
+
} catch {
|
|
181
|
+
return void 0;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
var webpack_default = StarkoWebpackPlugin;
|
|
185
|
+
|
|
186
|
+
exports.StarkoWebpackPlugin = StarkoWebpackPlugin;
|
|
187
|
+
exports.webpack_default = webpack_default;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { openRequestScope, readScope, currentRequestKey, platformWaitUntil, flushIfPending } from './chunk-N5R6ORIB.js';
|
|
2
|
+
import { isNextControlFlow, describeRequestError, nextControlFlowIntegration } from './chunk-EC2WZ6PG.js';
|
|
3
|
+
import { captureException } from './chunk-WDKRKGYF.js';
|
|
4
|
+
|
|
5
|
+
// src/next/server-common.ts
|
|
6
|
+
var LAST_RESORT_FLUSH_MS = 500;
|
|
7
|
+
function isServerless() {
|
|
8
|
+
try {
|
|
9
|
+
const env = typeof process !== "undefined" && process.env ? process.env : {};
|
|
10
|
+
return !!(env.VERCEL || env.AWS_LAMBDA_FUNCTION_NAME || env.NETLIFY || env.FUNCTION_TARGET || env.FUNCTIONS_WORKER_RUNTIME);
|
|
11
|
+
} catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
async function scheduleFlush(flushTimeout, runtime) {
|
|
16
|
+
try {
|
|
17
|
+
const waitUntil = platformWaitUntil();
|
|
18
|
+
if (waitUntil) {
|
|
19
|
+
waitUntil(flushIfPending(flushTimeout, true));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (runtime === "nodejs" && !isServerless()) return;
|
|
23
|
+
await flushIfPending(Math.min(flushTimeout, LAST_RESORT_FLUSH_MS), true);
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function captureNextRequestError(error, request, context, flushTimeout, runtime) {
|
|
28
|
+
if (isNextControlFlow(error)) return;
|
|
29
|
+
const d = describeRequestError(error, request, context);
|
|
30
|
+
openRequestScope(
|
|
31
|
+
() => {
|
|
32
|
+
captureException(error, d.hint);
|
|
33
|
+
},
|
|
34
|
+
d.request,
|
|
35
|
+
void 0,
|
|
36
|
+
readScope(),
|
|
37
|
+
currentRequestKey()
|
|
38
|
+
);
|
|
39
|
+
await scheduleFlush(flushTimeout, runtime);
|
|
40
|
+
}
|
|
41
|
+
function withNextDefaults(options) {
|
|
42
|
+
if (!options || options.defaultIntegrations === false) return options;
|
|
43
|
+
const user = options.integrations;
|
|
44
|
+
return {
|
|
45
|
+
...options,
|
|
46
|
+
integrations: (defaults) => {
|
|
47
|
+
const withNext = [...defaults, nextControlFlowIntegration()];
|
|
48
|
+
return typeof user === "function" ? user(withNext) : [...withNext, ...user || []];
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { captureNextRequestError, withNextDefaults };
|