@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/README.md +17 -19
- package/dist/index.cjs +93 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +77 -3
- package/dist/index.d.ts +77 -3
- package/dist/index.mjs +89 -24
- package/dist/index.mjs.map +1 -1
- package/dist/react.cjs +88 -23
- package/dist/react.cjs.map +1 -1
- package/dist/react.mjs +88 -23
- package/dist/react.mjs.map +1 -1
- package/package.json +2 -3
- package/src/anon.d.ts +2 -2
- package/src/anon.js +43 -23
- package/src/anon.test.ts +17 -38
- package/src/core.ts +16 -6
- package/src/index.ts +7 -0
- package/src/org.test.ts +113 -0
- package/src/org.ts +129 -0
- package/src/stack.ts +144 -0
- package/src/storage.test.ts +3 -3
- package/src/storage.ts +1 -1
- package/src/uid.ts +1 -1
- package/src/version.ts +1 -1
- package/hz.js +0 -511
- package/src/hz.test.ts +0 -376
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 = "
|
|
209
|
-
var
|
|
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) ||
|
|
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.
|
|
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
|
-
//
|
|
773
|
-
//
|
|
774
|
-
//
|
|
775
|
-
//
|
|
776
|
-
//
|
|
777
|
-
|
|
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,
|
|
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`
|
|
1122
|
-
*
|
|
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
|
|
1189
|
+
* The two call sites:
|
|
1125
1190
|
* 1. src/storage.ts — the bundled npm client; IMPORTS this file.
|
|
1126
|
-
* 2.
|
|
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)
|
|
1132
|
-
*
|
|
1133
|
-
*
|
|
1134
|
-
*
|
|
1135
|
-
*
|
|
1136
|
-
*
|
|
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 };
|