@domandigital/sentry 0.0.0-stage → 0.1.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.
@@ -0,0 +1,352 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/cloudflare.ts
21
+ var cloudflare_exports = {};
22
+ __export(cloudflare_exports, {
23
+ SERVER_TRACES_SAMPLE_RATE: () => SERVER_TRACES_SAMPLE_RATE,
24
+ cloudflareOptions: () => cloudflareOptions
25
+ });
26
+ module.exports = __toCommonJS(cloudflare_exports);
27
+
28
+ // src/env.ts
29
+ var INGEST_HOST = "o4510784554991616.ingest.de.sentry.io";
30
+ var ENVIRONMENT_VARS = [
31
+ "SENTRY_ENVIRONMENT",
32
+ "PUBLIC_SENTRY_ENVIRONMENT",
33
+ "NEXT_PUBLIC_SENTRY_ENVIRONMENT",
34
+ // Vercel sets these itself, so a Vercel project is right without any setup.
35
+ "VERCEL_ENV",
36
+ "NEXT_PUBLIC_VERCEL_ENV"
37
+ ];
38
+ var RELEASE_VARS = [
39
+ "SENTRY_RELEASE",
40
+ "PUBLIC_SENTRY_RELEASE",
41
+ "NEXT_PUBLIC_SENTRY_RELEASE",
42
+ "CF_PAGES_COMMIT_SHA",
43
+ "WORKERS_CI_COMMIT_SHA",
44
+ "VERCEL_GIT_COMMIT_SHA",
45
+ "NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA",
46
+ "GITHUB_SHA"
47
+ ];
48
+ var DSN_VARS = ["SENTRY_DSN", "PUBLIC_SENTRY_DSN", "NEXT_PUBLIC_SENTRY_DSN"];
49
+ function text(value) {
50
+ if (typeof value !== "string") return void 0;
51
+ const trimmed = value.trim();
52
+ return trimmed === "" ? void 0 : trimmed;
53
+ }
54
+ function firstOf(env, names) {
55
+ if (!env) return void 0;
56
+ for (const name of names) {
57
+ const value = text(env[name]);
58
+ if (value) return { value, from: name };
59
+ }
60
+ return void 0;
61
+ }
62
+ var ALIASES = {
63
+ production: "production",
64
+ prod: "production",
65
+ live: "production",
66
+ staging: "staging",
67
+ stage: "staging",
68
+ stg: "staging",
69
+ preview: "preview"
70
+ };
71
+ var LOCAL = /* @__PURE__ */ new Set(["development", "dev", "local", "test"]);
72
+ function resolveEnvironment(input = {}) {
73
+ const explicit = text(input.environment);
74
+ const found = explicit ? { value: explicit, from: "explicit" } : firstOf(input.env, ENVIRONMENT_VARS);
75
+ if (!found) return { environment: "preview", enabled: true, from: null };
76
+ const key = found.value.toLowerCase();
77
+ if (LOCAL.has(key)) return { environment: "preview", enabled: false, from: found.from };
78
+ return { environment: ALIASES[key] ?? "preview", enabled: true, from: found.from };
79
+ }
80
+ function resolveRelease(input = {}) {
81
+ return text(input.release) ?? firstOf(input.env, RELEASE_VARS)?.value;
82
+ }
83
+ var OLD_INGEST = /^(https?:\/\/[^@/]+@)(o\d+\.ingest\.de\.sentry\.io)(\/.*)$/i;
84
+ function normaliseDsn(dsn) {
85
+ const value = text(dsn);
86
+ if (!value) return void 0;
87
+ const match = OLD_INGEST.exec(value);
88
+ return match ? `${match[1]}${INGEST_HOST}${match[3]}` : value;
89
+ }
90
+ function resolveDsn(input = {}) {
91
+ return normaliseDsn(text(input.dsn) ?? firstOf(input.env, DSN_VARS)?.value);
92
+ }
93
+
94
+ // src/filters.ts
95
+ var IGNORE_ERRORS = [
96
+ // In-app browsers and wallet extensions poking at objects they injected.
97
+ /\bethereum\b/i,
98
+ "__firefox__",
99
+ "webkit.messageHandlers",
100
+ "Java object is gone",
101
+ // Globals that tag managers, extensions and injected bars expect to exist.
102
+ /\b(?:googletag|jQuery|zaius|eventTracker) is not defined\b/,
103
+ /(?:^|[^\w$])\$ is not defined\b/,
104
+ /Can't find variable: (?:googletag|jQuery|zaius|eventTracker|\$)(?![\w$])/,
105
+ // Next.js after a deploy: an open tab posts to a server action the new build no longer has.
106
+ "Failed to find Server Action",
107
+ // The browser skipped a view transition (a second navigation, a hidden tab). Nothing broke.
108
+ "Skipping view transition",
109
+ "Transition was skipped"
110
+ ];
111
+ var DENY_URLS = [
112
+ // Errors whose top frame is in a browser extension, or Safari's mask for one.
113
+ /^(?:chrome|moz|safari|safari-web|ms-browser)-extension:\/\//i,
114
+ /^webkit-masked-url:/i,
115
+ // Third-party scripts a site embeds and cannot fix.
116
+ /googletagmanager\.com/i,
117
+ /google-analytics\.com/i,
118
+ /googlesyndication\.com/i,
119
+ /connect\.facebook\.net/i,
120
+ /static\.hotjar\.com/i,
121
+ /clarity\.ms/i
122
+ ];
123
+ var NETWORK_FAILURE = /^(?:Failed to fetch|Load failed|NetworkError when attempting to fetch resource\.)(?: \(([^)\s]+)\))?$/;
124
+ var isRec = (value) => typeof value === "object" && value !== null;
125
+ function bareHost(host) {
126
+ return host.toLowerCase().replace(/:\d+$/, "").replace(/^www\./, "");
127
+ }
128
+ function hostOf(url) {
129
+ if (typeof url !== "string") return void 0;
130
+ try {
131
+ return new URL(url).host;
132
+ } catch {
133
+ return void 0;
134
+ }
135
+ }
136
+ function sameSite(a, b) {
137
+ const x = bareHost(a);
138
+ const y = bareHost(b);
139
+ return x === y || x.endsWith(`.${y}`) || y.endsWith(`.${x}`);
140
+ }
141
+ function isThirdPartyNetworkError(event, hint, firstPartyHosts = []) {
142
+ if (!isRec(event) || !isRec(event.exception) || !Array.isArray(event.exception.values)) return false;
143
+ const values = event.exception.values.filter(isRec);
144
+ const last = values[values.length - 1];
145
+ if (!last || last.type !== "TypeError" || typeof last.value !== "string") return false;
146
+ const match = NETWORK_FAILURE.exec(last.value);
147
+ if (!match) return false;
148
+ const original = isRec(hint) && isRec(hint.originalException) ? hint.originalException : void 0;
149
+ const target = match[1] ?? (typeof original?.__sentry_fetch_url_host__ === "string" ? original.__sentry_fetch_url_host__ : void 0);
150
+ if (!target) return false;
151
+ const page = isRec(event.request) ? hostOf(event.request.url) : void 0;
152
+ const ours = [...firstPartyHosts, ...page ? [page] : []];
153
+ if (ours.length === 0) return false;
154
+ return !ours.some((host) => sameSite(host, target));
155
+ }
156
+
157
+ // src/scrub.ts
158
+ var import_synthetic = require("@domandigital/synthetic");
159
+ var REDACTED = "[REDACTED]";
160
+ var REDACT_KEYS = /email|token|cookie|authori[sz]ation|^auth$|password|passwd|secret|session|signature|api[-_]?key|phone/i;
161
+ var EMAIL = /[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}/gi;
162
+ var BEARER = /bearer\s+[a-z0-9._\-~+/]+=*/gi;
163
+ var PHONE = /(?<![\w.+])(?:\+44\s?(?:\(0\)\s?)?|0)\d(?:[\s-]?\d){8,9}(?![\w.])/g;
164
+ var MAX_DEPTH = 8;
165
+ var MAX_ITEMS = 100;
166
+ function scrubString(input) {
167
+ return input.replace(EMAIL, "[REDACTED_EMAIL]").replace(BEARER, "Bearer [REDACTED_TOKEN]").replace(PHONE, "[REDACTED_PHONE]");
168
+ }
169
+ function scrubValue(value, depth = 0) {
170
+ if (depth > MAX_DEPTH) return "[TRUNCATED_DEPTH]";
171
+ if (value == null) return value;
172
+ if (typeof value === "string") return scrubString(value);
173
+ if (typeof value === "number" || typeof value === "boolean") return value;
174
+ if (typeof value === "bigint") return value.toString();
175
+ if (value instanceof Error) return { name: value.name, message: scrubString(value.message) };
176
+ if (Array.isArray(value)) return value.slice(0, MAX_ITEMS).map((item) => scrubValue(item, depth + 1));
177
+ if (typeof value === "object") {
178
+ const out = {};
179
+ for (const [key, item] of Object.entries(value)) {
180
+ out[key] = REDACT_KEYS.test(key) ? REDACTED : scrubValue(item, depth + 1);
181
+ }
182
+ return out;
183
+ }
184
+ return String(value);
185
+ }
186
+ var isRec2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
187
+ function scrubRequest(request) {
188
+ const out = { ...request };
189
+ if ("headers" in out) out.headers = scrubValue(out.headers);
190
+ if ("cookies" in out && out.cookies) out.cookies = REDACTED;
191
+ if ("data" in out) out.data = scrubValue(out.data);
192
+ if (typeof out.query_string === "string") out.query_string = scrubString(out.query_string);
193
+ else if ("query_string" in out) out.query_string = scrubValue(out.query_string);
194
+ if (typeof out.url === "string") out.url = scrubString(out.url);
195
+ return out;
196
+ }
197
+ function scrubException(exception) {
198
+ if (!Array.isArray(exception.values)) return exception;
199
+ return {
200
+ ...exception,
201
+ // Only the message: stack frames, types and mechanisms are code, not customer data.
202
+ values: exception.values.map((v) => isRec2(v) && typeof v.value === "string" ? { ...v, value: scrubString(v.value) } : v)
203
+ };
204
+ }
205
+ function scrubBreadcrumb(crumb) {
206
+ if (!isRec2(crumb)) return crumb;
207
+ const out = { ...crumb };
208
+ if (typeof out.message === "string") out.message = scrubString(out.message);
209
+ if ("data" in out) out.data = scrubValue(out.data);
210
+ return out;
211
+ }
212
+ function scrubPii(event) {
213
+ const out = { ...event };
214
+ if (isRec2(out.request)) out.request = scrubRequest(out.request);
215
+ for (const key of ["user", "extra", "contexts", "tags"]) {
216
+ if (key in out) out[key] = scrubValue(out[key]);
217
+ }
218
+ if (typeof out.message === "string") out.message = scrubString(out.message);
219
+ if (isRec2(out.logentry) && typeof out.logentry.message === "string") {
220
+ out.logentry = { ...out.logentry, message: scrubString(out.logentry.message) };
221
+ }
222
+ if (isRec2(out.exception)) out.exception = scrubException(out.exception);
223
+ if (Array.isArray(out.breadcrumbs)) out.breadcrumbs = out.breadcrumbs.map(scrubBreadcrumb);
224
+ return out;
225
+ }
226
+ var SPAN_REDACT_KEYS = /x-dd-synth|cookie|authori[sz]ation|token|secret|password|email|phone/i;
227
+ function scrubAttributes(attributes) {
228
+ const out = {};
229
+ for (const [key, value] of Object.entries(attributes)) {
230
+ if (SPAN_REDACT_KEYS.test(key)) out[key] = REDACTED;
231
+ else if (typeof value === "string") out[key] = scrubString(value);
232
+ else if (Array.isArray(value)) out[key] = value.map((v) => typeof v === "string" ? scrubString(v) : v);
233
+ else out[key] = value;
234
+ }
235
+ return out;
236
+ }
237
+ function scrubSpan(span) {
238
+ try {
239
+ const out = { ...span };
240
+ if (typeof out.name === "string") out.name = scrubString(out.name);
241
+ if (typeof out.description === "string") out.description = scrubString(out.description);
242
+ if (isRec2(out.attributes)) out.attributes = scrubAttributes(out.attributes);
243
+ if (isRec2(out.data)) out.data = scrubAttributes(out.data);
244
+ return out;
245
+ } catch {
246
+ return span;
247
+ }
248
+ }
249
+ function scrubEvent(event) {
250
+ try {
251
+ return (0, import_synthetic.scrubSentryEvent)(scrubPii(event));
252
+ } catch {
253
+ const { request: _request, user: _user, extra: _extra, breadcrumbs: _breadcrumbs, ...rest } = event;
254
+ return rest;
255
+ }
256
+ }
257
+
258
+ // src/preset.ts
259
+ var DATA_COLLECTION = {
260
+ userInfo: false,
261
+ cookies: false,
262
+ httpHeaders: { request: true, response: false },
263
+ httpBodies: [],
264
+ urlQueryParams: true,
265
+ graphQL: { document: true, variables: false },
266
+ genAI: { inputs: false, outputs: false },
267
+ databaseQueryData: false,
268
+ queues: false,
269
+ stackFrameVariables: false
270
+ };
271
+ function isThenable(value) {
272
+ return typeof value === "object" && value !== null && typeof value.then === "function";
273
+ }
274
+ function scrubbingHook(user, drop) {
275
+ return ((event, hint) => {
276
+ if (drop?.(event, hint)) return null;
277
+ const out = user ? user(event, hint) : event;
278
+ if (isThenable(out)) return Promise.resolve(out).then((e) => e ? scrubEvent(e) : null);
279
+ return out ? scrubEvent(out) : null;
280
+ });
281
+ }
282
+ var SCRUB_TRANSACTIONS = {
283
+ name: "DomanDigitalScrubTransactions",
284
+ processEvent: (event) => event.type === "transaction" ? scrubEvent(event) : event
285
+ };
286
+ function withScrubber(integrations) {
287
+ if (typeof integrations === "function") {
288
+ return (defaults) => [...integrations(defaults), SCRUB_TRANSACTIONS];
289
+ }
290
+ return [...Array.isArray(integrations) ? integrations : [], SCRUB_TRANSACTIONS];
291
+ }
292
+ function hasReplay(integrations) {
293
+ return Array.isArray(integrations) && integrations.some((i) => typeof i === "object" && i !== null && i.name === "Replay");
294
+ }
295
+ function buildPreset(input, runtime) {
296
+ const {
297
+ dsn: dsnIn,
298
+ env,
299
+ environment: environmentIn,
300
+ release: releaseIn,
301
+ firstPartyHosts = [],
302
+ ignoreErrors = [],
303
+ denyUrls = [],
304
+ integrations,
305
+ beforeSend,
306
+ beforeSendSpan,
307
+ dataCollection,
308
+ tracesSampleRate,
309
+ replaysSessionSampleRate,
310
+ replaysOnErrorSampleRate,
311
+ sendDefaultPii: _sendDefaultPii,
312
+ ...rest
313
+ } = input;
314
+ const { environment, enabled } = resolveEnvironment({ environment: environmentIn, env });
315
+ const dsn = resolveDsn({ dsn: dsnIn, env });
316
+ const release = resolveRelease({ release: releaseIn, env });
317
+ const out = {
318
+ ...rest,
319
+ environment,
320
+ dataCollection: { ...DATA_COLLECTION, ...dataCollection },
321
+ ignoreErrors: [...IGNORE_ERRORS, ...ignoreErrors],
322
+ denyUrls: [...DENY_URLS, ...denyUrls],
323
+ integrations: withScrubber(integrations),
324
+ beforeSend: scrubbingHook(
325
+ beforeSend,
326
+ runtime.browser ? (event, hint) => isThirdPartyNetworkError(event, hint, firstPartyHosts) : void 0
327
+ ),
328
+ // A site's own hook replaces this one rather than being wrapped: v11 marks
329
+ // a static-span hook (`withStaticSpan`), and a wrapper would lose the mark.
330
+ beforeSendSpan: beforeSendSpan ?? scrubSpan,
331
+ tracesSampleRate: tracesSampleRate ?? runtime.tracesSampleRate
332
+ };
333
+ if (dsn) out.dsn = dsn;
334
+ if (release) out.release = release;
335
+ if (!enabled) out.enabled = false;
336
+ if (runtime.browser && hasReplay(integrations)) {
337
+ out.replaysSessionSampleRate = replaysSessionSampleRate ?? 0;
338
+ out.replaysOnErrorSampleRate = replaysOnErrorSampleRate ?? 1;
339
+ }
340
+ return out;
341
+ }
342
+
343
+ // src/cloudflare.ts
344
+ var SERVER_TRACES_SAMPLE_RATE = 0.1;
345
+ function cloudflareOptions(input = {}) {
346
+ return buildPreset(input, { tracesSampleRate: SERVER_TRACES_SAMPLE_RATE, browser: false });
347
+ }
348
+ // Annotate the CommonJS export names for ESM import in node:
349
+ 0 && (module.exports = {
350
+ SERVER_TRACES_SAMPLE_RATE,
351
+ cloudflareOptions
352
+ });
@@ -0,0 +1,27 @@
1
+ import { P as PresetInput, c as Preset } from './preset-D2peo0uv.cjs';
2
+ export { d as PresetDefaults, S as ScrubbingHook, b as SpanScrubbingHook } from './preset-D2peo0uv.cjs';
3
+
4
+ /**
5
+ * Cloudflare Worker init options, for `@sentry/cloudflare`'s `withSentry`
6
+ * (and Astro or any framework running on a Worker). The Worker's `env` is
7
+ * only available per request, so the options are built from it there.
8
+ */
9
+
10
+ /** Traces sampled on a server when the input does not say. */
11
+ declare const SERVER_TRACES_SAMPLE_RATE = 0.1;
12
+ /**
13
+ * `Sentry.init` options for a Worker. `env` is the Worker's bindings: the DSN
14
+ * comes from `SENTRY_DSN`, the environment from `SENTRY_ENVIRONMENT` and the
15
+ * release from `SENTRY_RELEASE` (set it at deploy: `wrangler deploy --var
16
+ * SENTRY_RELEASE:$GITHUB_SHA`).
17
+ *
18
+ * ```ts
19
+ * import * as Sentry from "@sentry/cloudflare";
20
+ * import { cloudflareOptions } from "@domandigital/sentry/cloudflare";
21
+ *
22
+ * export default Sentry.withSentry((env: Env) => cloudflareOptions({ env }), handler);
23
+ * ```
24
+ */
25
+ declare function cloudflareOptions<I extends PresetInput>(input?: I): Preset<I>;
26
+
27
+ export { Preset, PresetInput, SERVER_TRACES_SAMPLE_RATE, cloudflareOptions };
@@ -0,0 +1,27 @@
1
+ import { P as PresetInput, c as Preset } from './preset-D2peo0uv.js';
2
+ export { d as PresetDefaults, S as ScrubbingHook, b as SpanScrubbingHook } from './preset-D2peo0uv.js';
3
+
4
+ /**
5
+ * Cloudflare Worker init options, for `@sentry/cloudflare`'s `withSentry`
6
+ * (and Astro or any framework running on a Worker). The Worker's `env` is
7
+ * only available per request, so the options are built from it there.
8
+ */
9
+
10
+ /** Traces sampled on a server when the input does not say. */
11
+ declare const SERVER_TRACES_SAMPLE_RATE = 0.1;
12
+ /**
13
+ * `Sentry.init` options for a Worker. `env` is the Worker's bindings: the DSN
14
+ * comes from `SENTRY_DSN`, the environment from `SENTRY_ENVIRONMENT` and the
15
+ * release from `SENTRY_RELEASE` (set it at deploy: `wrangler deploy --var
16
+ * SENTRY_RELEASE:$GITHUB_SHA`).
17
+ *
18
+ * ```ts
19
+ * import * as Sentry from "@sentry/cloudflare";
20
+ * import { cloudflareOptions } from "@domandigital/sentry/cloudflare";
21
+ *
22
+ * export default Sentry.withSentry((env: Env) => cloudflareOptions({ env }), handler);
23
+ * ```
24
+ */
25
+ declare function cloudflareOptions<I extends PresetInput>(input?: I): Preset<I>;
26
+
27
+ export { Preset, PresetInput, SERVER_TRACES_SAMPLE_RATE, cloudflareOptions };
@@ -0,0 +1,9 @@
1
+ import {
2
+ SERVER_TRACES_SAMPLE_RATE,
3
+ cloudflareOptions
4
+ } from "./chunk-ZIWYCDHF.js";
5
+ import "./chunk-BICH2PO4.js";
6
+ export {
7
+ SERVER_TRACES_SAMPLE_RATE,
8
+ cloudflareOptions
9
+ };