@hanzo/event 0.3.12 → 0.3.14

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
@@ -142,7 +142,47 @@ function redactPAN(s) {
142
142
  var RE_EMAIL = /[A-Za-z0-9._%+-]{1,64}@[A-Za-z0-9.-]{1,255}\.[A-Za-z]{2,24}/g;
143
143
  var RE_IPV4 = /\b(?:\d{1,3}\.){3}\d{1,3}\b/g;
144
144
  var RE_IPV6 = /\b(?:[0-9A-Fa-f]{1,4}:){2,7}[0-9A-Fa-f]{1,4}\b/g;
145
+ var CREDENTIAL_PARAMS = [
146
+ "code",
147
+ "state",
148
+ "token",
149
+ "access_token",
150
+ "id_token",
151
+ "refresh_token",
152
+ "auth",
153
+ "authorization",
154
+ "secret",
155
+ "client_secret",
156
+ "password",
157
+ "passwd",
158
+ "pwd",
159
+ "api_key",
160
+ "apikey",
161
+ "key",
162
+ "session",
163
+ "session_id",
164
+ "sid",
165
+ "sig",
166
+ "signature",
167
+ "nonce",
168
+ "otp",
169
+ "invite",
170
+ "invitation",
171
+ "reset_token",
172
+ "confirmation_token",
173
+ "magic",
174
+ "ticket",
175
+ "assertion"
176
+ ];
177
+ var RE_CREDENTIAL_PARAM = new RegExp(
178
+ "([?&#;](?:" + CREDENTIAL_PARAMS.join("|") + ")=)[^&#;\\s]{1,4096}",
179
+ "gi"
180
+ );
181
+ function redactCredentialParams(s) {
182
+ return s.replace(RE_CREDENTIAL_PARAM, (_m, prefix) => prefix + REDACTED);
183
+ }
145
184
  function redactSecrets(s) {
185
+ s = redactCredentialParams(s);
146
186
  for (const re of SECRET_PATTERNS) s = s.replace(re, REDACTED);
147
187
  return redactPAN(s);
148
188
  }
@@ -188,7 +228,7 @@ function uuidv7(now = Date.now()) {
188
228
  }
189
229
 
190
230
  // src/version.ts
191
- var VERSION = "0.3.12";
231
+ var VERSION = "0.3.14";
192
232
 
193
233
  // src/sentry.ts
194
234
  var MAX_FRAMES = 50;
@@ -389,6 +429,8 @@ var KEY = {
389
429
  cohort: "hz_cohort"
390
430
  };
391
431
  var SESSION_TTL_MS = 30 * 60 * 1e3;
432
+ var ANON_DOMAIN = "hanzo.ai";
433
+ var ANON_MAX_AGE_S = 2 * 365 * 24 * 60 * 60;
392
434
  function ls() {
393
435
  try {
394
436
  if (typeof window === "undefined" || !window.localStorage) return void 0;
@@ -397,15 +439,69 @@ function ls() {
397
439
  return void 0;
398
440
  }
399
441
  }
442
+ function jar() {
443
+ try {
444
+ if (typeof document === "undefined" || typeof document.cookie !== "string") return void 0;
445
+ return document;
446
+ } catch {
447
+ return void 0;
448
+ }
449
+ }
450
+ function getCookie(name) {
451
+ const d = jar();
452
+ if (!d) return void 0;
453
+ for (const part of d.cookie.split(";")) {
454
+ const eq = part.indexOf("=");
455
+ if (eq < 0 || part.slice(0, eq).trim() !== name) continue;
456
+ const v = part.slice(eq + 1).trim();
457
+ if (!v) continue;
458
+ try {
459
+ return decodeURIComponent(v);
460
+ } catch {
461
+ return v;
462
+ }
463
+ }
464
+ return void 0;
465
+ }
466
+ function setCookie(name, value) {
467
+ const d = jar();
468
+ if (!d) return;
469
+ let host = "";
470
+ let secure = false;
471
+ try {
472
+ if (typeof window !== "undefined" && window.location) {
473
+ host = window.location.hostname || "";
474
+ secure = window.location.protocol === "https:";
475
+ }
476
+ } catch {
477
+ }
478
+ const attrs = [
479
+ // encodeURIComponent leaves a UUID byte-identical while making any value that
480
+ // is not one unable to forge a `;` and inject an attribute.
481
+ `${name}=${encodeURIComponent(value)}`,
482
+ "Path=/",
483
+ `Max-Age=${ANON_MAX_AGE_S}`,
484
+ "SameSite=Lax"
485
+ ];
486
+ if (host === ANON_DOMAIN || host.endsWith(`.${ANON_DOMAIN}`)) attrs.push(`Domain=${ANON_DOMAIN}`);
487
+ if (secure) attrs.push("Secure");
488
+ try {
489
+ d.cookie = attrs.join("; ");
490
+ } catch {
491
+ }
492
+ }
493
+ var memAnon;
400
494
  function anonId() {
495
+ if (typeof window === "undefined") return void 0;
401
496
  const s = ls();
402
- if (!s) return void 0;
403
- let v = s.getItem(KEY.anon);
404
- if (!v) {
405
- v = uuidv7();
406
- s.setItem(KEY.anon, v);
497
+ const id = getCookie(KEY.anon) || s?.getItem(KEY.anon) || memAnon || uuidv7();
498
+ memAnon = id;
499
+ setCookie(KEY.anon, id);
500
+ try {
501
+ if (s && s.getItem(KEY.anon) !== id) s.setItem(KEY.anon, id);
502
+ } catch {
407
503
  }
408
- return v;
504
+ return id;
409
505
  }
410
506
  function sessionId(now = Date.now()) {
411
507
  const s = ls();