@getexception/browser 0.1.5 → 0.1.7

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/README.md CHANGED
@@ -55,16 +55,28 @@ await GetException.flush(1500);
55
55
 
56
56
  `captureException` and `captureMessage` return an event ID, or an empty string when inactive. An event ID does not confirm delivery. `captureMessage` supports only `error` and `fatal`. `flush` waits for local work to finish; it does not guarantee acceptance or processing by the server. `close` shuts down the client. Both return `Promise<boolean>` and cap waiting at two seconds.
57
57
 
58
- Tags are limited to `feature`, `component` and `operation`. Context is limited to `app.route`, with query strings and fragments removed. Manual breadcrumbs support `navigation`, `http` and `manual` with allowed fields only. See the [compatibility guide](https://github.com/GetException/GetException/blob/stable/docs/sdk-compatibility.md) before replacing Sentry imports through npm aliases.
58
+ Tags are limited to `feature`, `component` and `operation`. Context supports `app.route` (query strings and fragments removed) and bounded `api.code`, `api.reason`, `api.status_code`. Manual breadcrumbs support `navigation`, `http` and `manual` with allowed fields only. See the [compatibility guide](https://github.com/GetException/GetException/blob/stable/docs/sdk-compatibility.md) before replacing Sentry imports through npm aliases.
59
59
 
60
60
  ## Privacy and scope
61
61
 
62
62
  The client uses a restricted Sentry integration and cleans event data before sending. The server independently validates and cleans it again. Requests omit cookies and referrers. Network failures do not throw into your application; the client limits pending requests and backs off after HTTP 429.
63
63
 
64
- No replay, tracing, user identity, automatic console/DOM breadcrumbs, cookies, form data, local storage, attachments or arbitrary context are collected. Avoid putting credentials or personal data in error messages. Source map upload and symbolication are not yet implemented.
64
+ No replay, tracing, user identity, automatic console/DOM breadcrumbs, cookies, form data, local storage, attachments or arbitrary context are collected. Avoid putting credentials or personal data in error messages. Browser family and major version are collected automatically; the full User-Agent is never sent in the payload. Private source map upload is available through `@getexception/cli`; match the SDK release to the exact build SHA.
65
65
 
66
66
  This package targets modern browsers, is ESM and includes TypeScript declarations. It is not a Node.js SDK.
67
67
 
68
68
  ## License
69
69
 
70
70
  MIT. See `THIRD-PARTY-NOTICES.md` for the underlying Sentry SDK and bundled dependencies.
71
+
72
+ ## API diagnostics
73
+
74
+ ```ts
75
+ GetException.captureException(error, {
76
+ contexts: {
77
+ api: { code: "error.request", reason: "timeout", status_code: 504 },
78
+ },
79
+ });
80
+ ```
81
+
82
+ Only documented technical codes are allowed (64 ASCII letters/digits/`_.-`, starting with a letter, or 1–6 digits). Reasons: `network_error`, `timeout`, `aborted`, `unauthorized`, `forbidden`, `not_found`, `validation_error`, `conflict`, `rate_limited`, `server_error`. HTTP status is an integer from 100 to 599. Unknown fields/reasons are dropped; do not pass arbitrary response text. These fields also work with `scope.setContext("api", ...)`.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,13 @@
1
+ import { ApiContext } from '@getexception/protocol';
2
+ export { ApiContext, BrowserContext } from '@getexception/protocol';
3
+
1
4
  type SeverityLevel = "error" | "fatal";
5
+
6
+ interface CaptureContext {
7
+ contexts?: {
8
+ api?: ApiContext;
9
+ };
10
+ }
2
11
  interface BrowserOptions {
3
12
  dsn: string;
4
13
  release?: string;
@@ -20,7 +29,7 @@ interface Scope {
20
29
  declare function dsnEndpoint(dsn: string): string;
21
30
  /** Unsupported options are ignored; only this allow-list is ever passed to Sentry. */
22
31
  declare function init(options?: BrowserOptions): void;
23
- declare function captureException(exception: unknown): string;
32
+ declare function captureException(exception: unknown, context?: CaptureContext): string;
24
33
  /** Unsupported levels explicitly produce no event and return an empty ID. */
25
34
  declare function captureMessage(message: string, level?: SeverityLevel): string;
26
35
  declare function setTag(key: string, value: string | number | boolean): void;
@@ -31,4 +40,4 @@ declare function withScope<T>(callback: (scope: Scope) => T): T;
31
40
  declare function flush(timeout?: number): Promise<boolean>;
32
41
  declare function close(timeout?: number): Promise<boolean>;
33
42
 
34
- export { type Breadcrumb, type BrowserOptions, type Scope, type SeverityLevel, addBreadcrumb, captureException, captureMessage, close, dsnEndpoint, flush, init, setContext, setTag, setTags, withScope };
43
+ export { type Breadcrumb, type BrowserOptions, type CaptureContext, type Scope, type SeverityLevel, addBreadcrumb, captureException, captureMessage, close, dsnEndpoint, flush, init, setContext, setTag, setTags, withScope };
package/dist/index.js CHANGED
@@ -8,7 +8,41 @@ var __export = (target, all) => {
8
8
  import * as Sentry from "@getexception/sentry-browser";
9
9
 
10
10
  // packages/browser/package.json
11
- var version = "0.1.5";
11
+ var version = "0.1.7";
12
+
13
+ // packages/browser/src/browser-context.ts
14
+ function browserContext(userAgent) {
15
+ const text = userAgent.slice(0, 1024);
16
+ const patterns = [
17
+ ["Edge", /(?:Edg|EdgiOS|EdgA)\/(\d+)/],
18
+ ["Opera", /(?:OPR|OPiOS)\/(\d+)/],
19
+ ["Samsung Internet", /SamsungBrowser\/(\d+)/],
20
+ ["Firefox", /(?:Firefox|FxiOS)\/(\d+)/],
21
+ ["Chrome", /(?:Chrome|CriOS)\/(\d+)/],
22
+ ["Safari", /Version\/(\d+).*Safari\//]
23
+ ];
24
+ for (const [name, pattern] of patterns) {
25
+ const match = pattern.exec(text);
26
+ const major = Number(match?.[1]);
27
+ if (match && major >= 1 && major <= 9999) {
28
+ return { name, major };
29
+ }
30
+ }
31
+ return void 0;
32
+ }
33
+
34
+ // packages/browser/src/debug-ids.ts
35
+ function scriptDebugId(filename) {
36
+ if (!filename) {
37
+ return void 0;
38
+ }
39
+ const registry2 = Object.getOwnPropertyDescriptor(
40
+ globalThis,
41
+ "__GETEXCEPTION_DEBUG_IDS__"
42
+ )?.value;
43
+ const value = registry2 && typeof registry2 === "object" ? Object.getOwnPropertyDescriptor(registry2, filename)?.value : void 0;
44
+ return typeof value === "string" && /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(value) ? value : void 0;
45
+ }
12
46
 
13
47
  // node_modules/zod/v4/classic/external.js
14
48
  var external_exports = {};
@@ -18889,6 +18923,114 @@ function record2(value) {
18889
18923
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : /* @__PURE__ */ Object.create(null);
18890
18924
  }
18891
18925
 
18926
+ // packages/protocol/src/diagnostics.ts
18927
+ var API_REASONS = [
18928
+ "network_error",
18929
+ "timeout",
18930
+ "aborted",
18931
+ "unauthorized",
18932
+ "forbidden",
18933
+ "not_found",
18934
+ "validation_error",
18935
+ "conflict",
18936
+ "rate_limited",
18937
+ "server_error"
18938
+ ];
18939
+ var apiContextSchema = external_exports.object({
18940
+ code: external_exports.string().regex(/^(?:[a-zA-Z][a-zA-Z0-9_.-]{0,63}|[0-9]{1,6})$/).optional(),
18941
+ reason: external_exports.enum(API_REASONS).optional(),
18942
+ status_code: external_exports.number().int().min(100).max(599).optional()
18943
+ }).strict();
18944
+ var BROWSER_NAMES = [
18945
+ "Chrome",
18946
+ "Edge",
18947
+ "Firefox",
18948
+ "Safari",
18949
+ "Opera",
18950
+ "Samsung Internet"
18951
+ ];
18952
+ var browserContextSchema = external_exports.object({
18953
+ name: external_exports.enum(BROWSER_NAMES),
18954
+ major: external_exports.number().int().min(1).max(9999)
18955
+ }).strict();
18956
+ function sanitizeApiContext(value) {
18957
+ const input2 = record2(value);
18958
+ const out = {};
18959
+ for (const key of ["code", "reason", "status_code"]) {
18960
+ const parsed = apiContextSchema.shape[key].safeParse(input2[key]);
18961
+ if (parsed.success && parsed.data !== void 0) {
18962
+ Object.defineProperty(out, key, { value: parsed.data, enumerable: true });
18963
+ }
18964
+ }
18965
+ return Object.keys(out).length ? out : void 0;
18966
+ }
18967
+ function sanitizeBrowserContext(value) {
18968
+ const input2 = record2(value);
18969
+ const parsed = browserContextSchema.safeParse({
18970
+ name: input2.name,
18971
+ major: input2.major
18972
+ });
18973
+ return parsed.success ? parsed.data : void 0;
18974
+ }
18975
+
18976
+ // packages/protocol/src/source-maps.ts
18977
+ var SOURCE_MAP_LIMITS = {
18978
+ files: 128,
18979
+ fileBytes: 16 * 1024 * 1024,
18980
+ releaseBytes: 128 * 1024 * 1024,
18981
+ projectBytes: 1024 * 1024 * 1024,
18982
+ installationBytes: 10 * 1024 * 1024 * 1024,
18983
+ manifestBytes: 64 * 1024
18984
+ };
18985
+ var releaseNameSchema = external_exports.string().regex(/^[a-z0-9][a-z0-9-]{0,79}@[a-f0-9]{40}$/);
18986
+ var artifactPathSchema = external_exports.string().max(512).regex(/^[a-zA-Z0-9_@~.-]+(?:\/[a-zA-Z0-9_@~.-]+)*\.(?:js|mjs)$/).refine(
18987
+ (value) => !value.split("/").some((part) => part === "." || part === "..")
18988
+ );
18989
+ var sourceArtifactSchema = external_exports.object({
18990
+ path: artifactPathSchema,
18991
+ debugId: external_exports.string().uuid(),
18992
+ sha256: external_exports.string().regex(/^[a-f0-9]{64}$/),
18993
+ size: external_exports.number().int().min(2).max(SOURCE_MAP_LIMITS.fileBytes)
18994
+ }).strict();
18995
+ var sourceUploadSchema = external_exports.object({
18996
+ release: releaseNameSchema,
18997
+ artifacts: external_exports.array(sourceArtifactSchema).min(1).max(SOURCE_MAP_LIMITS.files)
18998
+ }).strict().superRefine((value, ctx) => {
18999
+ if (value.artifacts.reduce((sum, file2) => sum + file2.size, 0) > SOURCE_MAP_LIMITS.releaseBytes || new Set(value.artifacts.map((file2) => file2.path)).size !== value.artifacts.length || new Set(value.artifacts.map((file2) => file2.debugId)).size !== value.artifacts.length) {
19000
+ ctx.addIssue({ code: "custom", message: "Invalid artifact manifest" });
19001
+ }
19002
+ });
19003
+ var originalFrameSchema = external_exports.object({
19004
+ filename: external_exports.string().max(512),
19005
+ function: external_exports.string().max(160),
19006
+ lineno: external_exports.number().int().min(1),
19007
+ colno: external_exports.number().int().min(0),
19008
+ contextLine: external_exports.string().max(2e3).optional(),
19009
+ preContext: external_exports.array(external_exports.string().max(2e3)).max(3),
19010
+ postContext: external_exports.array(external_exports.string().max(2e3)).max(3)
19011
+ }).strict();
19012
+
19013
+ // packages/protocol/src/releases.ts
19014
+ var RELEASE_ENVIRONMENTS = [
19015
+ "production",
19016
+ "staging",
19017
+ "development"
19018
+ ];
19019
+ var deploymentSchema = external_exports.object({
19020
+ environment: external_exports.enum(RELEASE_ENVIRONMENTS),
19021
+ review: external_exports.object({
19022
+ provider: external_exports.literal("gitlab"),
19023
+ repositoryId: external_exports.number().int().min(1).max(2147483647),
19024
+ number: external_exports.number().int().min(1).max(2147483647)
19025
+ }).strict().optional()
19026
+ }).strict().refine((value) => !value.review || value.environment === "staging", {
19027
+ message: "Merge requests belong to staging"
19028
+ });
19029
+ var releaseRegistrationSchema = external_exports.object({
19030
+ release: releaseNameSchema,
19031
+ deployment: deploymentSchema
19032
+ }).strict();
19033
+
18892
19034
  // packages/protocol/src/index.ts
18893
19035
  var safeFrameSchema = external_exports.object({
18894
19036
  filename: external_exports.string().max(512),
@@ -18920,6 +19062,8 @@ var safeEventSchema = external_exports.object({
18920
19062
  release: external_exports.string().max(160).optional(),
18921
19063
  dist: external_exports.string().max(64).optional(),
18922
19064
  route: external_exports.string().max(512).optional(),
19065
+ api: apiContextSchema.optional(),
19066
+ browser: browserContextSchema.optional(),
18923
19067
  frames: external_exports.array(safeFrameSchema).max(100),
18924
19068
  tags: external_exports.record(external_exports.string().max(32), external_exports.string().max(120)),
18925
19069
  breadcrumbs: external_exports.array(safeBreadcrumbSchema).max(50)
@@ -19060,6 +19204,14 @@ function sanitizeEvent(value, eventId, now = Date.now() / 1e3, allowedTags = DEF
19060
19204
  if (route) {
19061
19205
  out.route = route;
19062
19206
  }
19207
+ const api = sanitizeApiContext(record2(input2.contexts).api);
19208
+ const browser = sanitizeBrowserContext(record2(input2.contexts).browser);
19209
+ if (api) {
19210
+ out.api = api;
19211
+ }
19212
+ if (browser) {
19213
+ out.browser = browser;
19214
+ }
19063
19215
  return safeEventSchema.parse(out);
19064
19216
  }
19065
19217
  function toSentryEvent(event, sdkVersion = "0.1.0") {
@@ -19084,7 +19236,11 @@ function toSentryEvent(event, sdkVersion = "0.1.0") {
19084
19236
  },
19085
19237
  tags: event.tags,
19086
19238
  breadcrumbs: event.breadcrumbs,
19087
- contexts: event.route ? { app: { route: event.route } } : {}
19239
+ contexts: {
19240
+ ...event.route ? { app: { route: event.route } } : {},
19241
+ ...event.api ? { api: event.api } : {},
19242
+ ...event.browser ? { browser: event.browser } : {}
19243
+ }
19088
19244
  };
19089
19245
  }
19090
19246
  function encodeEnvelope(event, sdkVersion) {
@@ -19113,6 +19269,7 @@ function init2(options) {
19113
19269
  return;
19114
19270
  }
19115
19271
  const endpoint = dsnEndpoint(options.dsn);
19272
+ const browser = typeof navigator === "undefined" ? void 0 : browserContext(navigator.userAgent);
19116
19273
  const internalDsn = new URL(options.dsn);
19117
19274
  internalDsn.pathname = "/1";
19118
19275
  Sentry.init({
@@ -19130,9 +19287,26 @@ function init2(options) {
19130
19287
  beforeBreadcrumb: (breadcrumb) => sanitizeBreadcrumb(breadcrumb) ?? null,
19131
19288
  beforeSend: (event) => {
19132
19289
  try {
19290
+ for (const exception of event.exception?.values ?? []) {
19291
+ for (const frame of exception.stacktrace?.frames ?? []) {
19292
+ const debugId = scriptDebugId(frame.filename);
19293
+ if (debugId) {
19294
+ frame.debug_id = debugId;
19295
+ }
19296
+ }
19297
+ }
19133
19298
  return {
19134
19299
  ...toSentryEvent(
19135
- sanitizeEvent(event, event.event_id ?? ""),
19300
+ sanitizeEvent(
19301
+ {
19302
+ ...event,
19303
+ contexts: {
19304
+ ...event.contexts,
19305
+ ...browser ? { browser } : {}
19306
+ }
19307
+ },
19308
+ event.event_id ?? ""
19309
+ ),
19136
19310
  version
19137
19311
  ),
19138
19312
  type: void 0
@@ -19208,8 +19382,11 @@ function guarded(fn, fallback) {
19208
19382
  return fallback;
19209
19383
  }
19210
19384
  }
19211
- function captureException2(exception) {
19212
- return guarded(() => Sentry.captureException(exception), "");
19385
+ function captureException2(exception, context) {
19386
+ return guarded(() => {
19387
+ const api = sanitizeApiContext(context?.contexts?.api);
19388
+ return api ? Sentry.captureException(exception, { contexts: { api } }) : Sentry.captureException(exception);
19389
+ }, "");
19213
19390
  }
19214
19391
  function captureMessage2(message, level = "error") {
19215
19392
  return ["error", "fatal"].includes(level) ? guarded(() => Sentry.captureMessage(message, level), "") : "";
@@ -19221,10 +19398,14 @@ function setTags2(tags) {
19221
19398
  guarded(() => Sentry.setTags(sanitizeTags(tags)), void 0);
19222
19399
  }
19223
19400
  function setContext2(name, context) {
19224
- if (name !== "app") {
19401
+ if (name !== "app" && name !== "api") {
19225
19402
  return;
19226
19403
  }
19227
19404
  guarded(() => {
19405
+ if (name === "api") {
19406
+ Sentry.setContext("api", sanitizeApiContext(context) ?? null);
19407
+ return;
19408
+ }
19228
19409
  const route = safePath(context?.route);
19229
19410
  Sentry.setContext("app", route ? { route } : null);
19230
19411
  }, void 0);
@@ -19238,11 +19419,34 @@ function addBreadcrumb2(breadcrumb) {
19238
19419
  }, void 0);
19239
19420
  }
19240
19421
  function withScope2(callback) {
19241
- const invoke = () => callback({ setTag, setTags: setTags2, setContext: setContext2, addBreadcrumb: addBreadcrumb2 });
19242
19422
  if (!active) {
19243
- return invoke();
19423
+ return callback({ setTag, setTags: setTags2, setContext: setContext2, addBreadcrumb: addBreadcrumb2 });
19244
19424
  }
19245
- return Sentry.withScope(invoke);
19425
+ return Sentry.withScope(
19426
+ (scope) => callback({
19427
+ setTag: (key, value) => {
19428
+ scope.setTags(sanitizeTags({ [key]: value }));
19429
+ },
19430
+ setTags: (tags) => {
19431
+ scope.setTags(sanitizeTags(tags));
19432
+ },
19433
+ setContext: (name, context) => {
19434
+ if (name === "api") {
19435
+ scope.setContext(name, sanitizeApiContext(context) ?? null);
19436
+ }
19437
+ if (name === "app") {
19438
+ const route = safePath(context?.route);
19439
+ scope.setContext(name, route ? { route } : null);
19440
+ }
19441
+ },
19442
+ addBreadcrumb: (breadcrumb) => {
19443
+ const safe = sanitizeBreadcrumb(breadcrumb);
19444
+ if (safe) {
19445
+ scope.addBreadcrumb(safe);
19446
+ }
19447
+ }
19448
+ })
19449
+ );
19246
19450
  }
19247
19451
  async function waitPending(timeout) {
19248
19452
  let timer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getexception/browser",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Browser error monitoring for self-hosted GetException installations",
5
5
  "type": "module",
6
6
  "license": "MIT",