@hanzo/event 0.3.32 → 0.3.34

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
@@ -84,6 +84,56 @@ function dsnForProduct(product, key) {
84
84
  return `https://${key}@api.hanzo.ai/v1/event/${projectId}`;
85
85
  }
86
86
 
87
+ // src/org.ts
88
+ var ORG_DOMAIN = Object.freeze({
89
+ hanzo: Object.freeze(["hanzo.ai", "hanzo.app", "hanzo.chat", "hanzo.id", "hanzo.bot", "hanzo.sh"]),
90
+ lux: Object.freeze([
91
+ "lux.network",
92
+ "lux.exchange",
93
+ "lux.market",
94
+ "lux.finance",
95
+ "lux.financial",
96
+ "lux.credit",
97
+ "lux.fund",
98
+ "lux.id"
99
+ ]),
100
+ zoo: Object.freeze(["zoo.ngo", "zoo.network", "zoolabs.id"])
101
+ });
102
+ var ORG_KEY = Object.freeze({
103
+ hanzo: "pk-rM_CdaF2MQckGCrla113SrR1oH4zvqN8xh2I95Z9tY8",
104
+ lux: "pk-gUZp6ZVfhJzSwK-rb4oLbVkpCnMBx5uSCpxf_5yEhQk",
105
+ zoo: "pk-3TKpKnERV9AQSsBUERWkZejC1O1mUxc1jRzsP3MPbs4"
106
+ });
107
+ var PUBLISHABLE = "pk-";
108
+ var normalize = (host) => host.trim().toLowerCase().replace(/\.$/, "").split(":")[0] ?? "";
109
+ function orgOf(host) {
110
+ const h = normalize(host);
111
+ if (!h) return void 0;
112
+ let best;
113
+ let bestLen = 0;
114
+ for (const [org, domains] of Object.entries(ORG_DOMAIN)) {
115
+ for (const d of domains) {
116
+ if ((h === d || h.endsWith(`.${d}`)) && d.length > bestLen) {
117
+ best = org;
118
+ bestLen = d.length;
119
+ }
120
+ }
121
+ }
122
+ return best;
123
+ }
124
+ function keyFor(host, keyring = ORG_KEY) {
125
+ const org = orgOf(host);
126
+ if (!org) return void 0;
127
+ const key = keyring[org];
128
+ if (typeof key !== "string") return void 0;
129
+ const trimmed = key.trim();
130
+ return trimmed.startsWith(PUBLISHABLE) ? trimmed : void 0;
131
+ }
132
+ function keyForPage(keyring = ORG_KEY) {
133
+ if (typeof location === "undefined") return void 0;
134
+ return keyFor(location.hostname, keyring);
135
+ }
136
+
87
137
  // src/scrub.ts
88
138
  var REDACTED = "[redacted]";
89
139
  var EMAIL_MARK = "[email]";
@@ -205,8 +255,8 @@ function scrubText(s, capturePII = false) {
205
255
  }
206
256
 
207
257
  // src/anon.js
208
- var HZ_ANON_KEY = "hz_anon_id";
209
- var HZ_ANON_LEGACY_KEY = "hz_id";
258
+ var HZ_ANON_KEY = "iam-anon-id";
259
+ var HZ_ANON_ADOPT = ["hz_anon_id", "hz_id"];
210
260
  var HZ_ANON_DOMAIN = "hanzo.ai";
211
261
  var HZ_ANON_MAX_AGE = 2 * 365 * 24 * 60 * 60;
212
262
  var hzAnonMemo;
@@ -293,10 +343,17 @@ function hzAnonWrite(name, value) {
293
343
  } catch (e) {
294
344
  }
295
345
  }
346
+ function hzAnonAdopted(s) {
347
+ for (var i = 0; i < HZ_ANON_ADOPT.length; i++) {
348
+ var id = hzAnonCookie(HZ_ANON_ADOPT[i]) || hzAnonItem(s, HZ_ANON_ADOPT[i]);
349
+ if (id) return id;
350
+ }
351
+ return "";
352
+ }
296
353
  function hzAnonId() {
297
354
  if (typeof window === "undefined") return "";
298
355
  var s = hzAnonStore();
299
- var id = hzAnonCookie(HZ_ANON_KEY) || hzAnonItem(s, HZ_ANON_KEY) || hzAnonItem(s, HZ_ANON_LEGACY_KEY) || hzAnonMemo || hzUuidv7();
356
+ var id = hzAnonCookie(HZ_ANON_KEY) || hzAnonItem(s, HZ_ANON_KEY) || hzAnonAdopted(s) || hzAnonMemo || hzUuidv7();
300
357
  hzAnonMemo = id;
301
358
  hzAnonWrite(HZ_ANON_KEY, id);
302
359
  try {
@@ -307,7 +364,7 @@ function hzAnonId() {
307
364
  }
308
365
 
309
366
  // src/version.ts
310
- var VERSION = "0.3.32";
367
+ var VERSION = "0.3.34";
311
368
 
312
369
  // src/sentry.ts
313
370
  var MAX_FRAMES = 50;
@@ -769,12 +826,20 @@ var Analytics = class {
769
826
  // carries end to end — KMS `deploy/PUBLISHABLE_KEY` -> the PUBLISHABLE_KEY
770
827
  // build-arg -> the NEXT_PUBLIC_ prefix Next inlines.
771
828
  //
772
- // A surface that provides neither has no key, and its anonymous traffic
773
- // files under `$public` (which drops track/identify/group and answers 200);
774
- // the fix is to give it the KMS-sourced env, not to hardcode the org key
775
- // here. The key is a credential-class value: its home is KMS, and the ONE
776
- // build reads it from there.
777
- ingestKey: config.ingestKey ?? readEnv("NEXT_PUBLIC_PUBLISHABLE_KEY")
829
+ // 3. the org that owns the HOST this page is served from (`org.ts`).
830
+ //
831
+ // Step 3 fires only when a surface configured NOTHING, so it never overrides
832
+ // the KMS chain above it replaces going dark with reporting to the right
833
+ // brand. That is what a static export needs: `output: export` inlines no env,
834
+ // so before this the only way to report was to commit a key literal, and the
835
+ // fleet grew one copy per site of a value with a single source.
836
+ //
837
+ // A surface no brand claims still has no key, and the door REFUSES an
838
+ // unattributed event (401 `ingest_key_required`) — the reserved `$public`
839
+ // tenant that once caught keyless beacons is retired, and anonymous ingest is
840
+ // refused at every door on every brand host. So there is no quiet fallback to
841
+ // rely on: an event lands in the org a credential names, or it does not land.
842
+ ingestKey: config.ingestKey ?? readEnv("NEXT_PUBLIC_PUBLISHABLE_KEY") ?? keyForPage()
778
843
  };
779
844
  this.transport = config.transport ?? new DefaultTransport();
780
845
  this.dsn = parseDsn(
@@ -1114,26 +1179,26 @@ var ErrorBoundary = class extends Component {
1114
1179
  }
1115
1180
  };
1116
1181
  ErrorBoundary.contextType = Ctx;
1117
- /*! anon.js — THE anonymous-identity chain. ONE implementation, three distributions.
1182
+ /*! anon.js — THE anonymous-identity chain. ONE implementation, two distributions.
1118
1183
  *
1119
1184
  * One browser is ONE person on every Hanzo surface, whichever client a page
1120
- * happens to have loaded. There were three implementations writing TWO keys —
1121
- * `hz_anon_id` (the npm client, the hosted tag) and `hz_id` (hz.js) — so the same
1122
- * visitor was several people depending on which snippet the surface shipped.
1185
+ * happens to have loaded. There were once three implementations writing TWO keys —
1186
+ * `hz_anon_id` and `hz_id` — so the same visitor was several people depending on
1187
+ * which snippet the surface shipped.
1123
1188
  *
1124
- * The three call sites:
1189
+ * The two call sites:
1125
1190
  * 1. src/storage.ts — the bundled npm client; IMPORTS this file.
1126
- * 2. hz.js — the no-build script tag; INLINES the marked region.
1127
- * 3. hanzoai/cloud apps/analytics/tag.js — the tag the door hosts at
1191
+ * 2. hanzoai/cloud apps/analytics/tag.js — the tag the door hosts at
1128
1192
  * /v1/event.js; vendors this file and its tag.go serves the marked region
1129
1193
  * with the tag as one asset, so the door holds no second copy either.
1130
1194
  *
1131
- * (2) and (3) have no bundler and cannot import anything, which is why the chain
1132
- * lives in a file that is plain ES5 rather than in a .ts: the region between the
1133
- * BEGIN and END markers is COPIED VERBATIM, and src/anon.test.ts fails if hz.js's
1134
- * copy is so much as a byte different. Keep the region ES5, dependency-free,
1135
- * `hz`-prefixed (it is spliced into other people's scopes) and unformatted — a
1136
- * reformat of one copy is a diff against the other.
1195
+ * (2) has no bundler and cannot import anything, which is why the chain lives in a
1196
+ * file that is plain ES5 rather than in a .ts: the region between the BEGIN and END
1197
+ * markers is COPIED VERBATIM. Keep it ES5, dependency-free, `hz`-prefixed (it is
1198
+ * spliced into other people's scopes) and unformatted a reformat here is a diff
1199
+ * against the vendored copy. After editing, resync the door:
1200
+ *
1201
+ * curl -fsSL https://unpkg.com/@hanzo/event/src/anon.js -o apps/analytics/anon.js
1137
1202
  */
1138
1203
 
1139
1204
  export { AnalyticsProvider, ErrorBoundary, useAnalytics, usePageview };