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