@getexception/browser 0.1.6 → 0.1.8

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.6";
11
+ var version = "0.1.8";
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,121 @@ 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
+
19034
+ // packages/protocol/src/ci.ts
19035
+ var buildContextSchema = external_exports.object({
19036
+ release: releaseNameSchema,
19037
+ assetPrefix: external_exports.string().regex(/^assets\/ge-gl-[1-9][0-9]*-[1-9][0-9]*\/$/),
19038
+ deployment: deploymentSchema
19039
+ }).strict();
19040
+
18892
19041
  // packages/protocol/src/index.ts
18893
19042
  var safeFrameSchema = external_exports.object({
18894
19043
  filename: external_exports.string().max(512),
@@ -18920,6 +19069,8 @@ var safeEventSchema = external_exports.object({
18920
19069
  release: external_exports.string().max(160).optional(),
18921
19070
  dist: external_exports.string().max(64).optional(),
18922
19071
  route: external_exports.string().max(512).optional(),
19072
+ api: apiContextSchema.optional(),
19073
+ browser: browserContextSchema.optional(),
18923
19074
  frames: external_exports.array(safeFrameSchema).max(100),
18924
19075
  tags: external_exports.record(external_exports.string().max(32), external_exports.string().max(120)),
18925
19076
  breadcrumbs: external_exports.array(safeBreadcrumbSchema).max(50)
@@ -19060,6 +19211,14 @@ function sanitizeEvent(value, eventId, now = Date.now() / 1e3, allowedTags = DEF
19060
19211
  if (route) {
19061
19212
  out.route = route;
19062
19213
  }
19214
+ const api = sanitizeApiContext(record2(input2.contexts).api);
19215
+ const browser = sanitizeBrowserContext(record2(input2.contexts).browser);
19216
+ if (api) {
19217
+ out.api = api;
19218
+ }
19219
+ if (browser) {
19220
+ out.browser = browser;
19221
+ }
19063
19222
  return safeEventSchema.parse(out);
19064
19223
  }
19065
19224
  function toSentryEvent(event, sdkVersion = "0.1.0") {
@@ -19084,7 +19243,11 @@ function toSentryEvent(event, sdkVersion = "0.1.0") {
19084
19243
  },
19085
19244
  tags: event.tags,
19086
19245
  breadcrumbs: event.breadcrumbs,
19087
- contexts: event.route ? { app: { route: event.route } } : {}
19246
+ contexts: {
19247
+ ...event.route ? { app: { route: event.route } } : {},
19248
+ ...event.api ? { api: event.api } : {},
19249
+ ...event.browser ? { browser: event.browser } : {}
19250
+ }
19088
19251
  };
19089
19252
  }
19090
19253
  function encodeEnvelope(event, sdkVersion) {
@@ -19113,6 +19276,7 @@ function init2(options) {
19113
19276
  return;
19114
19277
  }
19115
19278
  const endpoint = dsnEndpoint(options.dsn);
19279
+ const browser = typeof navigator === "undefined" ? void 0 : browserContext(navigator.userAgent);
19116
19280
  const internalDsn = new URL(options.dsn);
19117
19281
  internalDsn.pathname = "/1";
19118
19282
  Sentry.init({
@@ -19130,9 +19294,26 @@ function init2(options) {
19130
19294
  beforeBreadcrumb: (breadcrumb) => sanitizeBreadcrumb(breadcrumb) ?? null,
19131
19295
  beforeSend: (event) => {
19132
19296
  try {
19297
+ for (const exception of event.exception?.values ?? []) {
19298
+ for (const frame of exception.stacktrace?.frames ?? []) {
19299
+ const debugId = scriptDebugId(frame.filename);
19300
+ if (debugId) {
19301
+ frame.debug_id = debugId;
19302
+ }
19303
+ }
19304
+ }
19133
19305
  return {
19134
19306
  ...toSentryEvent(
19135
- sanitizeEvent(event, event.event_id ?? ""),
19307
+ sanitizeEvent(
19308
+ {
19309
+ ...event,
19310
+ contexts: {
19311
+ ...event.contexts,
19312
+ ...browser ? { browser } : {}
19313
+ }
19314
+ },
19315
+ event.event_id ?? ""
19316
+ ),
19136
19317
  version
19137
19318
  ),
19138
19319
  type: void 0
@@ -19208,8 +19389,11 @@ function guarded(fn, fallback) {
19208
19389
  return fallback;
19209
19390
  }
19210
19391
  }
19211
- function captureException2(exception) {
19212
- return guarded(() => Sentry.captureException(exception), "");
19392
+ function captureException2(exception, context) {
19393
+ return guarded(() => {
19394
+ const api = sanitizeApiContext(context?.contexts?.api);
19395
+ return api ? Sentry.captureException(exception, { contexts: { api } }) : Sentry.captureException(exception);
19396
+ }, "");
19213
19397
  }
19214
19398
  function captureMessage2(message, level = "error") {
19215
19399
  return ["error", "fatal"].includes(level) ? guarded(() => Sentry.captureMessage(message, level), "") : "";
@@ -19221,10 +19405,14 @@ function setTags2(tags) {
19221
19405
  guarded(() => Sentry.setTags(sanitizeTags(tags)), void 0);
19222
19406
  }
19223
19407
  function setContext2(name, context) {
19224
- if (name !== "app") {
19408
+ if (name !== "app" && name !== "api") {
19225
19409
  return;
19226
19410
  }
19227
19411
  guarded(() => {
19412
+ if (name === "api") {
19413
+ Sentry.setContext("api", sanitizeApiContext(context) ?? null);
19414
+ return;
19415
+ }
19228
19416
  const route = safePath(context?.route);
19229
19417
  Sentry.setContext("app", route ? { route } : null);
19230
19418
  }, void 0);
@@ -19238,11 +19426,34 @@ function addBreadcrumb2(breadcrumb) {
19238
19426
  }, void 0);
19239
19427
  }
19240
19428
  function withScope2(callback) {
19241
- const invoke = () => callback({ setTag, setTags: setTags2, setContext: setContext2, addBreadcrumb: addBreadcrumb2 });
19242
19429
  if (!active) {
19243
- return invoke();
19430
+ return callback({ setTag, setTags: setTags2, setContext: setContext2, addBreadcrumb: addBreadcrumb2 });
19244
19431
  }
19245
- return Sentry.withScope(invoke);
19432
+ return Sentry.withScope(
19433
+ (scope) => callback({
19434
+ setTag: (key, value) => {
19435
+ scope.setTags(sanitizeTags({ [key]: value }));
19436
+ },
19437
+ setTags: (tags) => {
19438
+ scope.setTags(sanitizeTags(tags));
19439
+ },
19440
+ setContext: (name, context) => {
19441
+ if (name === "api") {
19442
+ scope.setContext(name, sanitizeApiContext(context) ?? null);
19443
+ }
19444
+ if (name === "app") {
19445
+ const route = safePath(context?.route);
19446
+ scope.setContext(name, route ? { route } : null);
19447
+ }
19448
+ },
19449
+ addBreadcrumb: (breadcrumb) => {
19450
+ const safe = sanitizeBreadcrumb(breadcrumb);
19451
+ if (safe) {
19452
+ scope.addBreadcrumb(safe);
19453
+ }
19454
+ }
19455
+ })
19456
+ );
19246
19457
  }
19247
19458
  async function waitPending(timeout) {
19248
19459
  let timer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getexception/browser",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Browser error monitoring for self-hosted GetException installations",
5
5
  "type": "module",
6
6
  "license": "MIT",