@hanzo/event 0.3.26 → 0.3.28
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/{core-DO8tBUy7.d.cts → core-usULsfUB.d.cts} +16 -4
- package/dist/{core-DO8tBUy7.d.ts → core-usULsfUB.d.ts} +16 -4
- package/dist/index.cjs +43 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +43 -5
- package/dist/index.mjs.map +1 -1
- package/dist/react.cjs +45 -10
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.mjs +46 -11
- package/dist/react.mjs.map +1 -1
- package/hz.js +1 -1
- package/package.json +1 -1
- package/src/core.ts +100 -17
- package/src/react.tsx +7 -7
- package/src/stream.test.ts +195 -0
- package/src/version.ts +1 -1
|
@@ -285,11 +285,19 @@ declare class Analytics {
|
|
|
285
285
|
private attribution;
|
|
286
286
|
private cohort;
|
|
287
287
|
private started;
|
|
288
|
+
/** The view pageview() last counted — path + location. */
|
|
289
|
+
private counted?;
|
|
288
290
|
/** Parsed error-plane DSN, or null when the plane is inert. */
|
|
289
291
|
private dsn;
|
|
290
292
|
/** Guards against an error thrown *inside* the error path re-entering it. */
|
|
291
293
|
private reentrant;
|
|
292
294
|
constructor(config: AnalyticsConfig);
|
|
295
|
+
/** adopt gives this client a credential it does not have. The key belongs to
|
|
296
|
+
* the stream, not to whichever caller happened to ask for the handle first,
|
|
297
|
+
* so a later caller carrying one hands it over. The error plane derives from
|
|
298
|
+
* the key, so it comes up here too when it was inert for want of one.
|
|
299
|
+
* Present fields are never overwritten: the first caller's key stays. */
|
|
300
|
+
adopt(config: AnalyticsConfig): void;
|
|
293
301
|
/** errorPlaneEnabled reports whether captured exceptions can actually reach the
|
|
294
302
|
* error host. False means a DSN was never configured — the documented
|
|
295
303
|
* fail-safe. Exposed so an app (or a test) can assert its wiring instead of
|
|
@@ -308,7 +316,9 @@ declare class Analytics {
|
|
|
308
316
|
/** group associates the visitor with an org/team (analytics grouping, not the
|
|
309
317
|
* server tenant — the server still derives tenant from the session). */
|
|
310
318
|
group(groupId: string, traits?: Record<string, unknown>): void;
|
|
311
|
-
/** pageview records a $pageview for the current (or given) location
|
|
319
|
+
/** pageview records a $pageview for the current (or given) location, once per
|
|
320
|
+
* view. A view is the path plus the full location, so a query or hash change
|
|
321
|
+
* is a new one and a repeat call for the same place is not. */
|
|
312
322
|
pageview(path?: string, properties?: Record<string, unknown>): void;
|
|
313
323
|
/** capture records a named product event with optional properties. Commerce
|
|
314
324
|
* fields (productId/quantity/revenue/currency) may be passed for order events. */
|
|
@@ -339,8 +349,8 @@ declare class Analytics {
|
|
|
339
349
|
* front door POST /v1/event, body { batch: [Event…] }. beacon=true selects the
|
|
340
350
|
* unload-safe transport. Auth is orthogonal to the wire:
|
|
341
351
|
*
|
|
342
|
-
* • publishable key set → rides
|
|
343
|
-
*
|
|
352
|
+
* • publishable key set → rides ?ingest_key=pk-… on both sends, keeping each
|
|
353
|
+
* a CORS-simple request that any origin may send.
|
|
344
354
|
* • else a bearer JWT rides Authorization (fetch only — sendBeacon cannot
|
|
345
355
|
* carry a header, so token apps fall back to keepalive fetch on unload).
|
|
346
356
|
* • else a cookie app rides same-origin credentials (beacon carries the
|
|
@@ -362,7 +372,9 @@ declare class Analytics {
|
|
|
362
372
|
private schedule;
|
|
363
373
|
private clearTimer;
|
|
364
374
|
}
|
|
365
|
-
/** createAnalytics
|
|
375
|
+
/** createAnalytics returns the client for a stream, building it on first ask.
|
|
376
|
+
* This is the ONE way to get a client: `new Analytics` bypasses the registry
|
|
377
|
+
* and is for tests and for a deliberately separate instance. */
|
|
366
378
|
declare function createAnalytics(config: AnalyticsConfig): Analytics;
|
|
367
379
|
|
|
368
380
|
export { type Attribution as A, type Cohort as C, type Dsn as D, type ExceptionEntry as E, type SentryEvent as S, type Transport as T, type WireEvent as W, type CaptureErrorOptions as a, type SentryFrame as b, type SentryLevel as c, type ExceptionProperties as d, Analytics as e, type AnalyticsConfig as f, type EventKind as g, type Exception as h, type ExceptionFrame as i, createAnalytics as j };
|
|
@@ -285,11 +285,19 @@ declare class Analytics {
|
|
|
285
285
|
private attribution;
|
|
286
286
|
private cohort;
|
|
287
287
|
private started;
|
|
288
|
+
/** The view pageview() last counted — path + location. */
|
|
289
|
+
private counted?;
|
|
288
290
|
/** Parsed error-plane DSN, or null when the plane is inert. */
|
|
289
291
|
private dsn;
|
|
290
292
|
/** Guards against an error thrown *inside* the error path re-entering it. */
|
|
291
293
|
private reentrant;
|
|
292
294
|
constructor(config: AnalyticsConfig);
|
|
295
|
+
/** adopt gives this client a credential it does not have. The key belongs to
|
|
296
|
+
* the stream, not to whichever caller happened to ask for the handle first,
|
|
297
|
+
* so a later caller carrying one hands it over. The error plane derives from
|
|
298
|
+
* the key, so it comes up here too when it was inert for want of one.
|
|
299
|
+
* Present fields are never overwritten: the first caller's key stays. */
|
|
300
|
+
adopt(config: AnalyticsConfig): void;
|
|
293
301
|
/** errorPlaneEnabled reports whether captured exceptions can actually reach the
|
|
294
302
|
* error host. False means a DSN was never configured — the documented
|
|
295
303
|
* fail-safe. Exposed so an app (or a test) can assert its wiring instead of
|
|
@@ -308,7 +316,9 @@ declare class Analytics {
|
|
|
308
316
|
/** group associates the visitor with an org/team (analytics grouping, not the
|
|
309
317
|
* server tenant — the server still derives tenant from the session). */
|
|
310
318
|
group(groupId: string, traits?: Record<string, unknown>): void;
|
|
311
|
-
/** pageview records a $pageview for the current (or given) location
|
|
319
|
+
/** pageview records a $pageview for the current (or given) location, once per
|
|
320
|
+
* view. A view is the path plus the full location, so a query or hash change
|
|
321
|
+
* is a new one and a repeat call for the same place is not. */
|
|
312
322
|
pageview(path?: string, properties?: Record<string, unknown>): void;
|
|
313
323
|
/** capture records a named product event with optional properties. Commerce
|
|
314
324
|
* fields (productId/quantity/revenue/currency) may be passed for order events. */
|
|
@@ -339,8 +349,8 @@ declare class Analytics {
|
|
|
339
349
|
* front door POST /v1/event, body { batch: [Event…] }. beacon=true selects the
|
|
340
350
|
* unload-safe transport. Auth is orthogonal to the wire:
|
|
341
351
|
*
|
|
342
|
-
* • publishable key set → rides
|
|
343
|
-
*
|
|
352
|
+
* • publishable key set → rides ?ingest_key=pk-… on both sends, keeping each
|
|
353
|
+
* a CORS-simple request that any origin may send.
|
|
344
354
|
* • else a bearer JWT rides Authorization (fetch only — sendBeacon cannot
|
|
345
355
|
* carry a header, so token apps fall back to keepalive fetch on unload).
|
|
346
356
|
* • else a cookie app rides same-origin credentials (beacon carries the
|
|
@@ -362,7 +372,9 @@ declare class Analytics {
|
|
|
362
372
|
private schedule;
|
|
363
373
|
private clearTimer;
|
|
364
374
|
}
|
|
365
|
-
/** createAnalytics
|
|
375
|
+
/** createAnalytics returns the client for a stream, building it on first ask.
|
|
376
|
+
* This is the ONE way to get a client: `new Analytics` bypasses the registry
|
|
377
|
+
* and is for tests and for a deliberately separate instance. */
|
|
366
378
|
declare function createAnalytics(config: AnalyticsConfig): Analytics;
|
|
367
379
|
|
|
368
380
|
export { type Attribution as A, type Cohort as C, type Dsn as D, type ExceptionEntry as E, type SentryEvent as S, type Transport as T, type WireEvent as W, type CaptureErrorOptions as a, type SentryFrame as b, type SentryLevel as c, type ExceptionProperties as d, Analytics as e, type AnalyticsConfig as f, type EventKind as g, type Exception as h, type ExceptionFrame as i, createAnalytics as j };
|
package/dist/index.cjs
CHANGED
|
@@ -319,7 +319,7 @@ function uuidv7Time(id) {
|
|
|
319
319
|
}
|
|
320
320
|
|
|
321
321
|
// src/version.ts
|
|
322
|
-
var VERSION = "0.3.
|
|
322
|
+
var VERSION = "0.3.28";
|
|
323
323
|
|
|
324
324
|
// src/sentry.ts
|
|
325
325
|
var MAX_FRAMES = 50;
|
|
@@ -796,6 +796,20 @@ var Analytics = class {
|
|
|
796
796
|
config.dsn ?? readEnvDsn() ?? dsnForProduct(this.cfg.product, this.cfg.ingestKey)
|
|
797
797
|
);
|
|
798
798
|
}
|
|
799
|
+
/** adopt gives this client a credential it does not have. The key belongs to
|
|
800
|
+
* the stream, not to whichever caller happened to ask for the handle first,
|
|
801
|
+
* so a later caller carrying one hands it over. The error plane derives from
|
|
802
|
+
* the key, so it comes up here too when it was inert for want of one.
|
|
803
|
+
* Present fields are never overwritten: the first caller's key stays. */
|
|
804
|
+
adopt(config) {
|
|
805
|
+
if (config.ingestKey && !this.cfg.ingestKey) this.cfg.ingestKey = config.ingestKey;
|
|
806
|
+
if (config.getToken && !this.cfg.getToken) this.cfg.getToken = config.getToken;
|
|
807
|
+
if (!this.dsn) {
|
|
808
|
+
this.dsn = parseDsn(
|
|
809
|
+
config.dsn ?? readEnvDsn() ?? dsnForProduct(this.cfg.product, this.cfg.ingestKey)
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
799
813
|
/** errorPlaneEnabled reports whether captured exceptions can actually reach the
|
|
800
814
|
* error host. False means a DSN was never configured — the documented
|
|
801
815
|
* fail-safe. Exposed so an app (or a test) can assert its wiring instead of
|
|
@@ -846,9 +860,14 @@ var Analytics = class {
|
|
|
846
860
|
group(groupId, traits) {
|
|
847
861
|
this.enqueue("group", void 0, { groupId, properties: traits });
|
|
848
862
|
}
|
|
849
|
-
/** pageview records a $pageview for the current (or given) location
|
|
863
|
+
/** pageview records a $pageview for the current (or given) location, once per
|
|
864
|
+
* view. A view is the path plus the full location, so a query or hash change
|
|
865
|
+
* is a new one and a repeat call for the same place is not. */
|
|
850
866
|
pageview(path, properties) {
|
|
851
867
|
const p = path ?? (isBrowser() ? window.location.pathname : void 0);
|
|
868
|
+
const view = (p ?? "") + "\0" + (isBrowser() ? window.location.href : "");
|
|
869
|
+
if (view === this.counted) return;
|
|
870
|
+
this.counted = view;
|
|
852
871
|
this.enqueue("pageview", events.PAGEVIEW, { path: p, properties });
|
|
853
872
|
}
|
|
854
873
|
/** capture records a named product event with optional properties. Commerce
|
|
@@ -909,8 +928,8 @@ var Analytics = class {
|
|
|
909
928
|
* front door POST /v1/event, body { batch: [Event…] }. beacon=true selects the
|
|
910
929
|
* unload-safe transport. Auth is orthogonal to the wire:
|
|
911
930
|
*
|
|
912
|
-
* • publishable key set → rides
|
|
913
|
-
*
|
|
931
|
+
* • publishable key set → rides ?ingest_key=pk-… on both sends, keeping each
|
|
932
|
+
* a CORS-simple request that any origin may send.
|
|
914
933
|
* • else a bearer JWT rides Authorization (fetch only — sendBeacon cannot
|
|
915
934
|
* carry a header, so token apps fall back to keepalive fetch on unload).
|
|
916
935
|
* • else a cookie app rides same-origin credentials (beacon carries the
|
|
@@ -1033,8 +1052,27 @@ var Analytics = class {
|
|
|
1033
1052
|
}
|
|
1034
1053
|
}
|
|
1035
1054
|
};
|
|
1055
|
+
var CLIENTS = /* @__PURE__ */ Symbol.for("hanzo.event.clients");
|
|
1056
|
+
function registry() {
|
|
1057
|
+
const g = globalThis;
|
|
1058
|
+
const existing = g[CLIENTS];
|
|
1059
|
+
if (existing) return existing;
|
|
1060
|
+
const fresh = /* @__PURE__ */ new Map();
|
|
1061
|
+
g[CLIENTS] = fresh;
|
|
1062
|
+
return fresh;
|
|
1063
|
+
}
|
|
1036
1064
|
function createAnalytics(config) {
|
|
1037
|
-
return new Analytics(config);
|
|
1065
|
+
if (!isBrowser() || config.enabled === false) return new Analytics(config);
|
|
1066
|
+
const key = (config.host ?? DEFAULT_HOST) + "\0" + config.product;
|
|
1067
|
+
const clients = registry();
|
|
1068
|
+
const existing = clients.get(key);
|
|
1069
|
+
if (existing) {
|
|
1070
|
+
existing.adopt(config);
|
|
1071
|
+
return existing;
|
|
1072
|
+
}
|
|
1073
|
+
const fresh = new Analytics(config);
|
|
1074
|
+
clients.set(key, fresh);
|
|
1075
|
+
return fresh;
|
|
1038
1076
|
}
|
|
1039
1077
|
|
|
1040
1078
|
// src/goals.ts
|