@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,249 @@
1
+ import { isTagged, isEventLike, isString, isPrimitive, safeString, isError, isPlainObject, truncate, normalizeToSize } from './chunk-WDKRKGYF.js';
2
+ import { NATIVE_DEBUG_ID_GLOBAL, DEBUG_ID_GLOBAL, LIMITS, RELEASE_GLOBAL } from './chunk-3AW5B2WW.js';
3
+
4
+ // src/core/debug-ids.ts
5
+ var SENTRY_DEBUG_ID_GLOBAL = "_sentryDebugIds";
6
+ var GLOBALS = [SENTRY_DEBUG_ID_GLOBAL, NATIVE_DEBUG_ID_GLOBAL, DEBUG_ID_GLOBAL];
7
+ var cache;
8
+ var fileOfStack = /* @__PURE__ */ new Map();
9
+ function readGlobal(name) {
10
+ try {
11
+ const v = globalThis[name];
12
+ return v && typeof v === "object" ? v : void 0;
13
+ } catch {
14
+ return void 0;
15
+ }
16
+ }
17
+ function getDebugIdMap(parser) {
18
+ const maps = GLOBALS.map(readGlobal);
19
+ if (!maps.some(Boolean)) return {};
20
+ const keys = maps.map((m) => m ? Object.keys(m) : []);
21
+ const sizes = keys.map((k) => k.length).join(":");
22
+ if (cache && cache.parser === parser && cache.sizes === sizes) return cache.map;
23
+ const map = {};
24
+ const add = (keys2, ids) => {
25
+ for (const stack of keys2) {
26
+ const id = ids[stack];
27
+ if (typeof id !== "string") continue;
28
+ let file = fileOfStack.get(stack);
29
+ if (file === void 0) {
30
+ file = parser(stack).find((f) => f.filename)?.filename ?? null;
31
+ fileOfStack.set(stack, file);
32
+ }
33
+ if (file) map[file] = id;
34
+ }
35
+ };
36
+ maps.forEach((m, i) => m && add(keys[i], m));
37
+ cache = { parser, sizes, map };
38
+ return map;
39
+ }
40
+ function getInjectedRelease() {
41
+ const v = globalThis[RELEASE_GLOBAL];
42
+ if (typeof v === "string" && v) return v;
43
+ if (v && typeof v === "object" && typeof v.id === "string") return v.id;
44
+ return void 0;
45
+ }
46
+
47
+ // src/core/exceptions.ts
48
+ var ERROR_EVENT_MESSAGE = /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/s;
49
+ var get = (o, k) => {
50
+ try {
51
+ return o[k];
52
+ } catch {
53
+ return void 0;
54
+ }
55
+ };
56
+ function className(o) {
57
+ try {
58
+ const name = Object.getPrototypeOf(o)?.constructor?.name;
59
+ return isString(name) && name ? name : void 0;
60
+ } catch {
61
+ return void 0;
62
+ }
63
+ }
64
+ function coerceError(err) {
65
+ const name = get(err, "name");
66
+ const message = get(err, "message");
67
+ const stack = get(err, "stack");
68
+ const out = {
69
+ type: isString(name) && name || className(err) || "Error",
70
+ value: isString(message) ? message : message == null ? "" : safeString(message),
71
+ stack: isString(stack) ? stack : void 0
72
+ };
73
+ const children = [];
74
+ const cause = get(err, "cause");
75
+ if (cause !== void 0 && cause !== null) children.push(["cause", cause]);
76
+ const errors = get(err, "errors");
77
+ if (Array.isArray(errors)) errors.forEach((e, i) => children.push([`errors[${i}]`, e]));
78
+ if (children.length) out.children = children;
79
+ return out;
80
+ }
81
+ function coerce(value, ctx, serialized) {
82
+ if (isTagged(value, "ErrorEvent") || isEventLike(value) && "error" in value && "message" in value) {
83
+ const ev = value;
84
+ const filename = get(ev, "filename");
85
+ const lineno = get(ev, "lineno");
86
+ const colno = get(ev, "colno");
87
+ const locStack = isString(filename) && filename && typeof lineno === "number" && lineno > 0 ? `Error
88
+ at ${filename}:${lineno}:${typeof colno === "number" ? colno : 0}` : void 0;
89
+ const inner = get(ev, "error");
90
+ if (inner !== void 0 && inner !== null) {
91
+ const ex = coerce(inner, { ...ctx, synthetic: void 0 }, serialized);
92
+ if (!ex.stack && locStack) {
93
+ ex.stack = locStack;
94
+ ex.synthetic = false;
95
+ }
96
+ return ex;
97
+ }
98
+ const msg = get(ev, "message");
99
+ const m = ERROR_EVENT_MESSAGE.exec(isString(msg) ? msg : "") || [];
100
+ return { type: m[1] || "Error", value: m[2] || "", stack: locStack };
101
+ }
102
+ if (isTagged(value, "PromiseRejectionEvent") || isEventLike(value) && ("reason" in value || hasDetailReason(value))) {
103
+ let reason = get(value, "reason");
104
+ if (reason === void 0 && hasDetailReason(value)) reason = get(get(value, "detail"), "reason");
105
+ if (isPrimitive(reason)) {
106
+ return {
107
+ type: "UnhandledRejection",
108
+ value: `Non-Error promise rejection captured with value: ${safeString(reason)}`,
109
+ ...syntheticStack(ctx)
110
+ };
111
+ }
112
+ return coerce(reason, ctx, serialized);
113
+ }
114
+ if (isError(value)) {
115
+ const out = coerceError(value);
116
+ if (!out.stack) Object.assign(out, syntheticStack(ctx));
117
+ return out;
118
+ }
119
+ if (isEventLike(value)) {
120
+ const type = get(value, "type");
121
+ return {
122
+ type: className(value) || "Event",
123
+ value: `Event \`${className(value) || "Event"}\` (type=${isString(type) ? type : "unknown"}) captured as exception`,
124
+ ...syntheticStack(ctx)
125
+ };
126
+ }
127
+ if (value !== null && typeof value === "object") {
128
+ const o = value;
129
+ if (isPlainObject(o)) {
130
+ for (const k of Object.keys(o)) {
131
+ const v = get(o, k);
132
+ if (isError(v)) return coerce(v, ctx, serialized);
133
+ }
134
+ }
135
+ const name = get(o, "name");
136
+ const message = get(o, "message");
137
+ const stack = get(o, "stack");
138
+ let text;
139
+ if (isString(message) && message) text = message;
140
+ else {
141
+ const keys = Object.keys(o).sort();
142
+ let list = keys.join(", ");
143
+ if (list.length > 40) list = truncate(list, 40) + "\u2026";
144
+ const cls = className(o);
145
+ text = `${cls && cls !== "Object" ? `'${cls}'` : "Object"} captured as exception with keys: ${list || "[none]"}`;
146
+ }
147
+ if (serialized) serialized.value = normalizeToSize(o, LIMITS.MAX_EXTRA_BYTES / 2, 3);
148
+ const out = { type: isString(name) && name || "Error", value: text };
149
+ if (isString(stack) && stack) out.stack = stack;
150
+ else Object.assign(out, syntheticStack(ctx));
151
+ return out;
152
+ }
153
+ if (isString(value)) return { type: "Error", value, ...syntheticStack(ctx) };
154
+ return { type: "Error", value: safeString(value), ...syntheticStack(ctx) };
155
+ }
156
+ function hasDetailReason(v) {
157
+ const d = get(v, "detail");
158
+ return !!d && typeof d === "object" && "reason" in d;
159
+ }
160
+ function syntheticStack(ctx) {
161
+ const s = ctx.synthetic;
162
+ if (!s || !s.stack) return {};
163
+ return { stack: s.stack, skip: s.skip, synthetic: true };
164
+ }
165
+ function toWireFrames(parsed, ctx) {
166
+ const ids = getDebugIdMap(ctx.parser);
167
+ return parsed.map((p) => {
168
+ const f = { platform: ctx.framePlatform };
169
+ if (p.filename !== void 0) f.filename = p.filename;
170
+ if (p.function !== void 0) f.function = p.function;
171
+ if (p.lineno !== void 0) f.lineno = p.lineno;
172
+ if (p.colno !== void 0) f.colno = p.colno;
173
+ try {
174
+ const inApp = ctx.isInApp && ctx.isInApp(p.filename);
175
+ if (typeof inApp === "boolean") f.in_app = inApp;
176
+ } catch {
177
+ }
178
+ const id = p.filename ? ids[p.filename] : void 0;
179
+ if (id) f.chunk_id = id;
180
+ return f;
181
+ });
182
+ }
183
+ function buildExceptions(value, mechanism, ctx) {
184
+ const ser = {};
185
+ const exceptions = [];
186
+ const seen = /* @__PURE__ */ new Set();
187
+ const handled = mechanism?.handled ?? true;
188
+ const visit = (v, source, parent, depth) => {
189
+ if (exceptions.length >= LIMITS.MAX_EXCEPTIONS) return;
190
+ if (v !== null && typeof v === "object") {
191
+ if (seen.has(v)) return;
192
+ seen.add(v);
193
+ }
194
+ const ex = coerce(v, parent === void 0 ? ctx : { ...ctx, synthetic: void 0 }, parent === void 0 ? ser : void 0);
195
+ const id = exceptions.length;
196
+ const wire = { type: ex.type || "Error", value: ex.value || "" };
197
+ const mech = parent === void 0 ? { type: mechanism?.type || "generic", handled, ...stripUndefined(mechanism) } : { type: "chained", handled, source, exception_id: id, parent_id: parent };
198
+ if (ex.synthetic) mech.synthetic = true;
199
+ wire.mechanism = mech;
200
+ if (ex.stack) {
201
+ const frames = toWireFrames(ctx.parser(ex.stack, ex.skip || 0), ctx);
202
+ if (frames.length) wire.stacktrace = { type: "raw", frames };
203
+ }
204
+ exceptions.push(wire);
205
+ if (depth >= LIMITS.MAX_EXCEPTIONS) return;
206
+ for (const [src, child] of ex.children || []) visit(child, src, id, depth + 1);
207
+ };
208
+ try {
209
+ visit(value, void 0, void 0, 0);
210
+ } catch {
211
+ if (!exceptions.length) exceptions.push({ type: "Error", value: safeString(value), mechanism: { type: mechanism?.type || "generic", handled } });
212
+ }
213
+ if (exceptions.length > 1) exceptions[0].mechanism.exception_id = 0;
214
+ return { exceptions, serialized: ser.value };
215
+ }
216
+ function stripUndefined(o) {
217
+ const out = {};
218
+ if (o) {
219
+ for (const k of Object.keys(o)) if (o[k] !== void 0) out[k] = o[k];
220
+ }
221
+ return out;
222
+ }
223
+ var captured = /* @__PURE__ */ new WeakMap();
224
+ function capturedAs(value) {
225
+ if (!value || typeof value !== "object") return void 0;
226
+ try {
227
+ return captured.get(value);
228
+ } catch {
229
+ return void 0;
230
+ }
231
+ }
232
+ function markCaptured(value, eventId) {
233
+ try {
234
+ if (!value || typeof value !== "object") return;
235
+ captured.set(value, eventId);
236
+ const inner = get(value, "error") || get(value, "reason");
237
+ if (isEventLike(value) && inner && typeof inner === "object") captured.set(inner, eventId);
238
+ } catch {
239
+ }
240
+ }
241
+ function unwrapThrown(value) {
242
+ if (isEventLike(value)) {
243
+ const inner = get(value, "error") || get(value, "reason");
244
+ if (inner && typeof inner === "object") return inner;
245
+ }
246
+ return value;
247
+ }
248
+
249
+ export { buildExceptions, capturedAs, coerce, getDebugIdMap, getInjectedRelease, markCaptured, toWireFrames, unwrapThrown };
@@ -0,0 +1,115 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // src/types/wire.ts
9
+ var WIRE_VERSION = 1;
10
+ var LIMITS = {
11
+ MAX_EVENTS_PER_ENVELOPE: 20,
12
+ /** Bytes of the request body as sent (after gzip when compressed). */
13
+ MAX_BODY_BYTES: 512 * 1024,
14
+ /** Bytes after decompression. */
15
+ MAX_INFLATED_BYTES: 2 * 1024 * 1024,
16
+ MAX_EXCEPTIONS: 10,
17
+ /** Beyond it the 25 most recent and the 25 oldest frames are kept (the middle of a deep recursion is dropped). */
18
+ MAX_FRAMES: 50,
19
+ /** Distinct `chunk_id`s the server resolves per event; frames of further chunks stay unresolved. */
20
+ MAX_CHUNK_IDS_PER_EVENT: 8,
21
+ /** Nesting depth of the JSON body; deeper bodies are rejected before any processing. */
22
+ MAX_JSON_DEPTH: 20,
23
+ MAX_TYPE: 200,
24
+ MAX_VALUE: 2e3,
25
+ MAX_FILENAME: 1e3,
26
+ MAX_FUNCTION: 300,
27
+ MAX_CONTEXT_LINE: 300,
28
+ /** Lines in each of pre_context / post_context. */
29
+ MAX_CONTEXT_LINES: 7,
30
+ MAX_BREADCRUMBS: 50,
31
+ /** Serialized bytes of all breadcrumbs. */
32
+ MAX_BREADCRUMB_BYTES: 32 * 1024,
33
+ MAX_TAGS: 50,
34
+ MAX_TAG_KEY: 64,
35
+ MAX_TAG_VALUE: 256,
36
+ /** Serialized bytes of `extra` and of `contexts`, each. */
37
+ MAX_EXTRA_BYTES: 16 * 1024,
38
+ MAX_FINGERPRINT: 128,
39
+ MAX_RELEASE: 128,
40
+ MAX_ENVIRONMENT: 64,
41
+ MAX_URL: 2048
42
+ };
43
+ var SESSION_ID_PATTERN = /^[A-Za-z0-9-]{8,70}$/;
44
+ var PATHS = {
45
+ INGEST: "/api/v1/ingest/errors",
46
+ CONFIG: "/api/v1/ingest/config",
47
+ SOURCEMAPS_CHECK: "/api/v1/sourcemaps/check",
48
+ SOURCEMAPS_UPLOAD: "/api/v1/sourcemaps/upload",
49
+ SOURCEMAPS_COMPLETE: "/api/v1/sourcemaps/complete",
50
+ /** Bulk upload (wire format v1, upload v2): see "Source-map bulk upload" below. */
51
+ SOURCEMAPS_BULK_CHECK: "/api/v1/sourcemaps/bulk/check",
52
+ SOURCEMAPS_BULK_START: "/api/v1/sourcemaps/bulk/start",
53
+ SOURCEMAPS_BULK_FINISH: "/api/v1/sourcemaps/bulk/finish"
54
+ };
55
+ var DEFAULT_HOST = "https://v2.starko.one";
56
+ var SENSITIVE_QUERY_PARAMS = [
57
+ "token",
58
+ "access_token",
59
+ "id_token",
60
+ "refresh_token",
61
+ "code",
62
+ "key",
63
+ "api_key",
64
+ "apikey",
65
+ "secret",
66
+ "password",
67
+ "passwd",
68
+ "pwd",
69
+ "auth",
70
+ "authorization",
71
+ "session",
72
+ "sessionid",
73
+ "sid",
74
+ "sig",
75
+ "signature",
76
+ "jwt",
77
+ "otp",
78
+ "pin",
79
+ "email",
80
+ "phone",
81
+ "ssn",
82
+ "x-amz-signature",
83
+ "x-amz-credential",
84
+ "x-amz-security-token"
85
+ ];
86
+ var REDACTED = "[redacted]";
87
+ var SOURCEMAP_PART_BYTES = 3 * 1024 * 1024;
88
+ var SOURCEMAP_MAX_BYTES = 64 * 1024 * 1024;
89
+ var SOURCEMAP_MAX_PARTS = 32;
90
+ var SOURCEMAP_MAX_CHUNKS_PER_CHECK = 500;
91
+ var SOURCEMAP_MAX_FILE_NAME = 512;
92
+ var SOURCEMAP_ROUTE_MAX_SECONDS = {
93
+ CHECK: 30,
94
+ UPLOAD: 60,
95
+ COMPLETE: 60,
96
+ BULK_CHECK: 30,
97
+ BULK_START: 30,
98
+ BULK_FINISH: 120
99
+ };
100
+ var SOURCEMAP_BULK_MAX_CHECK = 1e3;
101
+ var SOURCEMAP_BULK_MAX_MAPS = 200;
102
+ var SOURCEMAP_BULK_MAX_OBJECT_BYTES = Math.ceil(SOURCEMAP_MAX_BYTES * 1.01);
103
+ var SOURCEMAP_BULK_UPLOAD_CONCURRENCY = 16;
104
+ var SOURCEMAP_BULK_REQUEST_CONCURRENCY = 2;
105
+ var SOURCEMAP_BULK_VERIFY_PER_WORKSPACE = 6;
106
+ var DEBUG_ID_GLOBAL = "_starkoDebugIds";
107
+ var NATIVE_DEBUG_ID_GLOBAL = "_debugIds";
108
+ var RELEASE_GLOBAL = "_starkoRelease";
109
+ var DEBUG_ID_COMMENT = "//# debugId=";
110
+ var DEBUG_ID_NAMESPACE = "6f2d3c1e-9b4a-4f07-8a55-7c1e0d9b2a41";
111
+
112
+ // package.json
113
+ var version = "0.1.0-beta.1";
114
+
115
+ export { DEBUG_ID_COMMENT, DEBUG_ID_GLOBAL, DEBUG_ID_NAMESPACE, DEFAULT_HOST, LIMITS, NATIVE_DEBUG_ID_GLOBAL, PATHS, REDACTED, RELEASE_GLOBAL, SENSITIVE_QUERY_PARAMS, SESSION_ID_PATTERN, SOURCEMAP_BULK_MAX_CHECK, SOURCEMAP_BULK_MAX_MAPS, SOURCEMAP_BULK_MAX_OBJECT_BYTES, SOURCEMAP_BULK_REQUEST_CONCURRENCY, SOURCEMAP_BULK_UPLOAD_CONCURRENCY, SOURCEMAP_BULK_VERIFY_PER_WORKSPACE, SOURCEMAP_MAX_BYTES, SOURCEMAP_MAX_CHUNKS_PER_CHECK, SOURCEMAP_MAX_FILE_NAME, SOURCEMAP_MAX_PARTS, SOURCEMAP_PART_BYTES, SOURCEMAP_ROUTE_MAX_SECONDS, WIRE_VERSION, __require, version };
@@ -0,0 +1,216 @@
1
+ import { resolveConnection, createLogger, createFileFilter, NO_API_KEY_MESSAGE, runUpload, errorMessage, shouldDeleteSourcemaps, findDebugId, hasStarkoRegistration, planInjection, resolveReleaseInfo, findSourceMappingUrl, stripSourceMappingUrl, stripCssSourceMappingUrl, injectDebugId, localMapReference } from './chunk-XOZIXBUK.js';
2
+ import path from 'path';
3
+ import MagicString from 'magic-string';
4
+
5
+ function isRolldown(context) {
6
+ return Boolean(context.meta?.rolldownVersion);
7
+ }
8
+ function assetText(asset) {
9
+ return typeof asset.source === "string" ? asset.source : Buffer.from(asset.source).toString("utf8");
10
+ }
11
+ var SWITCHED_ON = /* @__PURE__ */ Symbol.for("starko.sdk.rollup.sourcemapSwitchedOn");
12
+ function markSwitchedOn(user) {
13
+ const transform = function(relativeSourcePath, sourcemapPath) {
14
+ return typeof user === "function" ? user.call(this, relativeSourcePath, sourcemapPath) : relativeSourcePath;
15
+ };
16
+ Object.defineProperty(transform, SWITCHED_ON, { value: true });
17
+ return transform;
18
+ }
19
+ function switchedOn(output) {
20
+ try {
21
+ const t = output.sourcemapPathTransform;
22
+ return typeof t === "function" && t[SWITCHED_ON] === true;
23
+ } catch {
24
+ return false;
25
+ }
26
+ }
27
+ function removeMapAssets(bundle) {
28
+ const removed = /* @__PURE__ */ new Set();
29
+ for (const [fileName, file] of Object.entries(bundle)) {
30
+ if (file.type === "asset" && fileName.endsWith(".map")) {
31
+ delete bundle[fileName];
32
+ removed.add(fileName);
33
+ }
34
+ }
35
+ if (removed.size === 0) return 0;
36
+ const pointsAtRemoved = (fileName, url) => {
37
+ const local = localMapReference(url);
38
+ if (local === void 0) return false;
39
+ return removed.has(path.posix.normalize(path.posix.join(path.posix.dirname(fileName), local)));
40
+ };
41
+ for (const file of Object.values(bundle)) {
42
+ if (file.type === "chunk") {
43
+ const ref = findSourceMappingUrl(file.code);
44
+ if (ref && pointsAtRemoved(file.fileName, ref.url)) file.code = stripSourceMappingUrl(file.code, ref);
45
+ } else if (file.fileName.endsWith(".css")) {
46
+ const css = assetText(file);
47
+ const stripped = stripCssSourceMappingUrl(css, (url) => pointsAtRemoved(file.fileName, url));
48
+ if (stripped !== css) file.source = stripped;
49
+ }
50
+ }
51
+ return removed.size;
52
+ }
53
+ function createStarkoRollupPlugin(options = {}, internals = {}) {
54
+ const connection = resolveConnection(options);
55
+ const logger = createLogger({ silent: options.silent, secrets: [connection.apiKey] });
56
+ const filter = createFileFilter(options);
57
+ let enabled = false;
58
+ let release;
59
+ let releaseResolved = false;
60
+ let warnedNoKey = false;
61
+ const resolveEnabled = (context) => {
62
+ const wanted = internals.isEnabled ? internals.isEnabled(context) : options.enabled ?? (!context.meta.watchMode && process.env.NODE_ENV !== "development");
63
+ if (wanted && !connection.apiKey) {
64
+ if (!warnedNoKey) logger.warn(NO_API_KEY_MESSAGE);
65
+ warnedNoKey = true;
66
+ return false;
67
+ }
68
+ return wanted;
69
+ };
70
+ const ownerOf = (output) => internals.sourcemapOwner ? internals.sourcemapOwner() : switchedOn(output) ? "starko" : "user";
71
+ const getRelease = () => {
72
+ if (!releaseResolved) {
73
+ release = resolveReleaseInfo(options.release);
74
+ releaseResolved = true;
75
+ }
76
+ return release;
77
+ };
78
+ const prepareChunks = (bundle, rolldown) => {
79
+ const entries = [];
80
+ for (const chunk of Object.values(bundle)) {
81
+ if (chunk.type !== "chunk" || !filter(chunk.fileName)) continue;
82
+ try {
83
+ const entry = prepareChunk(bundle, chunk, rolldown);
84
+ if (entry) entries.push(entry);
85
+ } catch (error) {
86
+ logger.warn(`could not process ${chunk.fileName}: ${errorMessage(error)}`);
87
+ }
88
+ }
89
+ return entries;
90
+ };
91
+ const prepareChunk = (bundle, chunk, rolldown) => {
92
+ const mapFileName = chunk.sourcemapFileName ?? `${chunk.fileName}.map`;
93
+ const mapAsset = bundle[mapFileName];
94
+ if (!mapAsset || mapAsset.type !== "asset") return void 0;
95
+ let map;
96
+ try {
97
+ map = JSON.parse(assetText(mapAsset));
98
+ } catch {
99
+ logger.warn(`could not read ${mapFileName}; ${chunk.fileName} is not processed`);
100
+ return void 0;
101
+ }
102
+ let chunkId = findDebugId(chunk.code);
103
+ if (rolldown && (!chunkId || !hasStarkoRegistration(chunk.code, chunkId))) {
104
+ const out = injectDebugId(chunk.code, map, { release: getRelease()?.version });
105
+ chunk.code = out.code;
106
+ map = out.map;
107
+ chunkId = out.debugId;
108
+ if (chunk.map) Object.assign(chunk.map, { mappings: map.mappings });
109
+ }
110
+ if (!chunkId) return void 0;
111
+ if (map.debugId !== chunkId) map = { ...map, debugId: chunkId };
112
+ const text = JSON.stringify(map);
113
+ mapAsset.source = text;
114
+ if (chunk.map) chunk.map.debugId = chunkId;
115
+ return { chunkId, map: text, fileName: chunk.fileName };
116
+ };
117
+ return {
118
+ name: internals.name ?? "starko-rollup-plugin",
119
+ buildStart() {
120
+ enabled = resolveEnabled(this);
121
+ releaseResolved = false;
122
+ },
123
+ outputOptions: {
124
+ order: "post",
125
+ handler(output) {
126
+ enabled = resolveEnabled(this);
127
+ if (!enabled) return null;
128
+ const next = { ...output };
129
+ if (!next.sourcemap) {
130
+ next.sourcemap = "hidden";
131
+ next.sourcemapPathTransform = markSwitchedOn(next.sourcemapPathTransform);
132
+ }
133
+ if (next.sourcemap === "inline") {
134
+ logger.warn("inline source maps are not uploaded; use `sourcemap: true` or `'hidden'`");
135
+ }
136
+ if (next.sourcemapDebugIds) {
137
+ next.sourcemapDebugIds = false;
138
+ logger.info("output.sourcemapDebugIds is turned off: the Starko plugin writes the debug ids");
139
+ }
140
+ return next;
141
+ }
142
+ },
143
+ // Rollup: inject after every other renderChunk hook (minifiers included),
144
+ // before file hashes and generateBundle, so the written files are final.
145
+ // Rollup composes the returned map with the chunk's map.
146
+ renderChunk: {
147
+ order: "post",
148
+ handler(code, chunk, output) {
149
+ if (!enabled || isRolldown(this) || !output.sourcemap || output.sourcemap === "inline") return null;
150
+ if (!filter(chunk.fileName)) return null;
151
+ try {
152
+ const existing = findDebugId(code);
153
+ if (existing && hasStarkoRegistration(code, existing)) return null;
154
+ const plan = planInjection(code, { release: getRelease()?.version, debugId: existing });
155
+ const s = new MagicString(code);
156
+ s.appendLeft(plan.snippet.offset, plan.snippet.text);
157
+ if (!existing) s.appendLeft(plan.comment.offset, plan.comment.text);
158
+ return { code: s.toString(), map: s.generateMap({ hires: "boundary" }) };
159
+ } catch (error) {
160
+ logger.warn(`could not inject ${chunk.fileName}: ${errorMessage(error)}`);
161
+ return null;
162
+ }
163
+ }
164
+ },
165
+ // Last generateBundle hook: every map gets its `debugId`, the maps are
166
+ // uploaded from memory, and then, whatever happened, the maps that must
167
+ // not ship are removed from the bundle so they are never written.
168
+ generateBundle: {
169
+ order: "post",
170
+ async handler(output, bundle) {
171
+ if (!enabled || !output.sourcemap || output.sourcemap === "inline") return;
172
+ const owner = ownerOf(output);
173
+ let failure;
174
+ try {
175
+ const entries = prepareChunks(bundle, isRolldown(this));
176
+ if (entries.length > 0) {
177
+ const outcome = await runUpload(entries, {
178
+ apiKey: connection.apiKey,
179
+ host: connection.host,
180
+ release: getRelease(),
181
+ dryRun: options.dryRun,
182
+ uploadTimeoutMs: options.uploadTimeoutMs,
183
+ uploadConcurrency: options.uploadConcurrency,
184
+ uploadProtocol: options.uploadProtocol,
185
+ logger
186
+ });
187
+ if (!outcome.ok) failure = outcome.error ?? "source map upload failed";
188
+ }
189
+ } catch (error) {
190
+ failure = errorMessage(error);
191
+ logger.error(`source maps: ${failure}`);
192
+ } finally {
193
+ if (shouldDeleteSourcemaps(owner, options)) {
194
+ try {
195
+ const removed = removeMapAssets(bundle);
196
+ if (removed > 0) {
197
+ logger.info(
198
+ owner === "starko" ? `removed ${removed} source map(s) from the output (switched on for the upload only)` : `removed ${removed} source map(s) from the output`
199
+ );
200
+ }
201
+ } catch (error) {
202
+ logger.error(`could not remove the source maps from the output: ${errorMessage(error)}`);
203
+ }
204
+ }
205
+ }
206
+ if (failure && options.failOnError) this.error(`[starko] ${failure}`);
207
+ }
208
+ }
209
+ };
210
+ }
211
+ function starkoRollupPlugin(options = {}) {
212
+ return createStarkoRollupPlugin(options);
213
+ }
214
+ var rollup_default = starkoRollupPlugin;
215
+
216
+ export { createStarkoRollupPlugin, rollup_default, starkoRollupPlugin };