@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/index.cjs CHANGED
@@ -197,7 +197,47 @@ function redactPAN(s2) {
197
197
  var RE_EMAIL = /[A-Za-z0-9._%+-]{1,64}@[A-Za-z0-9.-]{1,255}\.[A-Za-z]{2,24}/g;
198
198
  var RE_IPV4 = /\b(?:\d{1,3}\.){3}\d{1,3}\b/g;
199
199
  var RE_IPV6 = /\b(?:[0-9A-Fa-f]{1,4}:){2,7}[0-9A-Fa-f]{1,4}\b/g;
200
+ var CREDENTIAL_PARAMS = [
201
+ "code",
202
+ "state",
203
+ "token",
204
+ "access_token",
205
+ "id_token",
206
+ "refresh_token",
207
+ "auth",
208
+ "authorization",
209
+ "secret",
210
+ "client_secret",
211
+ "password",
212
+ "passwd",
213
+ "pwd",
214
+ "api_key",
215
+ "apikey",
216
+ "key",
217
+ "session",
218
+ "session_id",
219
+ "sid",
220
+ "sig",
221
+ "signature",
222
+ "nonce",
223
+ "otp",
224
+ "invite",
225
+ "invitation",
226
+ "reset_token",
227
+ "confirmation_token",
228
+ "magic",
229
+ "ticket",
230
+ "assertion"
231
+ ];
232
+ var RE_CREDENTIAL_PARAM = new RegExp(
233
+ "([?&#;](?:" + CREDENTIAL_PARAMS.join("|") + ")=)[^&#;\\s]{1,4096}",
234
+ "gi"
235
+ );
236
+ function redactCredentialParams(s2) {
237
+ return s2.replace(RE_CREDENTIAL_PARAM, (_m, prefix) => prefix + REDACTED);
238
+ }
200
239
  function redactSecrets(s2) {
240
+ s2 = redactCredentialParams(s2);
201
241
  for (const re of SECRET_PATTERNS) s2 = s2.replace(re, REDACTED);
202
242
  return redactPAN(s2);
203
243
  }
@@ -246,7 +286,7 @@ function uuidv7Time(id) {
246
286
  }
247
287
 
248
288
  // src/version.ts
249
- var VERSION = "0.3.12";
289
+ var VERSION = "0.3.14";
250
290
 
251
291
  // src/sentry.ts
252
292
  var MAX_FRAMES = 50;
@@ -447,6 +487,8 @@ var KEY = {
447
487
  cohort: "hz_cohort"
448
488
  };
449
489
  var SESSION_TTL_MS = 30 * 60 * 1e3;
490
+ var ANON_DOMAIN = "hanzo.ai";
491
+ var ANON_MAX_AGE_S = 2 * 365 * 24 * 60 * 60;
450
492
  function ls() {
451
493
  try {
452
494
  if (typeof window === "undefined" || !window.localStorage) return void 0;
@@ -455,15 +497,69 @@ function ls() {
455
497
  return void 0;
456
498
  }
457
499
  }
500
+ function jar() {
501
+ try {
502
+ if (typeof document === "undefined" || typeof document.cookie !== "string") return void 0;
503
+ return document;
504
+ } catch {
505
+ return void 0;
506
+ }
507
+ }
508
+ function getCookie(name) {
509
+ const d = jar();
510
+ if (!d) return void 0;
511
+ for (const part of d.cookie.split(";")) {
512
+ const eq = part.indexOf("=");
513
+ if (eq < 0 || part.slice(0, eq).trim() !== name) continue;
514
+ const v = part.slice(eq + 1).trim();
515
+ if (!v) continue;
516
+ try {
517
+ return decodeURIComponent(v);
518
+ } catch {
519
+ return v;
520
+ }
521
+ }
522
+ return void 0;
523
+ }
524
+ function setCookie(name, value) {
525
+ const d = jar();
526
+ if (!d) return;
527
+ let host = "";
528
+ let secure = false;
529
+ try {
530
+ if (typeof window !== "undefined" && window.location) {
531
+ host = window.location.hostname || "";
532
+ secure = window.location.protocol === "https:";
533
+ }
534
+ } catch {
535
+ }
536
+ const attrs = [
537
+ // encodeURIComponent leaves a UUID byte-identical while making any value that
538
+ // is not one unable to forge a `;` and inject an attribute.
539
+ `${name}=${encodeURIComponent(value)}`,
540
+ "Path=/",
541
+ `Max-Age=${ANON_MAX_AGE_S}`,
542
+ "SameSite=Lax"
543
+ ];
544
+ if (host === ANON_DOMAIN || host.endsWith(`.${ANON_DOMAIN}`)) attrs.push(`Domain=${ANON_DOMAIN}`);
545
+ if (secure) attrs.push("Secure");
546
+ try {
547
+ d.cookie = attrs.join("; ");
548
+ } catch {
549
+ }
550
+ }
551
+ var memAnon;
458
552
  function anonId() {
553
+ if (typeof window === "undefined") return void 0;
459
554
  const s2 = ls();
460
- if (!s2) return void 0;
461
- let v = s2.getItem(KEY.anon);
462
- if (!v) {
463
- v = uuidv7();
464
- s2.setItem(KEY.anon, v);
555
+ const id = getCookie(KEY.anon) || s2?.getItem(KEY.anon) || memAnon || uuidv7();
556
+ memAnon = id;
557
+ setCookie(KEY.anon, id);
558
+ try {
559
+ if (s2 && s2.getItem(KEY.anon) !== id) s2.setItem(KEY.anon, id);
560
+ } catch {
465
561
  }
466
- return v;
562
+ return id;
467
563
  }
468
564
  function sessionId(now = Date.now()) {
469
565
  const s2 = ls();