@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/index.d.cts CHANGED
@@ -8,7 +8,7 @@ declare function getFirstTouch(): Attribution | undefined;
8
8
  /** Read persisted cohort dimensions. */
9
9
  declare function getCohort(): Cohort | undefined;
10
10
 
11
- declare const VERSION = "0.3.32";
11
+ declare const VERSION = "0.3.34";
12
12
 
13
13
  /**
14
14
  * parseDsn parses "https://<version>:<hmac>@<host>/v1/event/<projectId>" into its
@@ -63,7 +63,7 @@ declare function buildSentryEvent(input: BuildEventInput): SentryEvent;
63
63
  declare function buildEnvelope(event: SentryEvent, dsn: Dsn, sentAt?: string): string;
64
64
 
65
65
  // Types for anon.js, which is hand-written ES5 rather than TypeScript because
66
- // hz.js and the door's hosted tag inline it VERBATIM and neither has a compiler.
66
+ // The door's hosted tag inlines it VERBATIM and has no compiler.
67
67
  // The declarations are here so the bundled client still imports it typed.
68
68
 
69
69
  /** Mints a time-ordered UUIDv7 (RFC 9562 §5.7) for `now` in epoch milliseconds. */
@@ -215,4 +215,78 @@ declare function hasAttribution(a: Attribution): boolean;
215
215
  /** isoWeek returns the ISO-8601 week label, e.g. "2026-W28". */
216
216
  declare function isoWeek(d: Date): string;
217
217
 
218
- export { Attribution, COHORTS, CaptureErrorOptions, Cohort, type CohortDef, Dsn, type ErrorIdentity, ExceptionEntry, ExceptionProperties, GOALS, type GoalDef, PRODUCT_PROJECT, SentryEvent, SentryFrame, SentryLevel, VERSION, buildEnvelope, buildSentryEvent, deriveChannel, digest, dsnForProduct, exceptionEntry, exceptionProperties, fingerprint, framesFromStack, getCohort, getFirstTouch, hasAttribution, hostOf, isoWeek, parseAttribution, parseDsn, redactSecrets, scrubPII, scrubText, hzUuidv7 as uuidv7, uuidv7Time };
218
+ /**
219
+ * Which org owns a host's telemetry.
220
+ *
221
+ * A surface should not have to LEARN its key. It already knows the domain it is
222
+ * served from, and a domain belongs to exactly one brand, so the key is derivable
223
+ * and asking a surface to carry one is asking it to restate something already
224
+ * true. This module answers `orgOf(location.hostname)` and hands back that org's
225
+ * publishable key, which is what lets a static export report correctly while
226
+ * configuring nothing.
227
+ *
228
+ * This is the SAME question `hanzo.id` answers at runtime for the identity hosts
229
+ * (`pkgs/shared/src/ingest.ts`): one image serves every brand, so the key cannot
230
+ * be a property of the build. It was, and the bill is on record — Lux's, Zoo's,
231
+ * Osage's and Pars' visitors were all filed in HANZO's project, because one
232
+ * build-time key was inlined for every brand. That is the white-label boundary
233
+ * crossed in the direction that shows up latest. The marketing sites carry the
234
+ * identical defect in its other form: each commits its OWN key literal, so the
235
+ * fleet holds N copies of a value with one source, and a site added tomorrow
236
+ * reports nothing until somebody remembers to paste one in.
237
+ *
238
+ * A `pk-` is PUBLISHABLE: it authorizes a write into one org and mints no reading
239
+ * principal. It is readable in devtools on every deployed page that sends an
240
+ * event, so stating it here exposes nothing that serving the page did not. What
241
+ * it does buy is that correct attribution becomes the DEFAULT rather than
242
+ * something each surface opts into.
243
+ *
244
+ * Keyed by ORG, never by host: a brand's facts repeat on every alias it owns
245
+ * (`lux.id`, `id.lux.network`), and a key stated per host would have to be
246
+ * repeated too — so the day someone adds an alias and forgets the key, that host
247
+ * silently stops reporting. Stated once per org, a new alias inherits its brand's
248
+ * key by naming its brand's domain, which is all an alias ever says.
249
+ */
250
+ /** One publishable key per org. */
251
+ type Keyring = Readonly<Record<string, string>>;
252
+ /**
253
+ * Each org's registrable domains. A host matches a domain when it IS that domain
254
+ * or a subdomain of it, so `explore.lux.network` needs no entry of its own.
255
+ *
256
+ * An org absent from this table resolves to undefined, and that is deliberate:
257
+ * `osage`, `pars` and `bootnode` have no project of their own yet, and reporting
258
+ * NOTHING is the honest answer. Filing them under a brand that is not theirs is
259
+ * the defect this module exists to prevent — it is silent, it reads as working,
260
+ * and it is only visible later in someone else's warehouse.
261
+ */
262
+ declare const ORG_DOMAIN: Readonly<Record<string, readonly string[]>>;
263
+ /**
264
+ * Each org's publishable key — the same values `universe`'s `SPA_INGEST_KEYRING`
265
+ * serves to the identity hosts, which are each brand's own insights team token.
266
+ * Add an org here the day its project exists, never before.
267
+ */
268
+ declare const ORG_KEY: Keyring;
269
+ /**
270
+ * The org that owns a host, or undefined when no brand claims it.
271
+ *
272
+ * Longest match wins, so a brand owning both a domain and a subdomain of another
273
+ * brand's cannot be decided by table order. Pure and total.
274
+ */
275
+ declare function orgOf(host: string): string | undefined;
276
+ /**
277
+ * The publishable key for a host, or undefined when there is not exactly one to
278
+ * give.
279
+ *
280
+ * Deliberately WITHOUT a fallback: returning Hanzo's key for an unrecognised host
281
+ * is precisely the defect described above. Undefined is the honest answer and the
282
+ * caller reports nothing.
283
+ *
284
+ * `keyring` is a parameter so the identity runtime — which receives its keyring
285
+ * from `/config.json` because one image serves every brand — resolves through
286
+ * this SAME function rather than a second copy of it.
287
+ */
288
+ declare function keyFor(host: string, keyring?: Keyring): string | undefined;
289
+ /** The key for the page this code is running on; undefined off a browser. */
290
+ declare function keyForPage(keyring?: Keyring): string | undefined;
291
+
292
+ export { Attribution, COHORTS, CaptureErrorOptions, Cohort, type CohortDef, Dsn, type ErrorIdentity, ExceptionEntry, ExceptionProperties, GOALS, type GoalDef, type Keyring, ORG_DOMAIN, ORG_KEY, PRODUCT_PROJECT, SentryEvent, SentryFrame, SentryLevel, VERSION, buildEnvelope, buildSentryEvent, deriveChannel, digest, dsnForProduct, exceptionEntry, exceptionProperties, fingerprint, framesFromStack, getCohort, getFirstTouch, hasAttribution, hostOf, isoWeek, keyFor, keyForPage, orgOf, parseAttribution, parseDsn, redactSecrets, scrubPII, scrubText, hzUuidv7 as uuidv7, uuidv7Time };
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ declare function getFirstTouch(): Attribution | undefined;
8
8
  /** Read persisted cohort dimensions. */
9
9
  declare function getCohort(): Cohort | undefined;
10
10
 
11
- declare const VERSION = "0.3.32";
11
+ declare const VERSION = "0.3.34";
12
12
 
13
13
  /**
14
14
  * parseDsn parses "https://<version>:<hmac>@<host>/v1/event/<projectId>" into its
@@ -63,7 +63,7 @@ declare function buildSentryEvent(input: BuildEventInput): SentryEvent;
63
63
  declare function buildEnvelope(event: SentryEvent, dsn: Dsn, sentAt?: string): string;
64
64
 
65
65
  // Types for anon.js, which is hand-written ES5 rather than TypeScript because
66
- // hz.js and the door's hosted tag inline it VERBATIM and neither has a compiler.
66
+ // The door's hosted tag inlines it VERBATIM and has no compiler.
67
67
  // The declarations are here so the bundled client still imports it typed.
68
68
 
69
69
  /** Mints a time-ordered UUIDv7 (RFC 9562 §5.7) for `now` in epoch milliseconds. */
@@ -215,4 +215,78 @@ declare function hasAttribution(a: Attribution): boolean;
215
215
  /** isoWeek returns the ISO-8601 week label, e.g. "2026-W28". */
216
216
  declare function isoWeek(d: Date): string;
217
217
 
218
- export { Attribution, COHORTS, CaptureErrorOptions, Cohort, type CohortDef, Dsn, type ErrorIdentity, ExceptionEntry, ExceptionProperties, GOALS, type GoalDef, PRODUCT_PROJECT, SentryEvent, SentryFrame, SentryLevel, VERSION, buildEnvelope, buildSentryEvent, deriveChannel, digest, dsnForProduct, exceptionEntry, exceptionProperties, fingerprint, framesFromStack, getCohort, getFirstTouch, hasAttribution, hostOf, isoWeek, parseAttribution, parseDsn, redactSecrets, scrubPII, scrubText, hzUuidv7 as uuidv7, uuidv7Time };
218
+ /**
219
+ * Which org owns a host's telemetry.
220
+ *
221
+ * A surface should not have to LEARN its key. It already knows the domain it is
222
+ * served from, and a domain belongs to exactly one brand, so the key is derivable
223
+ * and asking a surface to carry one is asking it to restate something already
224
+ * true. This module answers `orgOf(location.hostname)` and hands back that org's
225
+ * publishable key, which is what lets a static export report correctly while
226
+ * configuring nothing.
227
+ *
228
+ * This is the SAME question `hanzo.id` answers at runtime for the identity hosts
229
+ * (`pkgs/shared/src/ingest.ts`): one image serves every brand, so the key cannot
230
+ * be a property of the build. It was, and the bill is on record — Lux's, Zoo's,
231
+ * Osage's and Pars' visitors were all filed in HANZO's project, because one
232
+ * build-time key was inlined for every brand. That is the white-label boundary
233
+ * crossed in the direction that shows up latest. The marketing sites carry the
234
+ * identical defect in its other form: each commits its OWN key literal, so the
235
+ * fleet holds N copies of a value with one source, and a site added tomorrow
236
+ * reports nothing until somebody remembers to paste one in.
237
+ *
238
+ * A `pk-` is PUBLISHABLE: it authorizes a write into one org and mints no reading
239
+ * principal. It is readable in devtools on every deployed page that sends an
240
+ * event, so stating it here exposes nothing that serving the page did not. What
241
+ * it does buy is that correct attribution becomes the DEFAULT rather than
242
+ * something each surface opts into.
243
+ *
244
+ * Keyed by ORG, never by host: a brand's facts repeat on every alias it owns
245
+ * (`lux.id`, `id.lux.network`), and a key stated per host would have to be
246
+ * repeated too — so the day someone adds an alias and forgets the key, that host
247
+ * silently stops reporting. Stated once per org, a new alias inherits its brand's
248
+ * key by naming its brand's domain, which is all an alias ever says.
249
+ */
250
+ /** One publishable key per org. */
251
+ type Keyring = Readonly<Record<string, string>>;
252
+ /**
253
+ * Each org's registrable domains. A host matches a domain when it IS that domain
254
+ * or a subdomain of it, so `explore.lux.network` needs no entry of its own.
255
+ *
256
+ * An org absent from this table resolves to undefined, and that is deliberate:
257
+ * `osage`, `pars` and `bootnode` have no project of their own yet, and reporting
258
+ * NOTHING is the honest answer. Filing them under a brand that is not theirs is
259
+ * the defect this module exists to prevent — it is silent, it reads as working,
260
+ * and it is only visible later in someone else's warehouse.
261
+ */
262
+ declare const ORG_DOMAIN: Readonly<Record<string, readonly string[]>>;
263
+ /**
264
+ * Each org's publishable key — the same values `universe`'s `SPA_INGEST_KEYRING`
265
+ * serves to the identity hosts, which are each brand's own insights team token.
266
+ * Add an org here the day its project exists, never before.
267
+ */
268
+ declare const ORG_KEY: Keyring;
269
+ /**
270
+ * The org that owns a host, or undefined when no brand claims it.
271
+ *
272
+ * Longest match wins, so a brand owning both a domain and a subdomain of another
273
+ * brand's cannot be decided by table order. Pure and total.
274
+ */
275
+ declare function orgOf(host: string): string | undefined;
276
+ /**
277
+ * The publishable key for a host, or undefined when there is not exactly one to
278
+ * give.
279
+ *
280
+ * Deliberately WITHOUT a fallback: returning Hanzo's key for an unrecognised host
281
+ * is precisely the defect described above. Undefined is the honest answer and the
282
+ * caller reports nothing.
283
+ *
284
+ * `keyring` is a parameter so the identity runtime — which receives its keyring
285
+ * from `/config.json` because one image serves every brand — resolves through
286
+ * this SAME function rather than a second copy of it.
287
+ */
288
+ declare function keyFor(host: string, keyring?: Keyring): string | undefined;
289
+ /** The key for the page this code is running on; undefined off a browser. */
290
+ declare function keyForPage(keyring?: Keyring): string | undefined;
291
+
292
+ export { Attribution, COHORTS, CaptureErrorOptions, Cohort, type CohortDef, Dsn, type ErrorIdentity, ExceptionEntry, ExceptionProperties, GOALS, type GoalDef, type Keyring, ORG_DOMAIN, ORG_KEY, PRODUCT_PROJECT, SentryEvent, SentryFrame, SentryLevel, VERSION, buildEnvelope, buildSentryEvent, deriveChannel, digest, dsnForProduct, exceptionEntry, exceptionProperties, fingerprint, framesFromStack, getCohort, getFirstTouch, hasAttribution, hostOf, isoWeek, keyFor, keyForPage, orgOf, parseAttribution, parseDsn, redactSecrets, scrubPII, scrubText, hzUuidv7 as uuidv7, uuidv7Time };
package/dist/index.mjs CHANGED
@@ -90,6 +90,56 @@ function dsnForProduct(product, key) {
90
90
  return `https://${key}@api.hanzo.ai/v1/event/${projectId}`;
91
91
  }
92
92
 
93
+ // src/org.ts
94
+ var ORG_DOMAIN = Object.freeze({
95
+ hanzo: Object.freeze(["hanzo.ai", "hanzo.app", "hanzo.chat", "hanzo.id", "hanzo.bot", "hanzo.sh"]),
96
+ lux: Object.freeze([
97
+ "lux.network",
98
+ "lux.exchange",
99
+ "lux.market",
100
+ "lux.finance",
101
+ "lux.financial",
102
+ "lux.credit",
103
+ "lux.fund",
104
+ "lux.id"
105
+ ]),
106
+ zoo: Object.freeze(["zoo.ngo", "zoo.network", "zoolabs.id"])
107
+ });
108
+ var ORG_KEY = Object.freeze({
109
+ hanzo: "pk-rM_CdaF2MQckGCrla113SrR1oH4zvqN8xh2I95Z9tY8",
110
+ lux: "pk-gUZp6ZVfhJzSwK-rb4oLbVkpCnMBx5uSCpxf_5yEhQk",
111
+ zoo: "pk-3TKpKnERV9AQSsBUERWkZejC1O1mUxc1jRzsP3MPbs4"
112
+ });
113
+ var PUBLISHABLE = "pk-";
114
+ var normalize = (host) => host.trim().toLowerCase().replace(/\.$/, "").split(":")[0] ?? "";
115
+ function orgOf(host) {
116
+ const h = normalize(host);
117
+ if (!h) return void 0;
118
+ let best;
119
+ let bestLen = 0;
120
+ for (const [org, domains] of Object.entries(ORG_DOMAIN)) {
121
+ for (const d of domains) {
122
+ if ((h === d || h.endsWith(`.${d}`)) && d.length > bestLen) {
123
+ best = org;
124
+ bestLen = d.length;
125
+ }
126
+ }
127
+ }
128
+ return best;
129
+ }
130
+ function keyFor(host, keyring = ORG_KEY) {
131
+ const org = orgOf(host);
132
+ if (!org) return void 0;
133
+ const key = keyring[org];
134
+ if (typeof key !== "string") return void 0;
135
+ const trimmed = key.trim();
136
+ return trimmed.startsWith(PUBLISHABLE) ? trimmed : void 0;
137
+ }
138
+ function keyForPage(keyring = ORG_KEY) {
139
+ if (typeof location === "undefined") return void 0;
140
+ return keyFor(location.hostname, keyring);
141
+ }
142
+
93
143
  // src/scrub.ts
94
144
  var REDACTED = "[redacted]";
95
145
  var EMAIL_MARK = "[email]";
@@ -211,8 +261,8 @@ function scrubText(s, capturePII = false) {
211
261
  }
212
262
 
213
263
  // src/anon.js
214
- var HZ_ANON_KEY = "hz_anon_id";
215
- var HZ_ANON_LEGACY_KEY = "hz_id";
264
+ var HZ_ANON_KEY = "iam-anon-id";
265
+ var HZ_ANON_ADOPT = ["hz_anon_id", "hz_id"];
216
266
  var HZ_ANON_DOMAIN = "hanzo.ai";
217
267
  var HZ_ANON_MAX_AGE = 2 * 365 * 24 * 60 * 60;
218
268
  var hzAnonMemo;
@@ -299,10 +349,17 @@ function hzAnonWrite(name, value) {
299
349
  } catch (e) {
300
350
  }
301
351
  }
352
+ function hzAnonAdopted(s) {
353
+ for (var i = 0; i < HZ_ANON_ADOPT.length; i++) {
354
+ var id = hzAnonCookie(HZ_ANON_ADOPT[i]) || hzAnonItem(s, HZ_ANON_ADOPT[i]);
355
+ if (id) return id;
356
+ }
357
+ return "";
358
+ }
302
359
  function hzAnonId() {
303
360
  if (typeof window === "undefined") return "";
304
361
  var s = hzAnonStore();
305
- var id = hzAnonCookie(HZ_ANON_KEY) || hzAnonItem(s, HZ_ANON_KEY) || hzAnonItem(s, HZ_ANON_LEGACY_KEY) || hzAnonMemo || hzUuidv7();
362
+ var id = hzAnonCookie(HZ_ANON_KEY) || hzAnonItem(s, HZ_ANON_KEY) || hzAnonAdopted(s) || hzAnonMemo || hzUuidv7();
306
363
  hzAnonMemo = id;
307
364
  hzAnonWrite(HZ_ANON_KEY, id);
308
365
  try {
@@ -318,7 +375,7 @@ function uuidv7Time(id) {
318
375
  }
319
376
 
320
377
  // src/version.ts
321
- var VERSION = "0.3.32";
378
+ var VERSION = "0.3.34";
322
379
 
323
380
  // src/sentry.ts
324
381
  var MAX_FRAMES = 50;
@@ -780,12 +837,20 @@ var Analytics = class {
780
837
  // carries end to end — KMS `deploy/PUBLISHABLE_KEY` -> the PUBLISHABLE_KEY
781
838
  // build-arg -> the NEXT_PUBLIC_ prefix Next inlines.
782
839
  //
783
- // A surface that provides neither has no key, and its anonymous traffic
784
- // files under `$public` (which drops track/identify/group and answers 200);
785
- // the fix is to give it the KMS-sourced env, not to hardcode the org key
786
- // here. The key is a credential-class value: its home is KMS, and the ONE
787
- // build reads it from there.
788
- ingestKey: config.ingestKey ?? readEnv("NEXT_PUBLIC_PUBLISHABLE_KEY")
840
+ // 3. the org that owns the HOST this page is served from (`org.ts`).
841
+ //
842
+ // Step 3 fires only when a surface configured NOTHING, so it never overrides
843
+ // the KMS chain above it replaces going dark with reporting to the right
844
+ // brand. That is what a static export needs: `output: export` inlines no env,
845
+ // so before this the only way to report was to commit a key literal, and the
846
+ // fleet grew one copy per site of a value with a single source.
847
+ //
848
+ // A surface no brand claims still has no key, and the door REFUSES an
849
+ // unattributed event (401 `ingest_key_required`) — the reserved `$public`
850
+ // tenant that once caught keyless beacons is retired, and anonymous ingest is
851
+ // refused at every door on every brand host. So there is no quiet fallback to
852
+ // rely on: an event lands in the org a credential names, or it does not land.
853
+ ingestKey: config.ingestKey ?? readEnv("NEXT_PUBLIC_PUBLISHABLE_KEY") ?? keyForPage()
789
854
  };
790
855
  this.transport = config.transport ?? new DefaultTransport();
791
856
  this.dsn = parseDsn(
@@ -1109,28 +1174,28 @@ var COHORTS = {
1109
1174
  channel: { field: "channel", label: "Acquisition channel" },
1110
1175
  refCode: { field: "ref_code", label: "Referral code" }
1111
1176
  };
1112
- /*! anon.js — THE anonymous-identity chain. ONE implementation, three distributions.
1177
+ /*! anon.js — THE anonymous-identity chain. ONE implementation, two distributions.
1113
1178
  *
1114
1179
  * One browser is ONE person on every Hanzo surface, whichever client a page
1115
- * happens to have loaded. There were three implementations writing TWO keys —
1116
- * `hz_anon_id` (the npm client, the hosted tag) and `hz_id` (hz.js) — so the same
1117
- * visitor was several people depending on which snippet the surface shipped.
1180
+ * happens to have loaded. There were once three implementations writing TWO keys —
1181
+ * `hz_anon_id` and `hz_id` — so the same visitor was several people depending on
1182
+ * which snippet the surface shipped.
1118
1183
  *
1119
- * The three call sites:
1184
+ * The two call sites:
1120
1185
  * 1. src/storage.ts — the bundled npm client; IMPORTS this file.
1121
- * 2. hz.js — the no-build script tag; INLINES the marked region.
1122
- * 3. hanzoai/cloud apps/analytics/tag.js — the tag the door hosts at
1186
+ * 2. hanzoai/cloud apps/analytics/tag.js — the tag the door hosts at
1123
1187
  * /v1/event.js; vendors this file and its tag.go serves the marked region
1124
1188
  * with the tag as one asset, so the door holds no second copy either.
1125
1189
  *
1126
- * (2) and (3) have no bundler and cannot import anything, which is why the chain
1127
- * lives in a file that is plain ES5 rather than in a .ts: the region between the
1128
- * BEGIN and END markers is COPIED VERBATIM, and src/anon.test.ts fails if hz.js's
1129
- * copy is so much as a byte different. Keep the region ES5, dependency-free,
1130
- * `hz`-prefixed (it is spliced into other people's scopes) and unformatted — a
1131
- * reformat of one copy is a diff against the other.
1190
+ * (2) has no bundler and cannot import anything, which is why the chain lives in a
1191
+ * file that is plain ES5 rather than in a .ts: the region between the BEGIN and END
1192
+ * markers is COPIED VERBATIM. Keep it ES5, dependency-free, `hz`-prefixed (it is
1193
+ * spliced into other people's scopes) and unformatted a reformat here is a diff
1194
+ * against the vendored copy. After editing, resync the door:
1195
+ *
1196
+ * curl -fsSL https://unpkg.com/@hanzo/event/src/anon.js -o apps/analytics/anon.js
1132
1197
  */
1133
1198
 
1134
- export { Analytics, COHORTS, GOALS, PRODUCT_PROJECT, VERSION, buildEnvelope, buildSentryEvent, createAnalytics, deriveChannel, digest, dsnForProduct, exceptionEntry, exceptionProperties, fingerprint, framesFromStack, getCohort, getFirstTouch, hasAttribution, hostOf, isoWeek, parseAttribution, parseDsn, redactSecrets, scrubPII, scrubText, hzUuidv7 as uuidv7, uuidv7Time };
1199
+ export { Analytics, COHORTS, GOALS, ORG_DOMAIN, ORG_KEY, PRODUCT_PROJECT, VERSION, buildEnvelope, buildSentryEvent, createAnalytics, deriveChannel, digest, dsnForProduct, exceptionEntry, exceptionProperties, fingerprint, framesFromStack, getCohort, getFirstTouch, hasAttribution, hostOf, isoWeek, keyFor, keyForPage, orgOf, parseAttribution, parseDsn, redactSecrets, scrubPII, scrubText, hzUuidv7 as uuidv7, uuidv7Time };
1135
1200
  //# sourceMappingURL=index.mjs.map
1136
1201
  //# sourceMappingURL=index.mjs.map