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