@hanzo/event 0.3.19 → 0.3.21

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
@@ -76,19 +76,16 @@ var PRODUCT_PROJECT = Object.freeze({
76
76
  site: "019f9b1e-5785-7359-ad0b-f75db8e58c99"
77
77
  // hanzo.ai (marketing; product `site`)
78
78
  });
79
- function dsnForProduct(product) {
80
- if (!product) return void 0;
79
+ function dsnForProduct(product, key) {
80
+ if (!product || !key) return void 0;
81
81
  const projectId = PRODUCT_PROJECT[product];
82
82
  if (!projectId) return void 0;
83
- return `https://${HANZO_PUBLISHABLE_KEY}@api.hanzo.ai/v1/sentry/${projectId}`;
84
- }
85
- var HANZO_PUBLISHABLE_KEY = "pk-live-c88649f1085fb6ad441d8a0072933a9b";
86
- function defaultPublishableKey(host) {
87
- return host === void 0 || host === "https://api.hanzo.ai" ? HANZO_PUBLISHABLE_KEY : void 0;
83
+ return `https://${key}@api.hanzo.ai/v1/sentry/${projectId}`;
88
84
  }
89
85
 
90
86
  // src/events.ts
91
87
  var PAGEVIEW = "$pageview";
88
+ var EXCEPTION = "$exception";
92
89
 
93
90
  // src/scrub.ts
94
91
  var REDACTED = "[redacted]";
@@ -313,7 +310,7 @@ function hzAnonId() {
313
310
  }
314
311
 
315
312
  // src/version.ts
316
- var VERSION = "0.3.19";
313
+ var VERSION = "0.3.21";
317
314
 
318
315
  // src/sentry.ts
319
316
  var MAX_FRAMES = 50;
@@ -505,6 +502,94 @@ ${itemHeader}
505
502
  ${payload}
506
503
  `;
507
504
  }
505
+ var MAX_VALUE = 4096;
506
+ function digest(s) {
507
+ let out = "";
508
+ for (const seed of [2166136261, 16777619, 2654435769, 2246822507]) {
509
+ let h = seed >>> 0;
510
+ for (let i = 0; i < s.length; i++) {
511
+ h ^= s.charCodeAt(i);
512
+ h = h + (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24) >>> 0;
513
+ }
514
+ out += h.toString(16).padStart(8, "0");
515
+ }
516
+ return out;
517
+ }
518
+ function frameOf(f) {
519
+ const source = f.filename ?? "";
520
+ const name = f.function ?? "<anonymous>";
521
+ const line = f.lineno ?? 0;
522
+ const column = f.colno ?? 0;
523
+ return {
524
+ // Stable per code location, so the same frame groups and re-renders under one
525
+ // key. The '/part' suffix is the product's format for one raw frame expanding
526
+ // into several resolved ones; a browser frame is always part 0.
527
+ raw_id: `${digest(`${source}|${name}|${line}|${column}`)}/0`,
528
+ mangled_name: name,
529
+ source,
530
+ line,
531
+ column,
532
+ in_app: f.in_app ?? false,
533
+ lang: "javascript",
534
+ resolved: false,
535
+ resolve_failure: "no symbol set uploaded for this release",
536
+ resolved_name: null,
537
+ module: null
538
+ };
539
+ }
540
+ function truncate2(s, max) {
541
+ if (s.length <= max) return s;
542
+ let end = max;
543
+ const c = s.charCodeAt(end - 1);
544
+ if (c >= 55296 && c <= 56319) end--;
545
+ return s.slice(0, end);
546
+ }
547
+ function exceptionEntry(err, opts) {
548
+ const n = normalizeError(err);
549
+ const frames = framesFromStack(n.stack).slice(-50);
550
+ const entry = {
551
+ id: opts.id,
552
+ type: n.name,
553
+ value: truncate2(n.message, MAX_VALUE),
554
+ mechanism: {
555
+ type: "generic",
556
+ handled: opts.handled,
557
+ // An exception the app reported by hand was constructed, not thrown by the
558
+ // runtime at a real call site.
559
+ synthetic: !(err instanceof Error)
560
+ }
561
+ };
562
+ if (frames.length > 0) {
563
+ entry.stacktrace = { type: "resolved", frames: frames.map(frameOf) };
564
+ }
565
+ return entry;
566
+ }
567
+ function fingerprint(entry) {
568
+ const frames = entry.stacktrace?.frames ?? [];
569
+ const pieces = frames.filter((f) => f.in_app).map((f) => `${f.mangled_name}@${f.source}`);
570
+ return digest([entry.type, ...pieces].join("\n"));
571
+ }
572
+ function exceptionProperties(err, opts) {
573
+ const entry = exceptionEntry(err, opts);
574
+ const frames = entry.stacktrace?.frames ?? [];
575
+ const fp = fingerprint(entry);
576
+ return {
577
+ $exception_list: [entry],
578
+ $exception_fingerprint: fp,
579
+ // Records WHY this fingerprint holds. 'manual' is the honest value: the client
580
+ // supplied the key rather than a server grouper deriving one.
581
+ $exception_fingerprint_record: [{ type: "manual" }],
582
+ $exception_type: entry.type,
583
+ $exception_message: entry.value,
584
+ $exception_level: opts.level ?? "error",
585
+ $exception_handled: opts.handled,
586
+ $exception_synthetic: entry.mechanism?.synthetic ?? false,
587
+ $exception_types: [entry.type],
588
+ $exception_values: [entry.value],
589
+ $exception_sources: frames.map((f) => f.source).filter((s) => !!s),
590
+ $exception_functions: frames.map((f) => f.resolved_name ?? f.mangled_name).filter((s) => !!s)
591
+ };
592
+ }
508
593
 
509
594
  // src/storage.ts
510
595
  var KEY = {
@@ -676,27 +761,24 @@ var Analytics = class {
676
761
  enabled: true,
677
762
  captureErrors: true,
678
763
  ...config,
679
- // The publishable key resolves the SAME way the DSN below does, and now
680
- // ends the SAME way too — in a baked default, so declaring nothing is
681
- // enough. Most specific first:
764
+ // The publishable key resolves from ONE live source, never a literal baked
765
+ // beside the code. Most specific first:
682
766
  // 1. an explicit `ingestKey` in config;
683
767
  // 2. NEXT_PUBLIC_PUBLISHABLE_KEY, the inlined build-time env the fleet
684
- // carries end to end (KMS `deploy/PUBLISHABLE_KEY` -> the PUBLISHABLE_KEY
685
- // build-arg -> the NEXT_PUBLIC_ prefix Next inlines);
686
- // 3. the hanzo org key baked in `dsn.ts`, on the hanzo cloud only.
768
+ // carries end to end KMS `deploy/PUBLISHABLE_KEY` -> the PUBLISHABLE_KEY
769
+ // build-arg -> the NEXT_PUBLIC_ prefix Next inlines.
687
770
  //
688
- // (3) is why this is `publishable_key for all`: a hanzo surface that passes
689
- // no key in code and inlines no env still emits attributed, exactly as
690
- // declaring `product` is enough for the DSN. Without it that surface sent
691
- // its beacons to `$public` which drops every track/identify/group and
692
- // still answers 200 silent in the page and invisible until you read the
693
- // warehouse and find the host missing entirely. A white-label surface on
694
- // its own cloud (a non-default host) gets no default, so the org this
695
- // attributes to is never the wrong one.
696
- ingestKey: config.ingestKey ?? readEnv("NEXT_PUBLIC_PUBLISHABLE_KEY") ?? defaultPublishableKey(config.host ?? DEFAULT_HOST)
771
+ // A surface that provides neither has no key, and its anonymous traffic
772
+ // files under `$public` (which drops track/identify/group and answers 200);
773
+ // the fix is to give it the KMS-sourced env, not to hardcode the org key
774
+ // here. The key is a credential-class value: its home is KMS, and the ONE
775
+ // build reads it from there.
776
+ ingestKey: config.ingestKey ?? readEnv("NEXT_PUBLIC_PUBLISHABLE_KEY")
697
777
  };
698
778
  this.transport = config.transport ?? new DefaultTransport();
699
- this.dsn = parseDsn(config.dsn ?? readEnvDsn() ?? dsnForProduct(this.cfg.product));
779
+ this.dsn = parseDsn(
780
+ config.dsn ?? readEnvDsn() ?? dsnForProduct(this.cfg.product, this.cfg.ingestKey)
781
+ );
700
782
  }
701
783
  /** errorPlaneEnabled reports whether captured exceptions can actually reach the
702
784
  * error host. False means a DSN was never configured — the documented
@@ -781,9 +863,20 @@ var Analytics = class {
781
863
  } catch {
782
864
  }
783
865
  try {
866
+ const handled = context?.handled ?? true;
784
867
  const ex = normalizeError2(err);
785
- ex.handled = context?.handled ?? true;
786
- this.enqueue("error", ex.message, { error: ex, properties: context?.properties });
868
+ ex.handled = handled;
869
+ this.enqueue("event", EXCEPTION, {
870
+ error: ex,
871
+ properties: {
872
+ ...context?.properties,
873
+ ...exceptionProperties(err, {
874
+ handled,
875
+ id: hzUuidv7(),
876
+ level: context?.level
877
+ })
878
+ }
879
+ });
787
880
  this.flush();
788
881
  } catch {
789
882
  }