@krak-stack/registry 0.1.53 → 0.1.55

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.
@@ -3,6 +3,16 @@ import { Effect as Effect2, Option as Option2, Schema as Schema3 } from "effect"
3
3
 
4
4
  // ../../src/services/opentelemetry/schema.ts
5
5
  import { Schema } from "effect";
6
+ var BrowserAnalyticsPreference = Schema.Struct({
7
+ version: Schema.String,
8
+ choice: Schema.Literals(["accepted", "declined"]),
9
+ revision: Schema.String,
10
+ issuedAt: Schema.Finite,
11
+ expiresAt: Schema.Finite
12
+ }).annotate({ identifier: "BrowserAnalyticsPreference" });
13
+ var BrowserPrivacySignals = Schema.Struct({
14
+ globalPrivacyControl: Schema.optional(Schema.Boolean)
15
+ }).annotate({ identifier: "BrowserPrivacySignals" });
6
16
  var BrowserWebVital = Schema.Struct({
7
17
  name: Schema.Literals(["LCP", "INP", "CLS", "FCP", "TTFB"]),
8
18
  id: Schema.NonEmptyString.check(Schema.isMaxLength(64)),
@@ -219,10 +229,16 @@ var TrackEvent = Schema3.Union([
219
229
  target: AuditTarget
220
230
  })
221
231
  ]).annotate({ identifier: "TrackEvent" });
222
- var ListAudit = Schema3.Struct({
232
+ var EventQuery = Schema3.Struct({
233
+ ...Query.fields,
234
+ eventName: Schema3.optional(trackEventFields.name)
235
+ }).annotate({ identifier: "EventQuery" });
236
+ var EventQueryStandard = Schema3.toStandardSchemaV1(EventQuery);
237
+ var ListEvents = Schema3.Struct({
223
238
  organizationId: Schema3.NonEmptyString,
224
- ...Query.fields
225
- }).annotate({ identifier: "ListAudit" });
239
+ category: Schema3.Literals(["audit", "analytics"]),
240
+ ...EventQuery.fields
241
+ }).annotate({ identifier: "ListEvents" });
226
242
  var AuditSortId = Schema3.Literals([
227
243
  "time",
228
244
  "eventName",
@@ -344,12 +360,14 @@ export {
344
360
  EventIdentity,
345
361
  EventIpAddress,
346
362
  EventLogRecord,
363
+ EventQuery,
364
+ EventQueryStandard,
347
365
  EventRegion,
348
366
  EventSource,
349
367
  EventUuid,
350
368
  EventsPersistenceError,
351
369
  ExistingEventRequest,
352
- ListAudit,
370
+ ListEvents,
353
371
  OtlpLogs,
354
372
  RequestActorAttribution,
355
373
  StoredEventId,
@@ -40,6 +40,16 @@ import {
40
40
 
41
41
  // ../../src/services/opentelemetry/schema.ts
42
42
  import { Schema } from "effect";
43
+ var BrowserAnalyticsPreference = Schema.Struct({
44
+ version: Schema.String,
45
+ choice: Schema.Literals(["accepted", "declined"]),
46
+ revision: Schema.String,
47
+ issuedAt: Schema.Finite,
48
+ expiresAt: Schema.Finite
49
+ }).annotate({ identifier: "BrowserAnalyticsPreference" });
50
+ var BrowserPrivacySignals = Schema.Struct({
51
+ globalPrivacyControl: Schema.optional(Schema.Boolean)
52
+ }).annotate({ identifier: "BrowserPrivacySignals" });
43
53
  var BrowserWebVital = Schema.Struct({
44
54
  name: Schema.Literals(["LCP", "INP", "CLS", "FCP", "TTFB"]),
45
55
  id: Schema.NonEmptyString.check(Schema.isMaxLength(64)),
@@ -89,7 +99,9 @@ class OtlpEvents extends Context.Service()("krakstack/opentelemetry/Events") {
89
99
  label: "OtlpEvents",
90
100
  body: (logRecords) => {
91
101
  const scopes = new Map;
92
- for (const { scopeName, ...record } of logRecords) {
102
+ for (const { scopeName, canExport, ...record } of logRecords) {
103
+ if (canExport && !canExport())
104
+ continue;
93
105
  const name = scopeName ?? options.scopeName ?? "krakstack.events";
94
106
  const records = scopes.get(name);
95
107
  if (records)
@@ -2,6 +2,14 @@ import { Effect, Layer, Schema } from "effect";
2
2
  import { type Otlp, OtlpExporter, OtlpLogger, OtlpMetrics, OtlpTracer } from "effect/observability";
3
3
  import { OtlpEvents, type EventExportOptions } from "./events.js";
4
4
  export type { EventAttributes, EventOptions } from "./schema.js";
5
+ /** Essential diagnostics omit arbitrary messages, functions, URL queries and directories. */
6
+ export declare const sanitizeBrowserException: (input: {
7
+ readonly type: string;
8
+ readonly stack?: string;
9
+ }) => {
10
+ message: string;
11
+ stack: string | undefined;
12
+ };
5
13
  type OtlpOptions = Parameters<typeof Otlp.layerJson>[0];
6
14
  type SignalOptions<Options> = Omit<Options, "url" | "resource" | "headers">;
7
15
  export interface BrowserOtlpOptions {
@@ -28,6 +28,16 @@ import {
28
28
 
29
29
  // ../../src/services/opentelemetry/schema.ts
30
30
  import { Schema } from "effect";
31
+ var BrowserAnalyticsPreference = Schema.Struct({
32
+ version: Schema.String,
33
+ choice: Schema.Literals(["accepted", "declined"]),
34
+ revision: Schema.String,
35
+ issuedAt: Schema.Finite,
36
+ expiresAt: Schema.Finite
37
+ }).annotate({ identifier: "BrowserAnalyticsPreference" });
38
+ var BrowserPrivacySignals = Schema.Struct({
39
+ globalPrivacyControl: Schema.optional(Schema.Boolean)
40
+ }).annotate({ identifier: "BrowserPrivacySignals" });
31
41
  var BrowserWebVital = Schema.Struct({
32
42
  name: Schema.Literals(["LCP", "INP", "CLS", "FCP", "TTFB"]),
33
43
  id: Schema.NonEmptyString.check(Schema.isMaxLength(64)),
@@ -77,7 +87,9 @@ class OtlpEvents extends Context.Service()("krakstack/opentelemetry/Events") {
77
87
  label: "OtlpEvents",
78
88
  body: (logRecords) => {
79
89
  const scopes = new Map;
80
- for (const { scopeName, ...record } of logRecords) {
90
+ for (const { scopeName, canExport, ...record } of logRecords) {
91
+ if (canExport && !canExport())
92
+ continue;
81
93
  const name = scopeName ?? options.scopeName ?? "krakstack.events";
82
94
  const records = scopes.get(name);
83
95
  if (records)
@@ -146,15 +158,27 @@ class BrowserReportedError extends Schema3.TaggedError()("BrowserReportedError",
146
158
  stack: Schema3.optional(Schema3.String)
147
159
  }) {
148
160
  }
149
- var reportBrowserException = (exception) => Effect2.fail(exception).pipe(Effect2.withSpan("browser.exception", {
150
- root: true,
151
- sampled: true,
152
- attributes: {
153
- "exception.type": exception.type,
154
- "exception.message": exception.message,
155
- "exception.stacktrace": exception.stack ?? ""
156
- }
157
- }), Effect2.ignoreCause);
161
+ var reportBrowserException = (exception) => {
162
+ const sanitized = sanitizeBrowserException(exception);
163
+ return Effect2.fail(new BrowserReportedError({ type: exception.type, ...sanitized })).pipe(Effect2.withSpan("browser.exception", {
164
+ root: true,
165
+ sampled: true,
166
+ attributes: {
167
+ "exception.type": exception.type,
168
+ "exception.message": sanitized.message,
169
+ "exception.stacktrace": sanitized.stack ?? ""
170
+ }
171
+ }), Effect2.ignoreCause);
172
+ };
173
+ var sanitizeBrowserException = (input) => ({
174
+ message: input.type === "window.error" ? "Browser error" : "Unhandled promise rejection",
175
+ stack: input.stack?.split(`
176
+ `).slice(1, 21).flatMap((line) => {
177
+ const match = line.match(/([a-zA-Z0-9_.-]+\.(?:m?js|tsx?)):(\d+):(\d+)/);
178
+ return match ? [`${match[1]}:${match[2]}:${match[3]}`] : [];
179
+ }).join(`
180
+ `)
181
+ });
158
182
  var BrowserExceptionTrackingLive = Layer2.effectDiscard(Stream.merge(Stream.fromEventListener(globalThis, "error", {
159
183
  bufferSize: 100
160
184
  }).pipe(Stream.map((event) => {
@@ -246,5 +270,6 @@ class BrowserOtlp {
246
270
  };
247
271
  }
248
272
  export {
249
- BrowserOtlp
273
+ BrowserOtlp,
274
+ sanitizeBrowserException
250
275
  };
@@ -0,0 +1,21 @@
1
+ export declare const ANALYTICS_CONSENT_COOKIE = "krakstack_analytics_consent";
2
+ export declare const ANALYTICS_NOTICE_VERSION = "1";
3
+ export declare const analyticsPreference: (cookie: string, now?: number) => {
4
+ readonly version: string;
5
+ readonly choice: "accepted" | "declined";
6
+ readonly revision: string;
7
+ readonly issuedAt: number;
8
+ readonly expiresAt: number;
9
+ } | undefined;
10
+ /** Server-side check; request headers are opt-out signals, never proof of consent. */
11
+ export declare const hasAnalyticsConsent: (cookie: string, headers?: Readonly<Record<string, string | undefined>>) => boolean;
12
+ export declare const browserPrivacyEnabled: () => boolean;
13
+ export declare const analyticsConsentSnapshot: () => string;
14
+ export declare const analyticsAllowed: () => boolean;
15
+ /** Document-wide measurements require acceptance before navigation began. */
16
+ export declare const analyticsAcceptedBefore: (timestamp: number) => boolean;
17
+ /** A queued event is invalid forever if consent changes before export. */
18
+ export declare const analyticsExportGuard: () => () => boolean;
19
+ export declare const saveAnalyticsPreference: (choice: "accepted" | "declined") => boolean;
20
+ /** Polling covers cross-tab cookie changes, expiry and browser signal changes. */
21
+ export declare const subscribeAnalyticsConsent: (listener: () => void) => () => void;
@@ -13,6 +13,8 @@ export declare class OtlpEvents extends OtlpEvents_base {
13
13
  static readonly layer: (options: ExporterOptions) => Layer.Layer<OtlpEvents, never, OtlpExporter.Flusher | import("effect/http/HttpClient").HttpClient | OtlpSerialization.OtlpSerialization>;
14
14
  }
15
15
  interface EventRecord {
16
+ /** Local-only revocation check; never serialized into OTLP. */
17
+ readonly canExport?: () => boolean;
16
18
  readonly scopeName?: string;
17
19
  readonly eventName: string;
18
20
  readonly timeUnixNano: string;
@@ -27,6 +27,16 @@ import {
27
27
 
28
28
  // ../../src/services/opentelemetry/schema.ts
29
29
  import { Schema } from "effect";
30
+ var BrowserAnalyticsPreference = Schema.Struct({
31
+ version: Schema.String,
32
+ choice: Schema.Literals(["accepted", "declined"]),
33
+ revision: Schema.String,
34
+ issuedAt: Schema.Finite,
35
+ expiresAt: Schema.Finite
36
+ }).annotate({ identifier: "BrowserAnalyticsPreference" });
37
+ var BrowserPrivacySignals = Schema.Struct({
38
+ globalPrivacyControl: Schema.optional(Schema.Boolean)
39
+ }).annotate({ identifier: "BrowserPrivacySignals" });
30
40
  var BrowserWebVital = Schema.Struct({
31
41
  name: Schema.Literals(["LCP", "INP", "CLS", "FCP", "TTFB"]),
32
42
  id: Schema.NonEmptyString.check(Schema.isMaxLength(64)),
@@ -76,7 +86,9 @@ class OtlpEvents extends Context.Service()("krakstack/opentelemetry/Events") {
76
86
  label: "OtlpEvents",
77
87
  body: (logRecords) => {
78
88
  const scopes = new Map;
79
- for (const { scopeName, ...record } of logRecords) {
89
+ for (const { scopeName, canExport, ...record } of logRecords) {
90
+ if (canExport && !canExport())
91
+ continue;
80
92
  const name = scopeName ?? options.scopeName ?? "krakstack.events";
81
93
  const records = scopes.get(name);
82
94
  if (records)
@@ -1,4 +1,15 @@
1
1
  import { Schema } from "effect";
2
+ export declare const BrowserAnalyticsPreference: Schema.Struct<{
3
+ readonly version: Schema.String;
4
+ readonly choice: Schema.Literals<readonly ["accepted", "declined"]>;
5
+ /** A consent revision, not a visitor identifier; never exported with telemetry. */
6
+ readonly revision: Schema.String;
7
+ readonly issuedAt: Schema.Finite;
8
+ readonly expiresAt: Schema.Finite;
9
+ }>;
10
+ export declare const BrowserPrivacySignals: Schema.Struct<{
11
+ readonly globalPrivacyControl: Schema.optional<Schema.Boolean>;
12
+ }>;
2
13
  export declare const BrowserWebVital: Schema.Struct<{
3
14
  readonly name: Schema.Literals<readonly ["LCP", "INP", "CLS", "FCP", "TTFB"]>;
4
15
  readonly id: Schema.NonEmptyString;
@@ -1,5 +1,5 @@
1
1
  import { type Metric } from "web-vitals";
2
- import { Context, Layer, Schema } from "effect";
2
+ import { Context, Layer } from "effect";
3
3
  import { OtlpEvents } from "./events.js";
4
4
  /** web-vitals observers are document-scoped; only subscribers retain application state. */
5
5
  export declare const subscribeWebVitals: (subscriber: (metric: Metric) => void) => () => void;
@@ -7,9 +7,10 @@ export declare const WebVitals: Context.Reference<{
7
7
  readonly subscribe: typeof subscribeWebVitals;
8
8
  }>;
9
9
  export interface BrowserWebVitalsOptions {
10
+ readonly requireConsent?: boolean;
10
11
  readonly respectDoNotTrack?: boolean;
11
12
  }
12
13
  export declare class BrowserWebVitals {
13
14
  /** Provide a browser telemetry layer with events enabled; no exporter is created here. */
14
- static readonly layer: ({ respectDoNotTrack, }?: BrowserWebVitalsOptions) => Layer.Layer<never, Schema.SchemaError, OtlpEvents>;
15
+ static readonly layer: ({ respectDoNotTrack, requireConsent, }?: BrowserWebVitalsOptions) => Layer.Layer<never, never, OtlpEvents>;
15
16
  }
@@ -1,6 +1,6 @@
1
1
  // ../../src/services/opentelemetry/web-vitals.ts
2
2
  import { onCLS, onFCP, onINP, onLCP, onTTFB } from "web-vitals";
3
- import { Clock as Clock2, Context as Context2, Effect as Effect2, Layer as Layer2, Schema as Schema3 } from "effect";
3
+ import { Clock as Clock2, Context as Context2, Effect as Effect3, Layer as Layer2, Schema as Schema4 } from "effect";
4
4
 
5
5
  // ../../src/services/opentelemetry/events.ts
6
6
  import {
@@ -21,6 +21,16 @@ import {
21
21
 
22
22
  // ../../src/services/opentelemetry/schema.ts
23
23
  import { Schema } from "effect";
24
+ var BrowserAnalyticsPreference = Schema.Struct({
25
+ version: Schema.String,
26
+ choice: Schema.Literals(["accepted", "declined"]),
27
+ revision: Schema.String,
28
+ issuedAt: Schema.Finite,
29
+ expiresAt: Schema.Finite
30
+ }).annotate({ identifier: "BrowserAnalyticsPreference" });
31
+ var BrowserPrivacySignals = Schema.Struct({
32
+ globalPrivacyControl: Schema.optional(Schema.Boolean)
33
+ }).annotate({ identifier: "BrowserPrivacySignals" });
24
34
  var BrowserWebVital = Schema.Struct({
25
35
  name: Schema.Literals(["LCP", "INP", "CLS", "FCP", "TTFB"]),
26
36
  id: Schema.NonEmptyString.check(Schema.isMaxLength(64)),
@@ -70,7 +80,9 @@ class OtlpEvents extends Context.Service()("krakstack/opentelemetry/Events") {
70
80
  label: "OtlpEvents",
71
81
  body: (logRecords) => {
72
82
  const scopes = new Map;
73
- for (const { scopeName, ...record } of logRecords) {
83
+ for (const { scopeName, canExport, ...record } of logRecords) {
84
+ if (canExport && !canExport())
85
+ continue;
74
86
  const name = scopeName ?? options.scopeName ?? "krakstack.events";
75
87
  const records = scopes.get(name);
76
88
  if (records)
@@ -132,6 +144,78 @@ var event = Effect.fnUntraced(function* (name, properties, options) {
132
144
  });
133
145
  });
134
146
 
147
+ // ../../src/services/opentelemetry/consent.ts
148
+ import { Effect as Effect2, Option as Option2, Schema as Schema3 } from "effect";
149
+ var ANALYTICS_CONSENT_COOKIE = "krakstack_analytics_consent";
150
+ var ANALYTICS_NOTICE_VERSION = "1";
151
+ var changedEvent = "krakstack:analytics-consent";
152
+ var lifetime = 180 * 24 * 60 * 60 * 1000;
153
+ var codec = Schema3.StringFromUriComponent.pipe(Schema3.decodeTo(Schema3.fromJsonString(BrowserAnalyticsPreference)));
154
+ var readCookie = (cookie) => cookie.split(";").map((part) => part.trim()).find((part) => part.startsWith(`${ANALYTICS_CONSENT_COOKIE}=`))?.slice(ANALYTICS_CONSENT_COOKIE.length + 1);
155
+ var analyticsPreference = (cookie, now = Date.now()) => {
156
+ const value = readCookie(cookie);
157
+ if (!value)
158
+ return;
159
+ const decoded = Schema3.decodeUnknownOption(codec)(value);
160
+ if (Option2.isNone(decoded))
161
+ return;
162
+ const preference = decoded.value;
163
+ return preference.version === ANALYTICS_NOTICE_VERSION && preference.issuedAt <= now && preference.expiresAt > now && preference.expiresAt - preference.issuedAt <= lifetime ? preference : undefined;
164
+ };
165
+ var browserPrivacyEnabled = () => {
166
+ if (globalThis.navigator === undefined)
167
+ return false;
168
+ const value = Schema3.decodeUnknownOption(BrowserPrivacySignals)(navigator);
169
+ return navigator.doNotTrack === "1" || navigator.doNotTrack === "yes" || Option2.isSome(value) && value.value.globalPrivacyControl === true;
170
+ };
171
+ var browserPreference = () => {
172
+ if (globalThis.document === undefined)
173
+ return;
174
+ const cookie = Effect2.runSync(Effect2.try({
175
+ try: () => document.cookie,
176
+ catch: () => new Error("Analytics preference storage unavailable")
177
+ }).pipe(Effect2.catch(() => Effect2.succeed(""))));
178
+ return analyticsPreference(cookie);
179
+ };
180
+ var consentGeneration = 0;
181
+ var previousSnapshot;
182
+ var analyticsConsentSnapshot = () => {
183
+ const preference = browserPreference();
184
+ const snapshot = browserPrivacyEnabled() ? "blocked" : preference ? `${preference.choice}:${preference.revision}` : "pending";
185
+ if (snapshot !== previousSnapshot) {
186
+ consentGeneration++;
187
+ previousSnapshot = snapshot;
188
+ }
189
+ return snapshot;
190
+ };
191
+ var analyticsAllowed = () => analyticsConsentSnapshot().startsWith("accepted:");
192
+ var analyticsAcceptedBefore = (timestamp) => analyticsAllowed() && (browserPreference()?.issuedAt ?? Infinity) <= timestamp;
193
+ var analyticsExportGuard = () => {
194
+ const snapshot = analyticsConsentSnapshot();
195
+ const generation = consentGeneration;
196
+ return () => snapshot.startsWith("accepted:") && analyticsConsentSnapshot() === snapshot && consentGeneration === generation;
197
+ };
198
+ var subscribeAnalyticsConsent = (listener) => {
199
+ let previous = analyticsConsentSnapshot();
200
+ const notify = () => {
201
+ const next = analyticsConsentSnapshot();
202
+ if (next === previous)
203
+ return;
204
+ previous = next;
205
+ listener();
206
+ };
207
+ const timer = globalThis.setInterval(notify, 1000);
208
+ globalThis.addEventListener(changedEvent, notify);
209
+ globalThis.addEventListener("focus", notify);
210
+ document.addEventListener("visibilitychange", notify);
211
+ return () => {
212
+ globalThis.clearInterval(timer);
213
+ globalThis.removeEventListener(changedEvent, notify);
214
+ globalThis.removeEventListener("focus", notify);
215
+ document.removeEventListener("visibilitychange", notify);
216
+ };
217
+ };
218
+
135
219
  // ../../src/services/opentelemetry/web-vitals.ts
136
220
  var subscribers = new Set;
137
221
  var started = false;
@@ -156,71 +240,90 @@ var subscribeWebVitals = (subscriber) => {
156
240
  var WebVitals = Context2.Reference("krakstack/opentelemetry/WebVitals", {
157
241
  defaultValue: () => ({ subscribe: subscribeWebVitals })
158
242
  });
159
- var WebVitalsLive = Layer2.effectDiscard(Effect2.gen(function* () {
243
+ var WebVitalsLive = (requireConsent, respectDoNotTrack) => Layer2.effectDiscard(Effect3.gen(function* () {
160
244
  const vitals = yield* WebVitals;
161
245
  const events = yield* OtlpEvents;
162
246
  const clock = yield* Clock2.Clock;
163
247
  const seen = new Map;
164
- yield* Effect2.acquireRelease(Effect2.sync(() => vitals.subscribe((input) => {
165
- const parsed = Schema3.decodeUnknownOption(BrowserWebVital)(input);
166
- if (parsed._tag === "None")
167
- return;
168
- const metric = parsed.value;
169
- const key = `${metric.name}:${metric.id}`;
170
- if (seen.get(key) === metric.value)
171
- return;
172
- seen.set(key, metric.value);
173
- const timestamp = clock.currentTimeNanosUnsafe().toString();
174
- events.push({
175
- eventName: "browser.web_vital",
176
- timeUnixNano: timestamp,
177
- observedTimeUnixNano: timestamp,
178
- severityNumber: 9,
179
- droppedAttributesCount: 0,
180
- attributes: [
181
- {
182
- key: "browser.web_vital.name",
183
- value: { stringValue: metric.name.toLowerCase() }
184
- },
185
- {
186
- key: "browser.web_vital.id",
187
- value: { stringValue: metric.id }
188
- },
189
- {
190
- key: "browser.web_vital.value",
191
- value: { doubleValue: metric.value }
192
- },
193
- {
194
- key: "browser.web_vital.delta",
195
- value: { doubleValue: metric.delta }
196
- },
197
- {
198
- key: "browser.web_vital.rating",
199
- value: { stringValue: metric.rating }
200
- },
201
- {
202
- key: "browser.web_vital.navigation_type",
203
- value: { stringValue: metric.navigationType }
204
- },
205
- {
206
- key: "log.record.uid",
207
- value: { stringValue: `${metric.id}:${metric.value}` }
208
- }
209
- ]
248
+ if (requireConsent && !analyticsAcceptedBefore(performance.timeOrigin))
249
+ return;
250
+ const consentGuard = requireConsent ? analyticsExportGuard() : () => true;
251
+ let active = true;
252
+ const canExport = () => {
253
+ active = active && consentGuard() && (!respectDoNotTrack || !browserPrivacyEnabled());
254
+ return active;
255
+ };
256
+ if (!canExport())
257
+ return;
258
+ yield* Effect3.acquireRelease(Effect3.sync(() => {
259
+ const report = (input) => {
260
+ if (!canExport())
261
+ return;
262
+ const parsed = Schema4.decodeUnknownOption(BrowserWebVital)(input);
263
+ if (parsed._tag === "None")
264
+ return;
265
+ const metric = parsed.value;
266
+ const key = `${metric.name}:${metric.id}`;
267
+ if (seen.get(key) === metric.value)
268
+ return;
269
+ seen.set(key, metric.value);
270
+ const timestamp = clock.currentTimeNanosUnsafe().toString();
271
+ events.push({
272
+ canExport,
273
+ eventName: "browser.web_vital",
274
+ timeUnixNano: timestamp,
275
+ observedTimeUnixNano: timestamp,
276
+ severityNumber: 9,
277
+ droppedAttributesCount: 0,
278
+ attributes: [
279
+ {
280
+ key: "browser.web_vital.name",
281
+ value: { stringValue: metric.name.toLowerCase() }
282
+ },
283
+ {
284
+ key: "browser.web_vital.id",
285
+ value: { stringValue: metric.id }
286
+ },
287
+ {
288
+ key: "browser.web_vital.value",
289
+ value: { doubleValue: metric.value }
290
+ },
291
+ {
292
+ key: "browser.web_vital.delta",
293
+ value: { doubleValue: metric.delta }
294
+ },
295
+ {
296
+ key: "browser.web_vital.rating",
297
+ value: { stringValue: metric.rating }
298
+ },
299
+ {
300
+ key: "browser.web_vital.navigation_type",
301
+ value: { stringValue: metric.navigationType }
302
+ },
303
+ {
304
+ key: "log.record.uid",
305
+ value: { stringValue: `${metric.id}:${metric.value}` }
306
+ }
307
+ ]
308
+ });
309
+ };
310
+ const unsubscribe = vitals.subscribe(report);
311
+ const stop = subscribeAnalyticsConsent(() => {
312
+ if (!canExport())
313
+ unsubscribe();
210
314
  });
211
- })), (unsubscribe) => Effect2.sync(unsubscribe));
315
+ return () => {
316
+ stop();
317
+ unsubscribe();
318
+ };
319
+ }), (unsubscribe) => Effect3.sync(unsubscribe));
212
320
  }));
213
321
 
214
322
  class BrowserWebVitals {
215
323
  static layer = ({
216
- respectDoNotTrack = true
217
- } = {}) => Layer2.unwrap(Effect2.gen(function* () {
218
- const privacy = yield* Schema3.decodeUnknownEffect(Schema3.Struct({
219
- globalPrivacyControl: Schema3.optional(Schema3.Boolean)
220
- }))(navigator);
221
- const optedOut = respectDoNotTrack && (navigator.doNotTrack === "1" || navigator.doNotTrack === "yes" || privacy.globalPrivacyControl === true);
222
- return optedOut ? Layer2.empty : WebVitalsLive;
223
- }));
324
+ respectDoNotTrack = true,
325
+ requireConsent = true
326
+ } = {}) => WebVitalsLive(requireConsent, respectDoNotTrack);
224
327
  }
225
328
  export {
226
329
  BrowserWebVitals,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/registry",
3
- "version": "0.1.53",
3
+ "version": "0.1.55",
4
4
  "description": "Tree-shakable KrakStack components and Effect services.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,6 +17,10 @@
17
17
  "type": "module",
18
18
  "sideEffects": false,
19
19
  "exports": {
20
+ "./events/tracking-notice": {
21
+ "types": "./dist/services/events/client/tracking-notice.d.ts",
22
+ "import": "./dist/services/events/client/tracking-notice.js"
23
+ },
20
24
  "./events/client": {
21
25
  "types": "./dist/services/events/client/audit-log-table.d.ts",
22
26
  "import": "./dist/services/events/client/audit-log-table.js"