@hanzo/event 0.3.13 → 0.3.15

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
@@ -204,31 +204,110 @@ function scrubText(s, capturePII = false) {
204
204
  return s;
205
205
  }
206
206
 
207
- // src/uid.ts
208
- var HEX = Array.from({ length: 256 }, (_, i) => (i + 256).toString(16).slice(1));
209
- function fill(b) {
210
- const c = typeof crypto !== "undefined" ? crypto : void 0;
211
- if (c && typeof c.getRandomValues === "function") {
212
- c.getRandomValues(b);
213
- return b;
214
- }
215
- for (let i = 0; i < b.length; i++) b[i] = Math.random() * 256 | 0;
216
- return b;
217
- }
218
- function uuidv7(now = Date.now()) {
219
- const b = fill(new Uint8Array(16));
220
- let t = Math.floor(now);
221
- for (let i = 5; i >= 0; i--) {
207
+ // src/anon.js
208
+ var HZ_ANON_KEY = "hz_anon_id";
209
+ var HZ_ANON_LEGACY_KEY = "hz_id";
210
+ var HZ_ANON_DOMAIN = "hanzo.ai";
211
+ var HZ_ANON_MAX_AGE = 2 * 365 * 24 * 60 * 60;
212
+ var hzAnonMemo;
213
+ function hzUuidv7(now) {
214
+ var b = new Uint8Array(16);
215
+ var i;
216
+ var c = typeof crypto !== "undefined" ? crypto : void 0;
217
+ if (c && typeof c.getRandomValues === "function") c.getRandomValues(b);
218
+ else for (i = 0; i < 16; i++) b[i] = Math.random() * 256 | 0;
219
+ var t = Math.floor(now === void 0 ? Date.now() : now);
220
+ for (i = 5; i >= 0; i--) {
222
221
  b[i] = t % 256;
223
222
  t = Math.floor(t / 256);
224
223
  }
225
224
  b[6] = 112 | b[6] & 15;
226
225
  b[8] = 128 | b[8] & 63;
227
- return HEX[b[0]] + HEX[b[1]] + HEX[b[2]] + HEX[b[3]] + "-" + HEX[b[4]] + HEX[b[5]] + "-" + HEX[b[6]] + HEX[b[7]] + "-" + HEX[b[8]] + HEX[b[9]] + "-" + HEX[b[10]] + HEX[b[11]] + HEX[b[12]] + HEX[b[13]] + HEX[b[14]] + HEX[b[15]];
226
+ var h = "";
227
+ for (i = 0; i < 16; i++) {
228
+ h += (b[i] + 256).toString(16).slice(1);
229
+ if (i === 3 || i === 5 || i === 7 || i === 9) h += "-";
230
+ }
231
+ return h;
232
+ }
233
+ function hzAnonJar() {
234
+ try {
235
+ if (typeof document === "undefined" || typeof document.cookie !== "string") return null;
236
+ return document;
237
+ } catch (e) {
238
+ return null;
239
+ }
240
+ }
241
+ function hzAnonStore() {
242
+ try {
243
+ if (typeof window === "undefined" || !window.localStorage) return null;
244
+ return window.localStorage;
245
+ } catch (e) {
246
+ return null;
247
+ }
248
+ }
249
+ function hzAnonItem(store, name) {
250
+ try {
251
+ return store && store.getItem(name) || "";
252
+ } catch (e) {
253
+ return "";
254
+ }
255
+ }
256
+ function hzAnonCookie(name) {
257
+ var d = hzAnonJar();
258
+ if (!d) return "";
259
+ var parts = d.cookie.split(";");
260
+ for (var i = 0; i < parts.length; i++) {
261
+ var eq = parts[i].indexOf("=");
262
+ if (eq < 0 || parts[i].slice(0, eq).trim() !== name) continue;
263
+ var v = parts[i].slice(eq + 1).trim();
264
+ if (!v) continue;
265
+ try {
266
+ return decodeURIComponent(v);
267
+ } catch (e) {
268
+ return v;
269
+ }
270
+ }
271
+ return "";
272
+ }
273
+ function hzAnonWrite(name, value) {
274
+ var d = hzAnonJar();
275
+ if (!d) return;
276
+ var host = "";
277
+ var secure = false;
278
+ try {
279
+ if (typeof window !== "undefined" && window.location) {
280
+ host = window.location.hostname || "";
281
+ secure = window.location.protocol === "https:";
282
+ }
283
+ } catch (e) {
284
+ }
285
+ var c = name + "=" + encodeURIComponent(value);
286
+ c += "; Path=/; Max-Age=" + HZ_ANON_MAX_AGE + "; SameSite=Lax";
287
+ if (("." + host).slice(-(HZ_ANON_DOMAIN.length + 1)) === "." + HZ_ANON_DOMAIN) {
288
+ c += "; Domain=" + HZ_ANON_DOMAIN;
289
+ }
290
+ if (secure) c += "; Secure";
291
+ try {
292
+ d.cookie = c;
293
+ } catch (e) {
294
+ }
295
+ }
296
+ function hzAnonId() {
297
+ if (typeof window === "undefined") return "";
298
+ var s = hzAnonStore();
299
+ var id = hzAnonCookie(HZ_ANON_KEY) || hzAnonItem(s, HZ_ANON_KEY) || hzAnonItem(s, HZ_ANON_LEGACY_KEY) || hzAnonMemo || hzUuidv7();
300
+ hzAnonMemo = id;
301
+ hzAnonWrite(HZ_ANON_KEY, id);
302
+ try {
303
+ if (s && s.getItem(HZ_ANON_KEY) !== id) s.setItem(HZ_ANON_KEY, id);
304
+ } catch (e) {
305
+ }
306
+ return id;
228
307
  }
229
308
 
230
309
  // src/version.ts
231
- var VERSION = "0.3.13";
310
+ var VERSION = "0.3.15";
232
311
 
233
312
  // src/sentry.ts
234
313
  var MAX_FRAMES = 50;
@@ -237,7 +316,7 @@ var MAX_LINE_LEN = 2048;
237
316
  var MAX_TAG_LEN = 1024;
238
317
  var MAX_TAGS = 50;
239
318
  function eventId() {
240
- return uuidv7().replace(/-/g, "");
319
+ return hzUuidv7().replace(/-/g, "");
241
320
  }
242
321
  function byteLen(s) {
243
322
  if (typeof TextEncoder !== "undefined") return new TextEncoder().encode(s).length;
@@ -423,7 +502,6 @@ ${payload}
423
502
 
424
503
  // src/storage.ts
425
504
  var KEY = {
426
- anon: "hz_anon_id",
427
505
  session: "hz_session",
428
506
  firstTouch: "hz_first_touch",
429
507
  cohort: "hz_cohort"
@@ -438,14 +516,7 @@ function ls() {
438
516
  }
439
517
  }
440
518
  function anonId() {
441
- const s = ls();
442
- if (!s) return void 0;
443
- let v = s.getItem(KEY.anon);
444
- if (!v) {
445
- v = uuidv7();
446
- s.setItem(KEY.anon, v);
447
- }
448
- return v;
519
+ return hzAnonId() || void 0;
449
520
  }
450
521
  function sessionId(now = Date.now()) {
451
522
  const s = ls();
@@ -457,7 +528,7 @@ function sessionId(now = Date.now()) {
457
528
  state = null;
458
529
  }
459
530
  if (!state || now - state.last > SESSION_TTL_MS) {
460
- state = { id: uuidv7(now), last: now };
531
+ state = { id: hzUuidv7(now), last: now };
461
532
  } else {
462
533
  state.last = now;
463
534
  }
@@ -793,7 +864,7 @@ var Analytics = class {
793
864
  build(kind, event, extra) {
794
865
  const anon = anonId();
795
866
  const wire = {
796
- messageId: uuidv7(),
867
+ messageId: hzUuidv7(),
797
868
  type: kind,
798
869
  event,
799
870
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -906,6 +977,27 @@ var ErrorBoundary = class extends Component {
906
977
  }
907
978
  };
908
979
  ErrorBoundary.contextType = Ctx;
980
+ /*! anon.js — THE anonymous-identity chain. ONE implementation, three distributions.
981
+ *
982
+ * One browser is ONE person on every Hanzo surface, whichever client a page
983
+ * happens to have loaded. There were three implementations writing TWO keys —
984
+ * `hz_anon_id` (the npm client, the hosted tag) and `hz_id` (hz.js) — so the same
985
+ * visitor was several people depending on which snippet the surface shipped.
986
+ *
987
+ * The three call sites:
988
+ * 1. src/storage.ts — the bundled npm client; IMPORTS this file.
989
+ * 2. hz.js — the no-build script tag; INLINES the marked region.
990
+ * 3. hanzoai/cloud apps/analytics/tag.js — the tag the door hosts at
991
+ * /v1/event.js; vendors this file and its tag.go serves the marked region
992
+ * with the tag as one asset, so the door holds no second copy either.
993
+ *
994
+ * (2) and (3) have no bundler and cannot import anything, which is why the chain
995
+ * lives in a file that is plain ES5 rather than in a .ts: the region between the
996
+ * BEGIN and END markers is COPIED VERBATIM, and src/anon.test.ts fails if hz.js's
997
+ * copy is so much as a byte different. Keep the region ES5, dependency-free,
998
+ * `hz`-prefixed (it is spliced into other people's scopes) and unformatted — a
999
+ * reformat of one copy is a diff against the other.
1000
+ */
909
1001
 
910
1002
  export { AnalyticsProvider, ErrorBoundary, useAnalytics, usePageview };
911
1003
  //# sourceMappingURL=react.mjs.map