@starko-one/sdk 0.0.0-stage → 0.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/LICENSE +17 -0
  3. package/NOTICE +58 -0
  4. package/README.md +81 -2
  5. package/dist/api-B5IHeINe.d.ts +558 -0
  6. package/dist/api-DR4HazCu.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-7HYGODU6.cjs +583 -0
  24. package/dist/chunk-A5M4NOVT.js +413 -0
  25. package/dist/chunk-A7MYYWMP.cjs +15 -0
  26. package/dist/chunk-BAQA47FM.js +1113 -0
  27. package/dist/chunk-CM7HM6CC.js +563 -0
  28. package/dist/chunk-DFYNIWUN.js +608 -0
  29. package/dist/chunk-DMVVCGKO.cjs +96 -0
  30. package/dist/chunk-FARGXYJ4.cjs +56 -0
  31. package/dist/chunk-G3MYIAX2.js +1226 -0
  32. package/dist/chunk-G4NAVZQ4.js +249 -0
  33. package/dist/chunk-GH7RYPKS.js +96 -0
  34. package/dist/chunk-HADYYQNL.cjs +134 -0
  35. package/dist/chunk-HOQPAB4X.js +178 -0
  36. package/dist/chunk-J5RU73SW.js +214 -0
  37. package/dist/chunk-JNAJ3YZB.cjs +223 -0
  38. package/dist/chunk-KN7H22EQ.cjs +659 -0
  39. package/dist/chunk-LDQ4I7FZ.cjs +1151 -0
  40. package/dist/chunk-NPGESRVQ.js +1212 -0
  41. package/dist/chunk-OPWM5V7A.cjs +258 -0
  42. package/dist/chunk-PYYWPIFL.cjs +1230 -0
  43. package/dist/chunk-R7JLZ4WO.cjs +115 -0
  44. package/dist/chunk-SC6VQSES.js +213 -0
  45. package/dist/chunk-TPSJGLR3.cjs +220 -0
  46. package/dist/chunk-UKBY6HPC.js +131 -0
  47. package/dist/chunk-VRSEHRBX.cjs +185 -0
  48. package/dist/chunk-X74AONZA.js +90 -0
  49. package/dist/chunk-XW3I5CJN.js +12 -0
  50. package/dist/chunk-XW56FKKJ.js +53 -0
  51. package/dist/chunk-Z3G5SW7R.cjs +1251 -0
  52. package/dist/chunk-ZVMAN7OO.cjs +431 -0
  53. package/dist/cli/index.cjs +1487 -0
  54. package/dist/common-ARWXbeS3.d.ts +36 -0
  55. package/dist/common-CwIFh2hK.d.cts +36 -0
  56. package/dist/dedupe-eHBIfUUD.d.cts +13 -0
  57. package/dist/dedupe-fw8aNtt4.d.ts +13 -0
  58. package/dist/handler-DTZ4Rzcf.d.ts +82 -0
  59. package/dist/handler-_00lctTI.d.cts +82 -0
  60. package/dist/index.cjs +277 -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 +275 -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 +261 -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-0BhybO54.d.cts +47 -0
  81. package/dist/options-0BhybO54.d.ts +47 -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-Bvh45bOf.d.cts +404 -0
  87. package/dist/scope-Bvh45bOf.d.ts +404 -0
  88. package/dist/server-edge-BPOGA3GH.cjs +51 -0
  89. package/dist/server-edge-GYKAJREU.js +48 -0
  90. package/dist/server-node-HYK2OB2J.js +24 -0
  91. package/dist/server-node-J2DBAHDV.cjs +27 -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-B7REA7uy.d.cts +30 -0
  95. package/dist/session-propagation-BnJjKJbR.d.ts +30 -0
  96. package/dist/starko.min.js +6 -0
  97. package/docs/browser.md +381 -0
  98. package/docs/configuration.md +269 -0
  99. package/docs/nextjs.md +312 -0
  100. package/docs/node.md +376 -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 +332 -0
  105. package/docs/troubleshooting.md +171 -0
  106. package/docs/widget.md +84 -0
  107. package/docs/wire-format.md +367 -0
  108. package/package.json +98 -4
@@ -0,0 +1,249 @@
1
+ import { isTagged, isEventLike, isString, isPrimitive, safeString, isError, isPlainObject, truncate, normalizeToSize } from './chunk-DFYNIWUN.js';
2
+ import { NATIVE_DEBUG_ID_GLOBAL, DEBUG_ID_GLOBAL, LIMITS, RELEASE_GLOBAL } from './chunk-GH7RYPKS.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,96 @@
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
+ };
51
+ var DEFAULT_HOST = "https://v2.starko.one";
52
+ var SENSITIVE_QUERY_PARAMS = [
53
+ "token",
54
+ "access_token",
55
+ "id_token",
56
+ "refresh_token",
57
+ "code",
58
+ "key",
59
+ "api_key",
60
+ "apikey",
61
+ "secret",
62
+ "password",
63
+ "passwd",
64
+ "pwd",
65
+ "auth",
66
+ "authorization",
67
+ "session",
68
+ "sessionid",
69
+ "sid",
70
+ "sig",
71
+ "signature",
72
+ "jwt",
73
+ "otp",
74
+ "pin",
75
+ "email",
76
+ "phone",
77
+ "ssn",
78
+ "x-amz-signature",
79
+ "x-amz-credential",
80
+ "x-amz-security-token"
81
+ ];
82
+ var REDACTED = "[redacted]";
83
+ var SOURCEMAP_PART_BYTES = 3 * 1024 * 1024;
84
+ var SOURCEMAP_MAX_BYTES = 64 * 1024 * 1024;
85
+ var SOURCEMAP_MAX_PARTS = 32;
86
+ var SOURCEMAP_MAX_CHUNKS_PER_CHECK = 500;
87
+ var DEBUG_ID_GLOBAL = "_starkoDebugIds";
88
+ var NATIVE_DEBUG_ID_GLOBAL = "_debugIds";
89
+ var RELEASE_GLOBAL = "_starkoRelease";
90
+ var DEBUG_ID_COMMENT = "//# debugId=";
91
+ var DEBUG_ID_NAMESPACE = "6f2d3c1e-9b4a-4f07-8a55-7c1e0d9b2a41";
92
+
93
+ // package.json
94
+ var version = "0.1.0-beta.0";
95
+
96
+ 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_MAX_BYTES, SOURCEMAP_MAX_CHUNKS_PER_CHECK, SOURCEMAP_MAX_PARTS, SOURCEMAP_PART_BYTES, WIRE_VERSION, __require, version };
@@ -0,0 +1,134 @@
1
+ 'use strict';
2
+
3
+ var chunkKN7H22EQ_cjs = require('./chunk-KN7H22EQ.cjs');
4
+ var chunkR7JLZ4WO_cjs = require('./chunk-R7JLZ4WO.cjs');
5
+
6
+ // src/browser/transport.ts
7
+ var KEEPALIVE_BUDGET = 60 * 1024;
8
+ var REQUEST_TIMEOUT_MS = 12e3;
9
+ function currentFetch() {
10
+ try {
11
+ const f = chunkKN7H22EQ_cjs.originalOf(globalThis, "fetch");
12
+ return typeof f === "function" ? f.bind(globalThis) : void 0;
13
+ } catch {
14
+ return void 0;
15
+ }
16
+ }
17
+ var loadedFetch = currentFetch();
18
+ function parseRetryAfter(header, now = Date.now()) {
19
+ if (!header) return void 0;
20
+ const secs = Number(header);
21
+ if (!isNaN(secs)) return Math.max(0, secs);
22
+ const at = Date.parse(header);
23
+ return isNaN(at) ? void 0 : Math.max(0, Math.ceil((at - now) / 1e3));
24
+ }
25
+ function worst(results) {
26
+ const rank = (s) => s === 401 || s === 403 ? 6 : s === 413 ? 5 : s === 429 ? 4 : s === 0 || s >= 500 ? 3 : s >= 400 ? 2 : 1;
27
+ return results.reduce((a, b) => rank(b.status) > rank(a.status) ? b : a, { status: 200 });
28
+ }
29
+ function splitEnvelope(env, budget) {
30
+ const head = chunkKN7H22EQ_cjs.utf8Length(chunkKN7H22EQ_cjs.safeStringify({ ...env, events: [] }));
31
+ const out = [];
32
+ let cur = { ...env, events: [] };
33
+ let bytes = head;
34
+ for (const e of env.events) {
35
+ const size = chunkKN7H22EQ_cjs.utf8Length(chunkKN7H22EQ_cjs.safeStringify(e)) + 1;
36
+ if (cur.events.length && bytes + size > budget) {
37
+ out.push({ env: cur, bytes });
38
+ cur = { ...env, events: [] };
39
+ bytes = head;
40
+ }
41
+ cur.events.push(e);
42
+ bytes += size;
43
+ }
44
+ if (cur.events.length) out.push({ env: cur, bytes });
45
+ return out;
46
+ }
47
+ function makeFetchTransport(options) {
48
+ const host = options.host.replace(/\/+$/, "");
49
+ const timeoutMs = Math.max(1, chunkKN7H22EQ_cjs.num(options.timeoutMs, REQUEST_TIMEOUT_MS));
50
+ const getFetch = () => options.fetchImpl || loadedFetch || currentFetch();
51
+ let keepaliveBytes = 0;
52
+ const timed = (fallback, request) => {
53
+ const f = getFetch();
54
+ if (!f) return Promise.resolve(fallback);
55
+ let ctl;
56
+ try {
57
+ ctl = new AbortController();
58
+ } catch {
59
+ }
60
+ let t;
61
+ let p;
62
+ try {
63
+ p = request(f, ctl && ctl.signal).catch(() => fallback);
64
+ } catch {
65
+ p = Promise.resolve(fallback);
66
+ }
67
+ const deadline = new Promise((r) => {
68
+ t = setTimeout(() => {
69
+ try {
70
+ if (ctl) ctl.abort();
71
+ } catch {
72
+ }
73
+ r(fallback);
74
+ }, timeoutMs);
75
+ chunkKN7H22EQ_cjs.unref(t);
76
+ });
77
+ return Promise.race([p, deadline]).then((v) => {
78
+ clearTimeout(t);
79
+ return v;
80
+ });
81
+ };
82
+ const post = (body, keepalive) => timed({ status: 0 }, async (f, signal) => {
83
+ const res = await f(host + chunkR7JLZ4WO_cjs.PATHS.INGEST, {
84
+ method: "POST",
85
+ body,
86
+ headers: { "Content-Type": "text/plain;charset=UTF-8" },
87
+ keepalive,
88
+ credentials: "omit",
89
+ redirect: "manual",
90
+ signal
91
+ });
92
+ const out = { status: res.type === "opaqueredirect" ? 302 : res.status };
93
+ try {
94
+ out.retryAfter = parseRetryAfter(res.headers.get("Retry-After"));
95
+ } catch {
96
+ }
97
+ if (out.status >= 400) {
98
+ try {
99
+ const reason = (await res.json())?.data?.reason;
100
+ if (typeof reason === "string") out.reason = reason;
101
+ } catch {
102
+ }
103
+ }
104
+ return out;
105
+ });
106
+ return {
107
+ async send(envelope, opts = {}) {
108
+ if (!opts || !opts.keepalive) return post(chunkKN7H22EQ_cjs.safeStringify(envelope), false);
109
+ const results = await Promise.all(
110
+ splitEnvelope(envelope, KEEPALIVE_BUDGET).map(({ env, bytes }) => {
111
+ const fits = keepaliveBytes + bytes <= KEEPALIVE_BUDGET;
112
+ if (fits) keepaliveBytes += bytes;
113
+ return post(chunkKN7H22EQ_cjs.safeStringify({ ...env, sent_at: Date.now() }), fits).then((r) => {
114
+ if (fits) keepaliveBytes -= bytes;
115
+ return r;
116
+ });
117
+ })
118
+ );
119
+ return worst(results);
120
+ },
121
+ fetchConfig() {
122
+ return timed(null, async (f, signal) => {
123
+ const res = await f(`${host}${chunkR7JLZ4WO_cjs.PATHS.CONFIG}?workspace=${encodeURIComponent(options.workspaceKey)}`, { method: "GET", credentials: "omit", redirect: "manual", signal });
124
+ if (res.type === "opaqueredirect" || res.status >= 300 && res.status < 400) 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
+ });
129
+ }
130
+ };
131
+ }
132
+
133
+ exports.makeFetchTransport = makeFetchTransport;
134
+ exports.parseRetryAfter = parseRetryAfter;
@@ -0,0 +1,178 @@
1
+ import { createLogger, resolveConnection, NO_API_KEY_MESSAGE, createFileFilter, injectDebugId, errorMessage, runUpload, shouldDeleteSourcemaps, resolveReleaseInfo, findSourceMappingUrl, stripSourceMappingUrl, stripCssSourceMappingUrl, localMapReference } from './chunk-G3MYIAX2.js';
2
+ import path from 'path';
3
+
4
+ var PLUGIN_NAME = "StarkoWebpackPlugin";
5
+ var INFO_KEY = "starkoDebugId";
6
+ function relatedSourceMaps(info) {
7
+ const related = info.related?.sourceMap;
8
+ return related === void 0 ? [] : Array.isArray(related) ? related : [related];
9
+ }
10
+ var StarkoWebpackPlugin = class {
11
+ constructor(options = {}, internals = {}) {
12
+ this.options = options;
13
+ this.internals = internals;
14
+ this.logger = createLogger({ silent: options.silent, secrets: [resolveConnection(options).apiKey] });
15
+ }
16
+ apply(compiler) {
17
+ const options = this.options;
18
+ const logger = this.logger;
19
+ const enabled = options.enabled ?? compiler.options.mode === "production";
20
+ if (!enabled) return;
21
+ const connection = resolveConnection(options);
22
+ if (!connection.apiKey) {
23
+ logger.warn(NO_API_KEY_MESSAGE);
24
+ return;
25
+ }
26
+ const devtool = compiler.options.devtool;
27
+ const userPlugin = findSourceMapPlugin(compiler);
28
+ let owner = this.internals.sourcemapOwner ?? "user";
29
+ let addedMaps = false;
30
+ if (userPlugin === "eval") {
31
+ logger.warn('an EvalSourceMapDevToolPlugin puts the source maps inside the bundle; use SourceMapDevToolPlugin or devtool "source-map". Nothing is injected or uploaded.');
32
+ return;
33
+ }
34
+ if (!devtool && !userPlugin) {
35
+ new compiler.webpack.SourceMapDevToolPlugin({ filename: "[file].map", append: false }).apply(compiler);
36
+ owner = "starko";
37
+ addedMaps = true;
38
+ } else if (typeof devtool === "string" && /eval|inline/.test(devtool)) {
39
+ logger.warn(`devtool "${devtool}" puts the source map inside the bundle; use "source-map" or "hidden-source-map". Nothing is injected or uploaded.`);
40
+ return;
41
+ }
42
+ const filter = createFileFilter(options);
43
+ const releases = /* @__PURE__ */ new WeakMap();
44
+ const releaseFor = (compilation) => {
45
+ if (!releases.has(compilation)) releases.set(compilation, resolveReleaseInfo(options.release));
46
+ return releases.get(compilation);
47
+ };
48
+ const { Compilation: CompilationClass, sources, WebpackError } = compiler.webpack;
49
+ const before = /* @__PURE__ */ new WeakMap();
50
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
51
+ compilation.hooks.processAssets.tap({ name: PLUGIN_NAME, stage: CompilationClass.PROCESS_ASSETS_STAGE_DEV_TOOLING - 1 }, () => {
52
+ before.set(compilation, new Set(compilation.getAssets().map((a) => a.name).filter((name) => name.endsWith(".map"))));
53
+ });
54
+ compilation.hooks.processAssets.tap(
55
+ { name: PLUGIN_NAME, stage: CompilationClass.PROCESS_ASSETS_STAGE_DEV_TOOLING + 1 },
56
+ () => {
57
+ for (const chunk of compilation.chunks) {
58
+ for (const file of chunk.files) {
59
+ if (!filter(file)) continue;
60
+ try {
61
+ const asset = compilation.getAsset(file);
62
+ if (!asset || typeof asset.info[INFO_KEY] === "string") continue;
63
+ const mapName = relatedSourceMaps(asset.info)[0] ?? `${file}.map`;
64
+ const mapAsset = compilation.getAsset(mapName);
65
+ if (!mapAsset) continue;
66
+ const code = asset.source.source().toString();
67
+ const map = JSON.parse(mapAsset.source.source().toString());
68
+ const out = injectDebugId(code, map, { release: releaseFor(compilation)?.version });
69
+ if (out.injected) compilation.updateAsset(file, new sources.RawSource(out.code), { ...asset.info, [INFO_KEY]: out.debugId });
70
+ else compilation.updateAsset(file, asset.source, { ...asset.info, [INFO_KEY]: out.debugId });
71
+ compilation.updateAsset(mapName, new sources.RawSource(JSON.stringify(out.map)));
72
+ } catch (error) {
73
+ logger.warn(`could not inject ${file}: ${errorMessage(error)}`);
74
+ }
75
+ }
76
+ }
77
+ }
78
+ );
79
+ });
80
+ if (options.upload === false) return;
81
+ const removeMapAssets = (compilation) => {
82
+ const preexisting = addedMaps ? before.get(compilation) : void 0;
83
+ const removed = new Set(
84
+ compilation.getAssets().map((a) => a.name).filter((name) => name.endsWith(".map") && !(preexisting && preexisting.has(name)))
85
+ );
86
+ for (const name of removed) compilation.deleteAsset(name);
87
+ if (removed.size === 0) return 0;
88
+ const pointsAtRemoved = (fileName, url) => {
89
+ const local = localMapReference(url);
90
+ return local !== void 0 && removed.has(path.posix.normalize(path.posix.join(path.posix.dirname(fileName), local)));
91
+ };
92
+ for (const asset of compilation.getAssets()) {
93
+ const js = /\.(?:m|c)?js$/.test(asset.name);
94
+ if (!js && !asset.name.endsWith(".css")) continue;
95
+ const code = asset.source.source().toString();
96
+ let next = code;
97
+ if (js) {
98
+ const ref = findSourceMappingUrl(code);
99
+ if (ref && pointsAtRemoved(asset.name, ref.url)) next = stripSourceMappingUrl(code, ref);
100
+ } else {
101
+ next = stripCssSourceMappingUrl(code, (url) => pointsAtRemoved(asset.name, url));
102
+ }
103
+ if (next !== code) compilation.updateAsset(asset.name, new sources.RawSource(next));
104
+ }
105
+ return removed.size;
106
+ };
107
+ compiler.hooks.emit.tapPromise(PLUGIN_NAME, async (compilation) => {
108
+ let failure;
109
+ try {
110
+ if (compilation.errors.length > 0) {
111
+ logger.warn("the compilation has errors; source maps are not uploaded");
112
+ } else {
113
+ const entries = [];
114
+ for (const asset of compilation.getAssets()) {
115
+ const chunkId = asset.info[INFO_KEY];
116
+ if (typeof chunkId !== "string") continue;
117
+ const mapName = relatedSourceMaps(asset.info)[0] ?? `${asset.name}.map`;
118
+ if (!compilation.getAsset(mapName)) continue;
119
+ entries.push({
120
+ chunkId,
121
+ fileName: asset.name,
122
+ // Read from the compilation when it is sent, not held here.
123
+ load: async () => {
124
+ const source = compilation.getAsset(mapName)?.source.source();
125
+ if (source === void 0) throw new Error(`${mapName} is no longer in the compilation`);
126
+ return typeof source === "string" ? source : Buffer.from(source);
127
+ }
128
+ });
129
+ }
130
+ const outcome = await runUpload(entries, {
131
+ apiKey: connection.apiKey,
132
+ host: connection.host,
133
+ release: releaseFor(compilation),
134
+ dryRun: options.dryRun,
135
+ uploadTimeoutMs: options.uploadTimeoutMs,
136
+ logger
137
+ });
138
+ if (!outcome.ok) failure = outcome.error ?? "source map upload failed";
139
+ }
140
+ } catch (error) {
141
+ failure = errorMessage(error);
142
+ logger.error(`source maps: ${failure}`);
143
+ } finally {
144
+ if (shouldDeleteSourcemaps(owner, options)) {
145
+ try {
146
+ const removed = removeMapAssets(compilation);
147
+ if (removed > 0) {
148
+ logger.info(
149
+ owner === "starko" ? `removed ${removed} source map(s) from the output (switched on for the upload only)` : `removed ${removed} source map(s) from the output`
150
+ );
151
+ }
152
+ } catch (error) {
153
+ logger.error(`could not remove the source maps from the output: ${errorMessage(error)}`);
154
+ }
155
+ }
156
+ }
157
+ if (failure && options.failOnError) compilation.errors.push(new WebpackError(`[starko] ${failure}`));
158
+ });
159
+ }
160
+ };
161
+ function findSourceMapPlugin(compiler) {
162
+ try {
163
+ const { SourceMapDevToolPlugin, EvalSourceMapDevToolPlugin } = compiler.webpack;
164
+ let found;
165
+ for (const p of compiler.options.plugins || []) {
166
+ if (!p || typeof p !== "object") continue;
167
+ const name = p.constructor?.name;
168
+ if (EvalSourceMapDevToolPlugin && p instanceof EvalSourceMapDevToolPlugin || name === "EvalSourceMapDevToolPlugin") return "eval";
169
+ if (SourceMapDevToolPlugin && p instanceof SourceMapDevToolPlugin || name === "SourceMapDevToolPlugin") found = "maps";
170
+ }
171
+ return found;
172
+ } catch {
173
+ return void 0;
174
+ }
175
+ }
176
+ var webpack_default = StarkoWebpackPlugin;
177
+
178
+ export { StarkoWebpackPlugin, webpack_default };