@baukit/analytics-core 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Patrick Koss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,161 @@
1
+ # `@baukit/analytics-core`
2
+
3
+ Provider-neutral, privacy-first product analytics for Baukit TypeScript applications. The package
4
+ defines the port and the safety policy; PostHog support belongs in the separate web and native
5
+ adapter packages. It has no runtime dependencies.
6
+
7
+ ## Why a port, not a provider wrapper
8
+
9
+ Product code should own event meaning and compile-time shape without importing a provider SDK. The
10
+ core accepts a product event union, applies consent and privacy controls, and sends neutral command
11
+ envelopes to a `Transport`. A provider adapter only translates those already-sanitized envelopes.
12
+
13
+ The required order for captured properties is:
14
+
15
+ 1. Keep only keys in that event's allowlist.
16
+ 2. Scrub blocked keys and sensitive string patterns.
17
+ 3. Stamp the required common context and identity.
18
+ 4. Enqueue the sanitized envelope for transport.
19
+
20
+ ## Typed setup
21
+
22
+ ```ts
23
+ import {
24
+ AnalyticsClient,
25
+ type AnalyticsEvent,
26
+ type EventAllowlist,
27
+ type Transport,
28
+ } from '@baukit/analytics-core';
29
+
30
+ type ProductEvent =
31
+ | {
32
+ name: 'onboarding_started';
33
+ properties: { source: 'organic' | 'invite' };
34
+ }
35
+ | {
36
+ name: 'onboarding_completed';
37
+ properties: { duration_seconds: number };
38
+ };
39
+
40
+ const allowlist = {
41
+ onboarding_started: ['source'],
42
+ onboarding_completed: ['duration_seconds'],
43
+ } as const satisfies EventAllowlist<ProductEvent>;
44
+
45
+ declare const transport: Transport<ProductEvent>; // for example, a PostHog adapter
46
+
47
+ const analytics = new AnalyticsClient<ProductEvent>({
48
+ context: {
49
+ schema_version: 1,
50
+ app: 'architecture-health',
51
+ app_version: '1.0.0',
52
+ platform: 'web',
53
+ environment: 'production',
54
+ locale: 'de-DE',
55
+ },
56
+ allowlist,
57
+ transport,
58
+ });
59
+
60
+ analytics.capture({
61
+ name: 'onboarding_started',
62
+ properties: { source: 'organic' },
63
+ });
64
+ ```
65
+
66
+ `AnalyticsClientOptions.context` is required, so constructing a client without
67
+ `schema_version`, `app`, `app_version`, `platform`, `environment`, or `locale` does not type-check.
68
+ Adding a name to `ProductEvent` also makes the matching allowlist entry required. Runtime input can
69
+ still contain excess keys (for example, after an unsafe cast or across a JavaScript boundary), so
70
+ the allowlist drops them before transport.
71
+
72
+ Event names are a product-owned convention: stable, past-tense `snake_case`, such as
73
+ `onboarding_completed`. Encoding English past tense in template-literal types would reject valid
74
+ irregular forms and create false confidence. Instead, the client uses a conservative development
75
+ warning (snake case plus a past-tense heuristic); it never changes runtime delivery. Tracking-plan
76
+ purpose and ownership remain product responsibilities.
77
+
78
+ ## Consent
79
+
80
+ Consent starts as `unknown`. Captures, identify calls, and alias calls made while consent is
81
+ `unknown` or `denied` are dropped immediately and are never buffered for later opt-in.
82
+
83
+ ```ts
84
+ analytics.setConsent('granted'); // persist opt-in, then analytics may run
85
+ analytics.capture({
86
+ name: 'onboarding_completed',
87
+ properties: { duration_seconds: 42 },
88
+ });
89
+
90
+ analytics.setConsent('denied'); // persist withdrawal and discard every unsent command
91
+ ```
92
+
93
+ `setConsent` is not itself an analytics event. Consent is read synchronously during construction,
94
+ before the first capture is possible. `InMemoryAnalyticsStorage` is the dependency-free default;
95
+ products should inject a small synchronous `AnalyticsStorage` backed by device storage. If the
96
+ platform's native storage API is asynchronous, hydrate a synchronous application-owned cache
97
+ before constructing the client. Storage failures fail privacy-safe: unreadable consent becomes
98
+ `unknown`, and analytics methods do not throw because persistence diagnostics fail.
99
+
100
+ Withdrawal clears commands that have not been handed to the transport. A batch already in flight
101
+ cannot be recalled, which is a transport boundary rather than hidden buffering.
102
+
103
+ ## Identity
104
+
105
+ The client creates and persists an anonymous UUID with `globalThis.crypto.randomUUID()`. Runtimes
106
+ without it, including some React Native configurations, must inject a cryptographically secure
107
+ `uuidFactory`; there is intentionally no `Math.random()` fallback.
108
+
109
+ ```ts
110
+ analytics.setConsent('granted');
111
+ const anonymousId = analytics.anonymousId;
112
+
113
+ analytics.identify(internalUserUuid, { plan: 'free' });
114
+ analytics.alias(anonymousId, internalUserUuid); // accepted once for this anonymous identity
115
+
116
+ analytics.reset(); // logout: clear known identity and alias guard, rotate anonymous UUID
117
+ ```
118
+
119
+ Only UUID-shaped user IDs are accepted. This cannot prove which system issued a UUID, so products
120
+ must pass their internal user UUID—not an email, name, or provider subject. Switching directly
121
+ between known users is rejected; call `reset()` first. The alias guard is persisted and admits at
122
+ most one alias command for an anonymous identity, including across client reconstruction. Traits
123
+ are scrubbed with the same blocked-key and sensitive-value rules as event properties.
124
+
125
+ ## Scrubbing
126
+
127
+ The default key blocklist is `email`, `name`, `token`, `password`, `authorization`, `cookie`,
128
+ `phone`, and `address`. Matching is case/separator insensitive and deliberately conservative, so
129
+ keys such as `displayName` and `auth_token` are redacted. Products can add terms through
130
+ `blockedKeys`. Email-shaped strings, JWT-shaped strings, and long hex/base64-like strings become
131
+ `"[redacted]"`. Nested arrays and plain objects are traversed without mutating the input.
132
+
133
+ The scrubber is only a last line of defense. Event properties must remain bounded metadata: never
134
+ health or food values, conversation or prompt content, free text, precise location, credentials,
135
+ or raw identifying URLs.
136
+
137
+ ## Buffering and failures
138
+
139
+ Accepted commands enter an in-memory queue with these defaults:
140
+
141
+ - maximum 100 waiting commands;
142
+ - flush at 20 commands or after 5 seconds;
143
+ - oldest waiting command dropped on overflow;
144
+ - two retries after the initial transport attempt, with short exponential delays;
145
+ - a failed batch dropped after the retry cap.
146
+
147
+ `capture`, `identify`, `alias`, `reset`, and `setConsent` are synchronous and never wait for a
148
+ provider. Size-triggered delivery is scheduled in a microtask; interval delivery uses an unref'd
149
+ timer where the runtime supports it. Transport rejection and synchronous transport exceptions are
150
+ caught internally and never escape into the user journey. `onTransportFailure` is available for
151
+ bounded diagnostics, and even exceptions from that callback are contained.
152
+
153
+ `flush()` is an explicit best-effort boundary that always resolves, useful for tests and app
154
+ lifecycle hooks. `dispose()` performs a best-effort flush and clears its timer. Queues are not
155
+ persisted: application restarts do not resurrect analytics commands, and unknown/denied events can
156
+ never appear after later consent.
157
+
158
+ `NoopTransport` safely discards commands. `InMemoryTransport` retains inspectable envelopes for
159
+ tests. PostHog web and React Native packages plug in by implementing `Transport<E>` and translating
160
+ the neutral `capture`, `identify`, `alias`, and `reset` envelope variants; product code and privacy
161
+ policy stay unchanged.
@@ -0,0 +1,21 @@
1
+ import type { AnalyticsClientOptions, AnalyticsEvent, AnalyticsPort, ConsentState, SafeTraits } from './types.js';
2
+ /** A deliberately conservative development-time heuristic, not a type-level grammar. */
3
+ export declare function followsEventNameConvention(name: string): boolean;
4
+ export declare class AnalyticsClient<E extends AnalyticsEvent> implements AnalyticsPort<E> {
5
+ #private;
6
+ constructor(options: AnalyticsClientOptions<E>);
7
+ get consent(): ConsentState;
8
+ get anonymousId(): string;
9
+ get userId(): string | undefined;
10
+ get pendingCount(): number;
11
+ capture(event: E): void;
12
+ identify(userId: string, traits?: SafeTraits): void;
13
+ alias(anonymousId: string, userId: string): void;
14
+ reset(): void;
15
+ setConsent(value: ConsentState): void;
16
+ /** Flushes accepted commands and always resolves, including on transport failure. */
17
+ flush(): Promise<void>;
18
+ /** Stops the interval timer after a best-effort flush. */
19
+ dispose(): Promise<void>;
20
+ }
21
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,sBAAsB,EAGtB,cAAc,EACd,aAAa,EAEb,YAAY,EAIZ,UAAU,EAGX,MAAM,YAAY,CAAC;AAsGpB,wFAAwF;AACxF,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAKhE;AAED,qBAAa,eAAe,CAAC,CAAC,SAAS,cAAc,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;;gBA2B7D,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC;IAyDrD,IAAW,OAAO,IAAI,YAAY,CAEjC;IAED,IAAW,WAAW,IAAI,MAAM,CAE/B;IAED,IAAW,MAAM,IAAI,MAAM,GAAG,SAAS,CAEtC;IAED,IAAW,YAAY,IAAI,MAAM,CAEhC;IAEM,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAkCvB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,IAAI;IA+BnD,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IA4BhD,KAAK,IAAI,IAAI;IAuBb,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAa5C,qFAAqF;IAC9E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAiB7B,0DAA0D;IAC7C,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CA2NtC"}
package/dist/client.js ADDED
@@ -0,0 +1,496 @@
1
+ import { scrubProperties } from './scrubber.js';
2
+ import { InMemoryAnalyticsStorage } from './storage.js';
3
+ import { NoopTransport } from './transports.js';
4
+ const DEFAULT_MAX_QUEUE_SIZE = 100;
5
+ const DEFAULT_FLUSH_BATCH_SIZE = 20;
6
+ const DEFAULT_FLUSH_INTERVAL_MS = 5_000;
7
+ const DEFAULT_MAX_RETRIES = 2;
8
+ const DEFAULT_RETRY_DELAY_MS = 100;
9
+ const UUID_PATTERN = /^[A-Fa-f0-9]{8}-(?:[A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}$/;
10
+ const IRREGULAR_PAST_TENSE = new Set([
11
+ 'begun',
12
+ 'bought',
13
+ 'built',
14
+ 'caught',
15
+ 'chosen',
16
+ 'done',
17
+ 'found',
18
+ 'given',
19
+ 'gone',
20
+ 'kept',
21
+ 'known',
22
+ 'left',
23
+ 'lost',
24
+ 'made',
25
+ 'paid',
26
+ 'read',
27
+ 'run',
28
+ 'seen',
29
+ 'sent',
30
+ 'shown',
31
+ 'sold',
32
+ 'taken',
33
+ 'won',
34
+ 'written',
35
+ ]);
36
+ function getTimeoutRuntime() {
37
+ const runtime = globalThis;
38
+ if (runtime.setTimeout === undefined || runtime.clearTimeout === undefined) {
39
+ throw new Error('@baukit/analytics-core requires setTimeout and clearTimeout');
40
+ }
41
+ return runtime;
42
+ }
43
+ function inferDevelopmentMode() {
44
+ const runtime = globalThis;
45
+ return runtime.process?.env?.['NODE_ENV'] !== 'production';
46
+ }
47
+ function defaultWarning(message) {
48
+ const runtime = globalThis;
49
+ runtime.console?.warn(message);
50
+ }
51
+ function defaultUuidFactory() {
52
+ const runtime = globalThis;
53
+ if (runtime.crypto?.randomUUID === undefined) {
54
+ throw new Error('@baukit/analytics-core requires crypto.randomUUID; provide uuidFactory on runtimes without it');
55
+ }
56
+ return runtime.crypto.randomUUID();
57
+ }
58
+ function requireInteger(name, value, minimum) {
59
+ if (!Number.isInteger(value) || value < minimum) {
60
+ throw new TypeError(`${name} must be an integer greater than or equal to ${String(minimum)}`);
61
+ }
62
+ return value;
63
+ }
64
+ function requireNonEmpty(name, value) {
65
+ if (value.trim().length === 0) {
66
+ throw new TypeError(`${name} must not be empty`);
67
+ }
68
+ return value;
69
+ }
70
+ function validateContext(context) {
71
+ requireInteger('context.schema_version', context.schema_version, 1);
72
+ requireNonEmpty('context.app', context.app);
73
+ requireNonEmpty('context.app_version', context.app_version);
74
+ requireNonEmpty('context.platform', context.platform);
75
+ requireNonEmpty('context.environment', context.environment);
76
+ requireNonEmpty('context.locale', context.locale);
77
+ return { ...context };
78
+ }
79
+ function isUuid(value) {
80
+ return UUID_PATTERN.test(value);
81
+ }
82
+ /** A deliberately conservative development-time heuristic, not a type-level grammar. */
83
+ export function followsEventNameConvention(name) {
84
+ if (!/^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/.test(name)) {
85
+ return false;
86
+ }
87
+ return name.split('_').some((part) => part.endsWith('ed') || IRREGULAR_PAST_TENSE.has(part));
88
+ }
89
+ export class AnalyticsClient {
90
+ #context;
91
+ #allowlist;
92
+ #transport;
93
+ #storage;
94
+ #storagePrefix;
95
+ #uuidFactory;
96
+ #blockedKeys;
97
+ #maxQueueSize;
98
+ #flushBatchSize;
99
+ #flushIntervalMs;
100
+ #maxRetries;
101
+ #retryDelayMs;
102
+ #development;
103
+ #now;
104
+ #onWarning;
105
+ #onTransportFailure;
106
+ #queue = [];
107
+ #warnedEventNames = new Set();
108
+ #consent;
109
+ #anonymousId;
110
+ #userId;
111
+ #aliasedUserId;
112
+ #flushTimer;
113
+ #immediateFlushScheduled = false;
114
+ #activeFlush;
115
+ constructor(options) {
116
+ this.#context = validateContext(options.context);
117
+ this.#allowlist = options.allowlist;
118
+ this.#transport = options.transport ?? new NoopTransport();
119
+ this.#storage = options.storage ?? new InMemoryAnalyticsStorage();
120
+ this.#storagePrefix = options.storageKeyPrefix ?? `@baukit/analytics-core:${this.#context.app}`;
121
+ this.#uuidFactory = options.uuidFactory ?? defaultUuidFactory;
122
+ this.#blockedKeys = [...(options.blockedKeys ?? [])];
123
+ this.#maxQueueSize = requireInteger('maxQueueSize', options.maxQueueSize ?? DEFAULT_MAX_QUEUE_SIZE, 1);
124
+ this.#flushBatchSize = requireInteger('flushBatchSize', options.flushBatchSize ?? Math.min(DEFAULT_FLUSH_BATCH_SIZE, this.#maxQueueSize), 1);
125
+ this.#flushIntervalMs = requireInteger('flushIntervalMs', options.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS, 1);
126
+ this.#maxRetries = requireInteger('maxRetries', options.maxRetries ?? DEFAULT_MAX_RETRIES, 0);
127
+ this.#retryDelayMs = requireInteger('retryDelayMs', options.retryDelayMs ?? DEFAULT_RETRY_DELAY_MS, 0);
128
+ this.#development = options.development ?? inferDevelopmentMode();
129
+ this.#now = options.now ?? (() => new Date());
130
+ this.#onWarning = options.onWarning ?? defaultWarning;
131
+ this.#onTransportFailure = options.onTransportFailure;
132
+ const storedConsent = this.#readStorage(this.#consentKey);
133
+ this.#consent =
134
+ storedConsent === 'granted' || storedConsent === 'denied' || storedConsent === 'unknown'
135
+ ? storedConsent
136
+ : 'unknown';
137
+ const storedAnonymousId = this.#readStorage(this.#anonymousIdKey);
138
+ this.#anonymousId =
139
+ storedAnonymousId !== undefined && isUuid(storedAnonymousId)
140
+ ? storedAnonymousId
141
+ : this.#generateAnonymousId();
142
+ this.#writeStorage(this.#anonymousIdKey, this.#anonymousId);
143
+ const storedUserId = this.#readStorage(this.#userIdKey);
144
+ this.#userId = storedUserId !== undefined && isUuid(storedUserId) ? storedUserId : undefined;
145
+ const storedAliasedUserId = this.#readStorage(this.#aliasedUserIdKey);
146
+ this.#aliasedUserId =
147
+ storedAliasedUserId !== undefined && isUuid(storedAliasedUserId)
148
+ ? storedAliasedUserId
149
+ : undefined;
150
+ }
151
+ get consent() {
152
+ return this.#consent;
153
+ }
154
+ get anonymousId() {
155
+ return this.#anonymousId;
156
+ }
157
+ get userId() {
158
+ return this.#userId;
159
+ }
160
+ get pendingCount() {
161
+ return this.#queue.length;
162
+ }
163
+ capture(event) {
164
+ if (this.#consent !== 'granted') {
165
+ return;
166
+ }
167
+ this.#warnAboutEventName(event.name);
168
+ const allowedProperties = this.#allowedProperties(event);
169
+ if (allowedProperties === undefined) {
170
+ this.#warn(`Dropped undeclared analytics event "${event.name}".`);
171
+ return;
172
+ }
173
+ const filtered = {};
174
+ const source = event.properties;
175
+ for (const propertyName of allowedProperties) {
176
+ if (Object.prototype.hasOwnProperty.call(source, propertyName)) {
177
+ filtered[propertyName] = source[propertyName];
178
+ }
179
+ }
180
+ const envelope = {
181
+ type: 'capture',
182
+ captured_at: this.#timestamp(),
183
+ anonymous_id: this.#anonymousId,
184
+ ...(this.#userId === undefined ? {} : { user_id: this.#userId }),
185
+ event: {
186
+ ...this.#context,
187
+ name: event.name,
188
+ properties: scrubProperties(filtered, { blockedKeys: this.#blockedKeys }),
189
+ },
190
+ };
191
+ this.#enqueue(envelope);
192
+ }
193
+ identify(userId, traits) {
194
+ if (this.#consent !== 'granted') {
195
+ return;
196
+ }
197
+ if (!isUuid(userId)) {
198
+ this.#warn('Dropped analytics identify call because userId is not a UUID.');
199
+ return;
200
+ }
201
+ if (this.#userId !== undefined && this.#userId !== userId) {
202
+ this.#warn('Dropped analytics identify call for a different user; call reset() first.');
203
+ return;
204
+ }
205
+ this.#userId = userId;
206
+ this.#writeStorage(this.#userIdKey, userId);
207
+ const scrubbedTraits = traits === undefined
208
+ ? undefined
209
+ : scrubProperties(traits, {
210
+ blockedKeys: this.#blockedKeys,
211
+ });
212
+ const envelope = {
213
+ type: 'identify',
214
+ captured_at: this.#timestamp(),
215
+ anonymous_id: this.#anonymousId,
216
+ user_id: userId,
217
+ ...(scrubbedTraits === undefined ? {} : { traits: scrubbedTraits }),
218
+ };
219
+ this.#enqueue(envelope);
220
+ }
221
+ alias(anonymousId, userId) {
222
+ if (this.#consent !== 'granted') {
223
+ return;
224
+ }
225
+ if (!isUuid(anonymousId) || anonymousId !== this.#anonymousId) {
226
+ this.#warn('Dropped analytics alias call because anonymousId is not the current UUID.');
227
+ return;
228
+ }
229
+ if (!isUuid(userId) || this.#userId !== userId) {
230
+ this.#warn('Dropped analytics alias call; identify() must first set the same UUID userId.');
231
+ return;
232
+ }
233
+ if (this.#aliasedUserId !== undefined) {
234
+ this.#warn('Dropped repeated analytics alias call for the current anonymous identity.');
235
+ return;
236
+ }
237
+ this.#aliasedUserId = userId;
238
+ this.#writeStorage(this.#aliasedUserIdKey, userId);
239
+ const envelope = {
240
+ type: 'alias',
241
+ captured_at: this.#timestamp(),
242
+ anonymous_id: anonymousId,
243
+ user_id: userId,
244
+ };
245
+ this.#enqueue(envelope);
246
+ }
247
+ reset() {
248
+ const previousAnonymousId = this.#anonymousId;
249
+ const previousUserId = this.#userId;
250
+ const nextAnonymousId = this.#generateAnonymousId(previousAnonymousId);
251
+ if (this.#consent === 'granted') {
252
+ const envelope = {
253
+ type: 'reset',
254
+ captured_at: this.#timestamp(),
255
+ previous_anonymous_id: previousAnonymousId,
256
+ ...(previousUserId === undefined ? {} : { previous_user_id: previousUserId }),
257
+ };
258
+ this.#enqueue(envelope);
259
+ }
260
+ this.#anonymousId = nextAnonymousId;
261
+ this.#userId = undefined;
262
+ this.#aliasedUserId = undefined;
263
+ this.#writeStorage(this.#anonymousIdKey, nextAnonymousId);
264
+ this.#removeStorage(this.#userIdKey);
265
+ this.#removeStorage(this.#aliasedUserIdKey);
266
+ }
267
+ setConsent(value) {
268
+ const transitionedToDenied = this.#consent !== 'denied' && value === 'denied';
269
+ this.#consent = value;
270
+ this.#writeStorage(this.#consentKey, value);
271
+ if (value !== 'granted') {
272
+ this.#queue.length = 0;
273
+ this.#clearFlushTimer();
274
+ }
275
+ if (transitionedToDenied) {
276
+ this.#clearTransportPending();
277
+ }
278
+ }
279
+ /** Flushes accepted commands and always resolves, including on transport failure. */
280
+ flush() {
281
+ if (this.#activeFlush !== undefined) {
282
+ return this.#activeFlush;
283
+ }
284
+ this.#clearFlushTimer();
285
+ const operation = this.#drainQueue().finally(() => {
286
+ if (this.#activeFlush === operation) {
287
+ this.#activeFlush = undefined;
288
+ }
289
+ if (this.#queue.length > 0 && this.#consent === 'granted') {
290
+ this.#armFlushTimer();
291
+ }
292
+ });
293
+ this.#activeFlush = operation;
294
+ return operation;
295
+ }
296
+ /** Stops the interval timer after a best-effort flush. */
297
+ async dispose() {
298
+ this.#clearFlushTimer();
299
+ await this.flush();
300
+ this.#clearFlushTimer();
301
+ }
302
+ get #consentKey() {
303
+ return `${this.#storagePrefix}:consent`;
304
+ }
305
+ get #anonymousIdKey() {
306
+ return `${this.#storagePrefix}:anonymous-id`;
307
+ }
308
+ get #userIdKey() {
309
+ return `${this.#storagePrefix}:user-id`;
310
+ }
311
+ get #aliasedUserIdKey() {
312
+ return `${this.#storagePrefix}:aliased-user-id`;
313
+ }
314
+ #allowedProperties(event) {
315
+ const allowlist = this.#allowlist;
316
+ return allowlist[event.name];
317
+ }
318
+ #enqueue(envelope) {
319
+ if (this.#consent !== 'granted') {
320
+ return;
321
+ }
322
+ if (this.#queue.length === this.#maxQueueSize) {
323
+ this.#queue.shift();
324
+ }
325
+ this.#queue.push(envelope);
326
+ if (this.#queue.length >= this.#flushBatchSize) {
327
+ this.#requestImmediateFlush();
328
+ }
329
+ else {
330
+ this.#armFlushTimer();
331
+ }
332
+ }
333
+ #requestImmediateFlush() {
334
+ if (this.#immediateFlushScheduled) {
335
+ return;
336
+ }
337
+ this.#immediateFlushScheduled = true;
338
+ void Promise.resolve()
339
+ .then(() => {
340
+ this.#immediateFlushScheduled = false;
341
+ return this.flush();
342
+ })
343
+ .catch(() => {
344
+ // flush() is deliberately no-throw; this guard prevents future regressions leaking rejections.
345
+ });
346
+ }
347
+ #armFlushTimer() {
348
+ if (this.#flushTimer !== undefined || this.#queue.length === 0) {
349
+ return;
350
+ }
351
+ const timers = getTimeoutRuntime();
352
+ this.#flushTimer = timers.setTimeout(() => {
353
+ this.#flushTimer = undefined;
354
+ void this.flush();
355
+ }, this.#flushIntervalMs);
356
+ if (this.#isNodeStyleTimeout(this.#flushTimer)) {
357
+ this.#flushTimer.unref();
358
+ }
359
+ }
360
+ #clearFlushTimer() {
361
+ if (this.#flushTimer === undefined) {
362
+ return;
363
+ }
364
+ getTimeoutRuntime().clearTimeout(this.#flushTimer);
365
+ this.#flushTimer = undefined;
366
+ }
367
+ #clearTransportPending() {
368
+ try {
369
+ const operation = this.#transport.clearPending?.();
370
+ if (operation !== undefined) {
371
+ void Promise.resolve(operation).catch((error) => {
372
+ this.#reportTransportFailure({ error, envelopes: [], attempts: 0 });
373
+ });
374
+ }
375
+ }
376
+ catch (error) {
377
+ this.#reportTransportFailure({ error, envelopes: [], attempts: 0 });
378
+ }
379
+ }
380
+ #isNodeStyleTimeout(value) {
381
+ return (typeof value === 'object' &&
382
+ value !== null &&
383
+ 'unref' in value &&
384
+ typeof value.unref === 'function');
385
+ }
386
+ async #drainQueue() {
387
+ try {
388
+ while (this.#queue.length > 0 && this.#hasConsent()) {
389
+ const batch = this.#queue.splice(0, this.#flushBatchSize);
390
+ let lastError;
391
+ let attempts = 0;
392
+ while (attempts <= this.#maxRetries && this.#hasConsent()) {
393
+ attempts += 1;
394
+ try {
395
+ await this.#transport.send(batch);
396
+ lastError = undefined;
397
+ break;
398
+ }
399
+ catch (error) {
400
+ lastError = error;
401
+ if (attempts <= this.#maxRetries && this.#hasConsent()) {
402
+ await this.#retryDelay(attempts);
403
+ }
404
+ }
405
+ }
406
+ if (lastError !== undefined) {
407
+ this.#reportTransportFailure({ error: lastError, envelopes: batch, attempts });
408
+ }
409
+ }
410
+ }
411
+ catch (error) {
412
+ this.#reportTransportFailure({ error, envelopes: [], attempts: 0 });
413
+ }
414
+ }
415
+ #hasConsent() {
416
+ return this.#consent === 'granted';
417
+ }
418
+ async #retryDelay(attempt) {
419
+ const delay = this.#retryDelayMs * 2 ** (attempt - 1);
420
+ if (delay === 0) {
421
+ await Promise.resolve();
422
+ return;
423
+ }
424
+ await new Promise((resolve) => {
425
+ getTimeoutRuntime().setTimeout(resolve, delay);
426
+ });
427
+ }
428
+ #reportTransportFailure(failure) {
429
+ try {
430
+ this.#onTransportFailure?.(failure);
431
+ }
432
+ catch {
433
+ // Diagnostics are never allowed to affect application behavior.
434
+ }
435
+ }
436
+ #timestamp() {
437
+ try {
438
+ return this.#now().toISOString();
439
+ }
440
+ catch {
441
+ return new Date().toISOString();
442
+ }
443
+ }
444
+ #generateAnonymousId(previous) {
445
+ for (let attempt = 0; attempt < 3; attempt += 1) {
446
+ const candidate = this.#uuidFactory();
447
+ if (isUuid(candidate) && candidate !== previous) {
448
+ return candidate;
449
+ }
450
+ }
451
+ throw new Error('uuidFactory must return a fresh UUID');
452
+ }
453
+ #warnAboutEventName(name) {
454
+ if (!this.#development ||
455
+ this.#warnedEventNames.has(name) ||
456
+ followsEventNameConvention(name)) {
457
+ return;
458
+ }
459
+ this.#warnedEventNames.add(name);
460
+ this.#warn(`Analytics event "${name}" does not appear to use the past-tense snake_case convention.`);
461
+ }
462
+ #readStorage(key) {
463
+ try {
464
+ return this.#storage.getItem(key);
465
+ }
466
+ catch {
467
+ this.#warn(`Analytics storage read failed for "${key}"; using a privacy-safe default.`);
468
+ return undefined;
469
+ }
470
+ }
471
+ #writeStorage(key, value) {
472
+ try {
473
+ this.#storage.setItem(key, value);
474
+ }
475
+ catch {
476
+ this.#warn(`Analytics storage write failed for "${key}".`);
477
+ }
478
+ }
479
+ #removeStorage(key) {
480
+ try {
481
+ this.#storage.removeItem(key);
482
+ }
483
+ catch {
484
+ this.#warn(`Analytics storage removal failed for "${key}".`);
485
+ }
486
+ }
487
+ #warn(message) {
488
+ try {
489
+ this.#onWarning(message);
490
+ }
491
+ catch {
492
+ // Warnings are advisory and never alter analytics behavior.
493
+ }
494
+ }
495
+ }
496
+ //# sourceMapp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AAO,CAAC,GAAG,CAAC,CAAC;QACpC,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC,KAAK,CAAC,sCAAsC,GAAG,kCAAkC,CAAC,CAAC;YACxF,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAED,aAAa,CAAC,GAAW,EAAE,KAAa;QACtC,IAAI,CAAC;YACH,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACpC,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC,KAAK,CAAC,uCAAuC,GAAG,IAAI,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;IAED,cAAc,CAAC,GAAW;QACxB,IAAI,CAAC;YACH,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC,KAAK,CAAC,yCAAyC,GAAG,IAAI,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAe;QACnB,IAAI,CAAC;YACH,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;QAAC,MAAM,CAAC;YACP,4DAA4D;QAC9D,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export { AnalyticsClient, followsEventNameConvention } from './client.js';
2
+ export { DEFAULT_BLOCKED_KEYS, REDACTED_VALUE, scrubProperties, type ScrubberOptions, } from './scrubber.js';
3
+ export { InMemoryAnalyticsStorage } from './storage.js';
4
+ export { InMemoryTransport, NoopTransport } from './transports.js';
5
+ export type { AliasEnvelope, AnalyticsClientOptions, AnalyticsContext, AnalyticsEnvelope, AnalyticsEvent, AnalyticsPort, AnalyticsStorage, CaptureEnvelope, ConsentState, EventAllowlist, IdentifyEnvelope, ResetEnvelope, SafeTraits, Transport, TransportFailure, } from './types.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACnE,YAAY,EACV,aAAa,EACb,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,SAAS,EACT,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { AnalyticsClient, followsEventNameConvention } from './client.js';
2
+ export { DEFAULT_BLOCKED_KEYS, REDACTED_VALUE, scrubProperties, } from './scrubber.js';
3
+ export { InMemoryAnalyticsStorage } from './storage.js';
4
+ export { InMemoryTransport, NoopTransport } from './transports.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,eAAe,GAEhB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,11 @@
1
+ export declare const REDACTED_VALUE: "[redacted]";
2
+ export declare const DEFAULT_BLOCKED_KEYS: readonly ["email", "name", "token", "password", "authorization", "cookie", "phone", "address"];
3
+ export interface ScrubberOptions {
4
+ readonly blockedKeys?: readonly string[];
5
+ }
6
+ /**
7
+ * Returns a new object with blocked keys and sensitive string values redacted.
8
+ * Nested objects and arrays are traversed; the input is never mutated.
9
+ */
10
+ export declare function scrubProperties(properties: Readonly<Record<string, unknown>>, options?: ScrubberOptions): Readonly<Record<string, unknown>>;
11
+ //# sourceMappingURL=scrubber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scrubber.d.ts","sourceRoot":"","sources":["../src/scrubber.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,EAAG,YAAqB,CAAC;AAEpD,eAAO,MAAM,oBAAoB,gGASvB,CAAC;AAEX,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C;AA0FD;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC7C,OAAO,GAAE,eAAoB,GAC5B,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAKnC"}
@@ -0,0 +1,83 @@
1
+ export const REDACTED_VALUE = '[redacted]';
2
+ export const DEFAULT_BLOCKED_KEYS = [
3
+ 'email',
4
+ 'name',
5
+ 'token',
6
+ 'password',
7
+ 'authorization',
8
+ 'cookie',
9
+ 'phone',
10
+ 'address',
11
+ ];
12
+ const EMAIL_PATTERN = /(?:^|\s|[<(])[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+(?:$|\s|[>),.;:!?])/i;
13
+ const JWT_PATTERN = /^[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}$/;
14
+ const LONG_HEX_PATTERN = /^[A-Fa-f0-9]{32,}$/;
15
+ const LONG_BASE64_PATTERN = /^[A-Za-z0-9+/_-]{32,}={0,2}$/;
16
+ function normalizeKey(key) {
17
+ return key.toLowerCase().replaceAll(/[^a-z0-9]/g, '');
18
+ }
19
+ function createBlockedKeyList(extensions) {
20
+ return [...DEFAULT_BLOCKED_KEYS, ...extensions].map(normalizeKey).filter((key) => key.length > 0);
21
+ }
22
+ function isBlockedKey(key, blockedKeys) {
23
+ const normalized = normalizeKey(key);
24
+ return blockedKeys.some((blockedKey) => normalized.includes(blockedKey));
25
+ }
26
+ function isSensitiveString(value) {
27
+ const candidate = value.trim();
28
+ return (EMAIL_PATTERN.test(candidate) ||
29
+ JWT_PATTERN.test(candidate) ||
30
+ LONG_HEX_PATTERN.test(candidate) ||
31
+ LONG_BASE64_PATTERN.test(candidate));
32
+ }
33
+ function scrubValue(value, blockedKeys, ancestors) {
34
+ if (typeof value === 'string') {
35
+ return isSensitiveString(value) ? REDACTED_VALUE : value;
36
+ }
37
+ if (value === null ||
38
+ typeof value === 'number' ||
39
+ typeof value === 'boolean' ||
40
+ typeof value === 'undefined') {
41
+ return value;
42
+ }
43
+ if (typeof value !== 'object') {
44
+ return REDACTED_VALUE;
45
+ }
46
+ if (ancestors.has(value)) {
47
+ return REDACTED_VALUE;
48
+ }
49
+ ancestors.add(value);
50
+ let result;
51
+ if (Array.isArray(value)) {
52
+ result = value.map((item) => scrubValue(item, blockedKeys, ancestors));
53
+ }
54
+ else if (Object.getPrototypeOf(value) === Object.prototype ||
55
+ Object.getPrototypeOf(value) === null) {
56
+ result = scrubRecord(value, blockedKeys, ancestors);
57
+ }
58
+ else {
59
+ result = REDACTED_VALUE;
60
+ }
61
+ ancestors.delete(value);
62
+ return result;
63
+ }
64
+ function scrubRecord(properties, blockedKeys, ancestors) {
65
+ const scrubbed = {};
66
+ for (const [key, value] of Object.entries(properties)) {
67
+ scrubbed[key] = isBlockedKey(key, blockedKeys)
68
+ ? REDACTED_VALUE
69
+ : scrubValue(value, blockedKeys, ancestors);
70
+ }
71
+ return scrubbed;
72
+ }
73
+ /**
74
+ * Returns a new object with blocked keys and sensitive string values redacted.
75
+ * Nested objects and arrays are traversed; the input is never mutated.
76
+ */
77
+ export function scrubProperties(properties, options = {}) {
78
+ const blockedKeys = createBlockedKeyList(options.blockedKeys ?? []);
79
+ const ancestors = new WeakSet();
80
+ ancestors.add(properties);
81
+ return scrubRecord(properties, blockedKeys, ancestors);
82
+ }
83
+ //# sourceMappingURL=scrubber.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scrubber.js","sourceRoot":"","sources":["../src/scrubber.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,YAAqB,CAAC;AAEpD,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,OAAO;IACP,MAAM;IACN,OAAO;IACP,UAAU;IACV,eAAe;IACf,QAAQ;IACR,OAAO;IACP,SAAS;CACD,CAAC;AAMX,MAAM,aAAa,GAAG,iEAAiE,CAAC;AACxF,MAAM,WAAW,GAAG,2DAA2D,CAAC;AAChF,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAC9C,MAAM,mBAAmB,GAAG,8BAA8B,CAAC;AAE3D,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,oBAAoB,CAAC,UAA6B;IACzD,OAAO,CAAC,GAAG,oBAAoB,EAAE,GAAG,UAAU,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACpG,CAAC;AAED,SAAS,YAAY,CAAC,GAAW,EAAE,WAA8B;IAC/D,MAAM,UAAU,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IACrC,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS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AAC,KAAK,IAAI,EACrC,CAAC;QACD,MAAM,GAAG,WAAW,CAAC,KAA0C,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IAC3F,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,cAAc,CAAC;IAC1B,CAAC;IAED,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACxB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,WAAW,CAClB,UAA6C,EAC7C,WAA8B,EAC9B,SAA0B;IAE1B,MAAM,QAAQ,GAA4B,EAAE,CAAC;IAE7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACtD,QAAQ,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,EAAE,WAAW,CAAC;YAC5C,CAAC,CAAC,cAAc;YAChB,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,UAA6C,EAC7C,UAA2B,EAAE;IAE7B,MAAM,WAAW,GAAG,oBAAoB,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;IACpE,MAAM,SAAS,GAAG,IAAI,OAAO,EAAE,CAAC;IAChC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC1B,OAAO,WAAW,CAAC,UAAU,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;AACzD,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { AnalyticsStorage } from './types.js';
2
+ /** Small dependency-free storage useful as the default and in tests. */
3
+ export declare class InMemoryAnalyticsStorage implements AnalyticsStorage {
4
+ #private;
5
+ constructor(initialValues?: Readonly<Record<string, string>>);
6
+ getItem(key: string): string | undefined;
7
+ setItem(key: string, value: string): void;
8
+ removeItem(key: string): void;
9
+ snapshot(): Readonly<Record<string, string>>;
10
+ }
11
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,wEAAwE;AACxE,qBAAa,wBAAyB,YAAW,gBAAgB;;gBAG5C,aAAa,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IAMhE,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIxC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIzC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAI7B,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAGpD"}
@@ -0,0 +1,22 @@
1
+ /** Small dependency-free storage useful as the default and in tests. */
2
+ export class InMemoryAnalyticsStorage {
3
+ #values = new Map();
4
+ constructor(initialValues = {}) {
5
+ for (const [key, value] of Object.entries(initialValues)) {
6
+ this.#values.set(key, value);
7
+ }
8
+ }
9
+ getItem(key) {
10
+ return this.#values.get(key);
11
+ }
12
+ setItem(key, value) {
13
+ this.#values.set(key, value);
14
+ }
15
+ removeItem(key) {
16
+ this.#values.delete(key);
17
+ }
18
+ snapshot() {
19
+ return Object.fromEntries(this.#values);
20
+ }
21
+ }
22
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAEA,wEAAwE;AACxE,MAAM,OAAO,wBAAwB;IAC1B,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE7C,YAAmB,gBAAkD,EAAE;QACrE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;YACzD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAEM,OAAO,CAAC,GAAW;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAEM,OAAO,CAAC,GAAW,EAAE,KAAa;QACvC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC/B,CAAC;IAEM,UAAU,CAAC,GAAW;QAC3B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAEM,QAAQ;QACb,OAAO,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ import type { AnalyticsEnvelope, AnalyticsEvent, Transport } from './types.js';
2
+ /** A production-safe transport that intentionally discards every command. */
3
+ export declare class NoopTransport<E extends AnalyticsEvent = AnalyticsEvent> implements Transport<E> {
4
+ send(envelopes: readonly AnalyticsEnvelope<E>[]): void;
5
+ }
6
+ /** An inspectable transport intended for unit tests and local development. */
7
+ export declare class InMemoryTransport<E extends AnalyticsEvent = AnalyticsEvent> implements Transport<E> {
8
+ #private;
9
+ get envelopes(): readonly AnalyticsEnvelope<E>[];
10
+ send(envelopes: readonly AnalyticsEnvelope<E>[]): void;
11
+ clear(): void;
12
+ }
13
+ //# sourceMappingURL=transports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transports.d.ts","sourceRoot":"","sources":["../src/transports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE/E,6EAA6E;AAC7E,qBAAa,aAAa,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,CAAE,YAAW,SAAS,CAAC,CAAC,CAAC;IACpF,IAAI,CAAC,SAAS,EAAE,SAAS,iBAAiB,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI;CAG9D;AAED,8EAA8E;AAC9E,qBAAa,iBAAiB,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,CAAE,YAAW,SAAS,CAAC,CAAC,CAAC;;IAG/F,IAAW,SAAS,IAAI,SAAS,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAEtD;IAEM,IAAI,CAAC,SAAS,EAAE,SAAS,iBAAiB,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI;IAItD,KAAK,IAAI,IAAI;CAGrB"}
@@ -0,0 +1,20 @@
1
+ /** A production-safe transport that intentionally discards every command. */
2
+ export class NoopTransport {
3
+ send(envelopes) {
4
+ void envelopes;
5
+ }
6
+ }
7
+ /** An inspectable transport intended for unit tests and local development. */
8
+ export class InMemoryTransport {
9
+ #envelopes = [];
10
+ get envelopes() {
11
+ return [...this.#envelopes];
12
+ }
13
+ send(envelopes) {
14
+ this.#envelopes.push(...envelopes);
15
+ }
16
+ clear() {
17
+ this.#envelopes.length = 0;
18
+ }
19
+ }
20
+ //# sourceMappingURL=transports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transports.js","sourceRoot":"","sources":["../src/transports.ts"],"names":[],"mappings":"AAEA,6EAA6E;AAC7E,MAAM,OAAO,aAAa;IACjB,IAAI,CAAC,SAA0C;QACpD,KAAK,SAAS,CAAC;IACjB,CAAC;CACF;AAED,8EAA8E;AAC9E,MAAM,OAAO,iBAAiB;IACnB,UAAU,GAA2B,EAAE,CAAC;IAEjD,IAAW,SAAS;QAClB,OAAO,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC;IAEM,IAAI,CAAC,SAA0C;QACpD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC;IACrC,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,100 @@
1
+ /** A product-owned, statically typed analytics event. */
2
+ export interface AnalyticsEvent {
3
+ readonly name: string;
4
+ readonly properties: object;
5
+ }
6
+ export type ConsentState = 'granted' | 'denied' | 'unknown';
7
+ /** Traits must be bounded product metadata, never user-provided free text or PII. */
8
+ export type SafeTraits = Readonly<Record<string, unknown>>;
9
+ export interface AnalyticsPort<E extends AnalyticsEvent> {
10
+ capture(event: E): void;
11
+ identify(userId: string, traits?: SafeTraits): void;
12
+ alias(anonymousId: string, userId: string): void;
13
+ reset(): void;
14
+ setConsent(value: ConsentState): void;
15
+ }
16
+ /** Required metadata stamped onto every captured event. */
17
+ export interface AnalyticsContext {
18
+ readonly schema_version: number;
19
+ readonly app: string;
20
+ readonly app_version: string;
21
+ readonly platform: string;
22
+ readonly environment: string;
23
+ readonly locale: string;
24
+ }
25
+ type EventPropertyName<Event extends AnalyticsEvent> = Extract<keyof Event['properties'], string>;
26
+ /**
27
+ * A complete per-event allowlist. Adding an event to a product union makes its
28
+ * allowlist entry a compile-time requirement.
29
+ */
30
+ export type EventAllowlist<E extends AnalyticsEvent> = {
31
+ readonly [Name in E['name']]: readonly EventPropertyName<Extract<E, {
32
+ name: Name;
33
+ }>>[];
34
+ };
35
+ interface BaseEnvelope {
36
+ readonly captured_at: string;
37
+ }
38
+ export interface CaptureEnvelope<E extends AnalyticsEvent = AnalyticsEvent> extends BaseEnvelope {
39
+ readonly type: 'capture';
40
+ readonly anonymous_id: string;
41
+ readonly user_id?: string;
42
+ readonly event: AnalyticsContext & {
43
+ readonly name: E['name'];
44
+ readonly properties: Readonly<Record<string, unknown>>;
45
+ };
46
+ }
47
+ export interface IdentifyEnvelope extends BaseEnvelope {
48
+ readonly type: 'identify';
49
+ readonly anonymous_id: string;
50
+ readonly user_id: string;
51
+ readonly traits?: SafeTraits;
52
+ }
53
+ export interface AliasEnvelope extends BaseEnvelope {
54
+ readonly type: 'alias';
55
+ readonly anonymous_id: string;
56
+ readonly user_id: string;
57
+ }
58
+ export interface ResetEnvelope extends BaseEnvelope {
59
+ readonly type: 'reset';
60
+ readonly previous_anonymous_id: string;
61
+ readonly previous_user_id?: string;
62
+ }
63
+ /** Provider-neutral commands delivered in ordering-preserving batches. */
64
+ export type AnalyticsEnvelope<E extends AnalyticsEvent = AnalyticsEvent> = CaptureEnvelope<E> | IdentifyEnvelope | AliasEnvelope | ResetEnvelope;
65
+ export interface Transport<E extends AnalyticsEvent = AnalyticsEvent> {
66
+ send(envelopes: readonly AnalyticsEnvelope<E>[]): Promise<void> | void;
67
+ /** Purges provider-owned queued commands after consent is denied. */
68
+ clearPending?(): Promise<void> | void;
69
+ }
70
+ /** Synchronous by design so consent can be applied before the first capture call. */
71
+ export interface AnalyticsStorage {
72
+ getItem(key: string): string | undefined;
73
+ setItem(key: string, value: string): void;
74
+ removeItem(key: string): void;
75
+ }
76
+ export interface TransportFailure<E extends AnalyticsEvent = AnalyticsEvent> {
77
+ readonly error: unknown;
78
+ readonly envelopes: readonly AnalyticsEnvelope<E>[];
79
+ readonly attempts: number;
80
+ }
81
+ export interface AnalyticsClientOptions<E extends AnalyticsEvent> {
82
+ readonly context: AnalyticsContext;
83
+ readonly allowlist: EventAllowlist<E>;
84
+ readonly transport?: Transport<E>;
85
+ readonly storage?: AnalyticsStorage;
86
+ readonly storageKeyPrefix?: string;
87
+ readonly uuidFactory?: () => string;
88
+ readonly blockedKeys?: readonly string[];
89
+ readonly maxQueueSize?: number;
90
+ readonly flushBatchSize?: number;
91
+ readonly flushIntervalMs?: number;
92
+ readonly maxRetries?: number;
93
+ readonly retryDelayMs?: number;
94
+ readonly development?: boolean;
95
+ readonly now?: () => Date;
96
+ readonly onWarning?: (message: string) => void;
97
+ readonly onTransportFailure?: (failure: TransportFailure<E>) => void;
98
+ }
99
+ export {};
100
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
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AAM,CAAC;IACnC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,MAAM,CAAC;IACpC,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CACtE"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@baukit/analytics-core",
3
+ "version": "0.1.0",
4
+ "description": "Provider-neutral, privacy-first product analytics port and safety policy.",
5
+ "license": "MIT",
6
+ "author": "Patrick Koss",
7
+ "homepage": "https://github.com/PatrickKoss/baukit#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/PatrickKoss/baukit.git",
11
+ "directory": "typescript/packages/analytics-core"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/PatrickKoss/baukit/issues"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "type": "module",
20
+ "engines": {
21
+ "node": ">=24.0.0"
22
+ },
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "devDependencies": {
36
+ "typescript": "6.0.3"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc -p tsconfig.json",
40
+ "test": "vitest run --config ../../vitest.config.ts",
41
+ "lint": "eslint src --max-warnings=0",
42
+ "format:check": "prettier --check src package.json tsconfig.json"
43
+ }
44
+ }