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