@hanzo/event 0.3.18 → 0.3.20

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/dist/react.mjs CHANGED
@@ -68,17 +68,19 @@ function hasAttribution(a) {
68
68
  }
69
69
 
70
70
  // src/dsn.ts
71
- var PRODUCT_DSN = Object.freeze({
72
- // hanzo-console — console.hanzo.ai (also served embedded by the cloud binary)
73
- console: "https://1:0c8054dbde157f4f420c56b58660052b2ad782293c4de1d606ef8fbc46a0bf34@api.hanzo.ai/v1/sentry/019fa40b-94ae-7f1d-8f7b-e92f123fad42",
74
- // hanzo-app — hanzo.app
75
- app: "https://1:b3e1173125568c80f91ef4b1fabbbd2d7e22341de02b33ce7e22ef4fc16a196e@api.hanzo.ai/v1/sentry/019f9b1e-57eb-7171-9d92-72c0b85e4b4b",
76
- // hanzo-ai — hanzo.ai (the marketing site; `site` is the product name it declares)
77
- site: "https://1:d9cbfb844958bd7ef2a455600f00fbf237fbd71b75c1504f137773096d6aa53f@api.hanzo.ai/v1/sentry/019f9b1e-5785-7359-ad0b-f75db8e58c99"
71
+ var PRODUCT_PROJECT = Object.freeze({
72
+ console: "019fa40b-94ae-7f1d-8f7b-e92f123fad42",
73
+ // console.hanzo.ai
74
+ app: "019f9b1e-57eb-7171-9d92-72c0b85e4b4b",
75
+ // hanzo.app
76
+ site: "019f9b1e-5785-7359-ad0b-f75db8e58c99"
77
+ // hanzo.ai (marketing; product `site`)
78
78
  });
79
79
  function dsnForProduct(product) {
80
80
  if (!product) return void 0;
81
- return PRODUCT_DSN[product];
81
+ const projectId = PRODUCT_PROJECT[product];
82
+ if (!projectId) return void 0;
83
+ return `https://${HANZO_PUBLISHABLE_KEY}@api.hanzo.ai/v1/sentry/${projectId}`;
82
84
  }
83
85
  var HANZO_PUBLISHABLE_KEY = "pk-live-c88649f1085fb6ad441d8a0072933a9b";
84
86
  function defaultPublishableKey(host) {
@@ -87,6 +89,7 @@ function defaultPublishableKey(host) {
87
89
 
88
90
  // src/events.ts
89
91
  var PAGEVIEW = "$pageview";
92
+ var EXCEPTION = "$exception";
90
93
 
91
94
  // src/scrub.ts
92
95
  var REDACTED = "[redacted]";
@@ -311,7 +314,7 @@ function hzAnonId() {
311
314
  }
312
315
 
313
316
  // src/version.ts
314
- var VERSION = "0.3.18";
317
+ var VERSION = "0.3.20";
315
318
 
316
319
  // src/sentry.ts
317
320
  var MAX_FRAMES = 50;
@@ -503,6 +506,94 @@ ${itemHeader}
503
506
  ${payload}
504
507
  `;
505
508
  }
509
+ var MAX_VALUE = 4096;
510
+ function digest(s) {
511
+ let out = "";
512
+ for (const seed of [2166136261, 16777619, 2654435769, 2246822507]) {
513
+ let h = seed >>> 0;
514
+ for (let i = 0; i < s.length; i++) {
515
+ h ^= s.charCodeAt(i);
516
+ h = h + (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24) >>> 0;
517
+ }
518
+ out += h.toString(16).padStart(8, "0");
519
+ }
520
+ return out;
521
+ }
522
+ function frameOf(f) {
523
+ const source = f.filename ?? "";
524
+ const name = f.function ?? "<anonymous>";
525
+ const line = f.lineno ?? 0;
526
+ const column = f.colno ?? 0;
527
+ return {
528
+ // Stable per code location, so the same frame groups and re-renders under one
529
+ // key. The '/part' suffix is the product's format for one raw frame expanding
530
+ // into several resolved ones; a browser frame is always part 0.
531
+ raw_id: `${digest(`${source}|${name}|${line}|${column}`)}/0`,
532
+ mangled_name: name,
533
+ source,
534
+ line,
535
+ column,
536
+ in_app: f.in_app ?? false,
537
+ lang: "javascript",
538
+ resolved: false,
539
+ resolve_failure: "no symbol set uploaded for this release",
540
+ resolved_name: null,
541
+ module: null
542
+ };
543
+ }
544
+ function truncate2(s, max) {
545
+ if (s.length <= max) return s;
546
+ let end = max;
547
+ const c = s.charCodeAt(end - 1);
548
+ if (c >= 55296 && c <= 56319) end--;
549
+ return s.slice(0, end);
550
+ }
551
+ function exceptionEntry(err, opts) {
552
+ const n = normalizeError(err);
553
+ const frames = framesFromStack(n.stack).slice(-50);
554
+ const entry = {
555
+ id: opts.id,
556
+ type: n.name,
557
+ value: truncate2(n.message, MAX_VALUE),
558
+ mechanism: {
559
+ type: "generic",
560
+ handled: opts.handled,
561
+ // An exception the app reported by hand was constructed, not thrown by the
562
+ // runtime at a real call site.
563
+ synthetic: !(err instanceof Error)
564
+ }
565
+ };
566
+ if (frames.length > 0) {
567
+ entry.stacktrace = { type: "resolved", frames: frames.map(frameOf) };
568
+ }
569
+ return entry;
570
+ }
571
+ function fingerprint(entry) {
572
+ const frames = entry.stacktrace?.frames ?? [];
573
+ const pieces = frames.filter((f) => f.in_app).map((f) => `${f.mangled_name}@${f.source}`);
574
+ return digest([entry.type, ...pieces].join("\n"));
575
+ }
576
+ function exceptionProperties(err, opts) {
577
+ const entry = exceptionEntry(err, opts);
578
+ const frames = entry.stacktrace?.frames ?? [];
579
+ const fp = fingerprint(entry);
580
+ return {
581
+ $exception_list: [entry],
582
+ $exception_fingerprint: fp,
583
+ // Records WHY this fingerprint holds. 'manual' is the honest value: the client
584
+ // supplied the key rather than a server grouper deriving one.
585
+ $exception_fingerprint_record: [{ type: "manual" }],
586
+ $exception_type: entry.type,
587
+ $exception_message: entry.value,
588
+ $exception_level: opts.level ?? "error",
589
+ $exception_handled: opts.handled,
590
+ $exception_synthetic: entry.mechanism?.synthetic ?? false,
591
+ $exception_types: [entry.type],
592
+ $exception_values: [entry.value],
593
+ $exception_sources: frames.map((f) => f.source).filter((s) => !!s),
594
+ $exception_functions: frames.map((f) => f.resolved_name ?? f.mangled_name).filter((s) => !!s)
595
+ };
596
+ }
506
597
 
507
598
  // src/storage.ts
508
599
  var KEY = {
@@ -779,9 +870,20 @@ var Analytics = class {
779
870
  } catch {
780
871
  }
781
872
  try {
873
+ const handled = context?.handled ?? true;
782
874
  const ex = normalizeError2(err);
783
- ex.handled = context?.handled ?? true;
784
- this.enqueue("error", ex.message, { error: ex, properties: context?.properties });
875
+ ex.handled = handled;
876
+ this.enqueue("event", EXCEPTION, {
877
+ error: ex,
878
+ properties: {
879
+ ...context?.properties,
880
+ ...exceptionProperties(err, {
881
+ handled,
882
+ id: hzUuidv7(),
883
+ level: context?.level
884
+ })
885
+ }
886
+ });
785
887
  this.flush();
786
888
  } catch {
787
889
  }