@hanzo/event 0.3.8 → 0.3.9
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 +33 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.mjs +32 -20
- package/dist/index.mjs.map +1 -1
- package/dist/react.cjs +28 -19
- package/dist/react.cjs.map +1 -1
- package/dist/react.mjs +28 -19
- package/dist/react.mjs.map +1 -1
- package/hz.js +26 -5
- package/package.json +1 -1
- package/src/core.ts +2 -7
- package/src/hz.test.ts +96 -0
- package/src/index.ts +1 -0
- package/src/sentry.ts +4 -6
- package/src/storage.ts +11 -9
- package/src/uid.test.ts +73 -0
- package/src/uid.ts +70 -0
- package/src/version.ts +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -6,7 +6,7 @@ declare function getFirstTouch(): Attribution | undefined;
|
|
|
6
6
|
/** Read persisted cohort dimensions. */
|
|
7
7
|
declare function getCohort(): Cohort | undefined;
|
|
8
8
|
|
|
9
|
-
declare const VERSION = "0.3.
|
|
9
|
+
declare const VERSION = "0.3.9";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* parseDsn parses "https://<version>:<hmac>@<host>/v1/sentry/<projectId>" into its
|
|
@@ -60,6 +60,16 @@ declare function buildSentryEvent(input: BuildEventInput): SentryEvent;
|
|
|
60
60
|
*/
|
|
61
61
|
declare function buildEnvelope(event: SentryEvent, dsn: Dsn, sentAt?: string): string;
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* uuidv7 mints a time-ordered UUIDv7 for `now` (epoch milliseconds).
|
|
65
|
+
*
|
|
66
|
+
* Two ids minted in the same millisecond sort arbitrarily between themselves; ids
|
|
67
|
+
* from different milliseconds sort by time, lexically and numerically alike.
|
|
68
|
+
*/
|
|
69
|
+
declare function uuidv7(now?: number): string;
|
|
70
|
+
/** The millisecond timestamp a v7 id was minted at — the inverse of uuidv7. */
|
|
71
|
+
declare function uuidv7Time(id: string): number;
|
|
72
|
+
|
|
63
73
|
/**
|
|
64
74
|
* The product → Sentry DSN registry.
|
|
65
75
|
*
|
|
@@ -273,4 +283,4 @@ declare function hasAttribution(a: Attribution): boolean;
|
|
|
273
283
|
/** isoWeek returns the ISO-8601 week label, e.g. "2026-W28". */
|
|
274
284
|
declare function isoWeek(d: Date): string;
|
|
275
285
|
|
|
276
|
-
export { Attribution, COHORTS, CaptureErrorOptions, Cohort, type CohortDef, Dsn, EVENTS, type ErrorIdentity, type EventName, FUNNELS, type FunnelDef, type FunnelId, type FunnelStep, GOALS, type GoalDef, PAGEVIEW, PRODUCTS, PRODUCT_DSN, type ProductId, SentryEvent, SentryFrame, VERSION, buildEnvelope, buildSentryEvent, deriveChannel, dsnForProduct, eventsOf, framesFromStack, getCohort, getFirstTouch, hasAttribution, hostOf, isoWeek, parseAttribution, parseDsn, redactSecrets, scrubPII, scrubText };
|
|
286
|
+
export { Attribution, COHORTS, CaptureErrorOptions, Cohort, type CohortDef, Dsn, EVENTS, type ErrorIdentity, type EventName, FUNNELS, type FunnelDef, type FunnelId, type FunnelStep, GOALS, type GoalDef, PAGEVIEW, PRODUCTS, PRODUCT_DSN, type ProductId, SentryEvent, SentryFrame, VERSION, buildEnvelope, buildSentryEvent, deriveChannel, dsnForProduct, eventsOf, framesFromStack, getCohort, getFirstTouch, hasAttribution, hostOf, isoWeek, parseAttribution, parseDsn, redactSecrets, scrubPII, scrubText, uuidv7, uuidv7Time };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ declare function getFirstTouch(): Attribution | undefined;
|
|
|
6
6
|
/** Read persisted cohort dimensions. */
|
|
7
7
|
declare function getCohort(): Cohort | undefined;
|
|
8
8
|
|
|
9
|
-
declare const VERSION = "0.3.
|
|
9
|
+
declare const VERSION = "0.3.9";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* parseDsn parses "https://<version>:<hmac>@<host>/v1/sentry/<projectId>" into its
|
|
@@ -60,6 +60,16 @@ declare function buildSentryEvent(input: BuildEventInput): SentryEvent;
|
|
|
60
60
|
*/
|
|
61
61
|
declare function buildEnvelope(event: SentryEvent, dsn: Dsn, sentAt?: string): string;
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* uuidv7 mints a time-ordered UUIDv7 for `now` (epoch milliseconds).
|
|
65
|
+
*
|
|
66
|
+
* Two ids minted in the same millisecond sort arbitrarily between themselves; ids
|
|
67
|
+
* from different milliseconds sort by time, lexically and numerically alike.
|
|
68
|
+
*/
|
|
69
|
+
declare function uuidv7(now?: number): string;
|
|
70
|
+
/** The millisecond timestamp a v7 id was minted at — the inverse of uuidv7. */
|
|
71
|
+
declare function uuidv7Time(id: string): number;
|
|
72
|
+
|
|
63
73
|
/**
|
|
64
74
|
* The product → Sentry DSN registry.
|
|
65
75
|
*
|
|
@@ -273,4 +283,4 @@ declare function hasAttribution(a: Attribution): boolean;
|
|
|
273
283
|
/** isoWeek returns the ISO-8601 week label, e.g. "2026-W28". */
|
|
274
284
|
declare function isoWeek(d: Date): string;
|
|
275
285
|
|
|
276
|
-
export { Attribution, COHORTS, CaptureErrorOptions, Cohort, type CohortDef, Dsn, EVENTS, type ErrorIdentity, type EventName, FUNNELS, type FunnelDef, type FunnelId, type FunnelStep, GOALS, type GoalDef, PAGEVIEW, PRODUCTS, PRODUCT_DSN, type ProductId, SentryEvent, SentryFrame, VERSION, buildEnvelope, buildSentryEvent, deriveChannel, dsnForProduct, eventsOf, framesFromStack, getCohort, getFirstTouch, hasAttribution, hostOf, isoWeek, parseAttribution, parseDsn, redactSecrets, scrubPII, scrubText };
|
|
286
|
+
export { Attribution, COHORTS, CaptureErrorOptions, Cohort, type CohortDef, Dsn, EVENTS, type ErrorIdentity, type EventName, FUNNELS, type FunnelDef, type FunnelId, type FunnelStep, GOALS, type GoalDef, PAGEVIEW, PRODUCTS, PRODUCT_DSN, type ProductId, SentryEvent, SentryFrame, VERSION, buildEnvelope, buildSentryEvent, deriveChannel, dsnForProduct, eventsOf, framesFromStack, getCohort, getFirstTouch, hasAttribution, hostOf, isoWeek, parseAttribution, parseDsn, redactSecrets, scrubPII, scrubText, uuidv7, uuidv7Time };
|
package/dist/index.mjs
CHANGED
|
@@ -217,8 +217,34 @@ function scrubText(s2, capturePII = false) {
|
|
|
217
217
|
return s2;
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
// src/uid.ts
|
|
221
|
+
var HEX = Array.from({ length: 256 }, (_, i) => (i + 256).toString(16).slice(1));
|
|
222
|
+
function fill(b) {
|
|
223
|
+
const c = typeof crypto !== "undefined" ? crypto : void 0;
|
|
224
|
+
if (c && typeof c.getRandomValues === "function") {
|
|
225
|
+
c.getRandomValues(b);
|
|
226
|
+
return b;
|
|
227
|
+
}
|
|
228
|
+
for (let i = 0; i < b.length; i++) b[i] = Math.random() * 256 | 0;
|
|
229
|
+
return b;
|
|
230
|
+
}
|
|
231
|
+
function uuidv7(now = Date.now()) {
|
|
232
|
+
const b = fill(new Uint8Array(16));
|
|
233
|
+
let t = Math.floor(now);
|
|
234
|
+
for (let i = 5; i >= 0; i--) {
|
|
235
|
+
b[i] = t % 256;
|
|
236
|
+
t = Math.floor(t / 256);
|
|
237
|
+
}
|
|
238
|
+
b[6] = 112 | b[6] & 15;
|
|
239
|
+
b[8] = 128 | b[8] & 63;
|
|
240
|
+
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]];
|
|
241
|
+
}
|
|
242
|
+
function uuidv7Time(id) {
|
|
243
|
+
return parseInt(id.slice(0, 8) + id.slice(9, 13), 16);
|
|
244
|
+
}
|
|
245
|
+
|
|
220
246
|
// src/version.ts
|
|
221
|
-
var VERSION = "0.3.
|
|
247
|
+
var VERSION = "0.3.9";
|
|
222
248
|
|
|
223
249
|
// src/sentry.ts
|
|
224
250
|
var MAX_FRAMES = 50;
|
|
@@ -227,11 +253,7 @@ var MAX_LINE_LEN = 2048;
|
|
|
227
253
|
var MAX_TAG_LEN = 1024;
|
|
228
254
|
var MAX_TAGS = 50;
|
|
229
255
|
function eventId() {
|
|
230
|
-
|
|
231
|
-
if (c && "randomUUID" in c) return c.randomUUID().replace(/-/g, "");
|
|
232
|
-
let s2 = "";
|
|
233
|
-
for (let i = 0; i < 32; i++) s2 += Math.floor(Math.random() * 16).toString(16);
|
|
234
|
-
return s2;
|
|
256
|
+
return uuidv7().replace(/-/g, "");
|
|
235
257
|
}
|
|
236
258
|
function byteLen(s2) {
|
|
237
259
|
if (typeof TextEncoder !== "undefined") return new TextEncoder().encode(s2).length;
|
|
@@ -431,17 +453,12 @@ function ls() {
|
|
|
431
453
|
return void 0;
|
|
432
454
|
}
|
|
433
455
|
}
|
|
434
|
-
function uid() {
|
|
435
|
-
const c = typeof crypto !== "undefined" ? crypto : void 0;
|
|
436
|
-
if (c && "randomUUID" in c) return c.randomUUID();
|
|
437
|
-
return "a-" + Date.now().toString(36) + Math.random().toString(36).slice(2, 10);
|
|
438
|
-
}
|
|
439
456
|
function anonId() {
|
|
440
457
|
const s2 = ls();
|
|
441
458
|
if (!s2) return void 0;
|
|
442
459
|
let v = s2.getItem(KEY.anon);
|
|
443
460
|
if (!v) {
|
|
444
|
-
v =
|
|
461
|
+
v = uuidv7();
|
|
445
462
|
s2.setItem(KEY.anon, v);
|
|
446
463
|
}
|
|
447
464
|
return v;
|
|
@@ -456,7 +473,7 @@ function sessionId(now = Date.now()) {
|
|
|
456
473
|
state = null;
|
|
457
474
|
}
|
|
458
475
|
if (!state || now - state.last > SESSION_TTL_MS) {
|
|
459
|
-
state = { id:
|
|
476
|
+
state = { id: uuidv7(now), last: now };
|
|
460
477
|
} else {
|
|
461
478
|
state.last = now;
|
|
462
479
|
}
|
|
@@ -525,11 +542,6 @@ function readEnv(name) {
|
|
|
525
542
|
function appendQuery(url, key, value) {
|
|
526
543
|
return url + (url.includes("?") ? "&" : "?") + key + "=" + encodeURIComponent(value);
|
|
527
544
|
}
|
|
528
|
-
function uid2() {
|
|
529
|
-
const c = typeof crypto !== "undefined" ? crypto : void 0;
|
|
530
|
-
if (c && "randomUUID" in c) return c.randomUUID();
|
|
531
|
-
return "m-" + Date.now().toString(36) + Math.random().toString(36).slice(2, 10);
|
|
532
|
-
}
|
|
533
545
|
function normalizeError2(err) {
|
|
534
546
|
const n = normalizeError(err);
|
|
535
547
|
return { type: n.name, message: n.message, stack: n.stack };
|
|
@@ -781,7 +793,7 @@ var Analytics = class {
|
|
|
781
793
|
build(kind, event, extra) {
|
|
782
794
|
const anon = anonId();
|
|
783
795
|
const wire = {
|
|
784
|
-
messageId:
|
|
796
|
+
messageId: uuidv7(),
|
|
785
797
|
type: kind,
|
|
786
798
|
event,
|
|
787
799
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -978,6 +990,6 @@ var COHORTS = {
|
|
|
978
990
|
refCode: { field: "ref_code", label: "Referral code" }
|
|
979
991
|
};
|
|
980
992
|
|
|
981
|
-
export { Analytics, COHORTS, EVENTS, FUNNELS, GOALS, PAGEVIEW, PRODUCTS, PRODUCT_DSN, VERSION, buildEnvelope, buildSentryEvent, createAnalytics, deriveChannel, dsnForProduct, eventsOf, framesFromStack, getCohort, getFirstTouch, hasAttribution, hostOf, isoWeek, parseAttribution, parseDsn, redactSecrets, scrubPII, scrubText };
|
|
993
|
+
export { Analytics, COHORTS, EVENTS, FUNNELS, GOALS, PAGEVIEW, PRODUCTS, PRODUCT_DSN, VERSION, buildEnvelope, buildSentryEvent, createAnalytics, deriveChannel, dsnForProduct, eventsOf, framesFromStack, getCohort, getFirstTouch, hasAttribution, hostOf, isoWeek, parseAttribution, parseDsn, redactSecrets, scrubPII, scrubText, uuidv7, uuidv7Time };
|
|
982
994
|
//# sourceMappingURL=index.mjs.map
|
|
983
995
|
//# sourceMappingURL=index.mjs.map
|