@wrelik/analytics 0.2.1 → 2.0.1

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.
@@ -1,18 +1,28 @@
1
1
 
2
- > @wrelik/analytics@0.2.1 build /home/runner/work/wrelik-kit/wrelik-kit/packages/analytics
3
- > tsup src/index.ts src/react-native.ts --format cjs,esm --clean
2
+ > @wrelik/analytics@2.0.1 build /Users/lee/Projects/wrelik-kit/packages/analytics
3
+ > tsup src/server/index.ts src/client/index.ts src/shared/index.ts --format cjs,esm --dts --clean
4
4
 
5
- CLI Building entry: src/index.ts, src/react-native.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.5.1
8
- CLI Target: es2022
9
- CLI Cleaning output folder
10
- CJS Build start
11
- ESM Build start
12
- ESM dist/index.mjs 937.00 B
13
- ESM dist/react-native.mjs 558.00 B
14
- ESM dist/chunk-ZASOR6XP.mjs 297.00 B
15
- ESM ⚡️ Build success in 55ms
16
- CJS dist/index.js 2.24 KB
17
- CJS dist/react-native.js 2.57 KB
18
- CJS ⚡️ Build success in 55ms
5
+ CLI Building entry: src/client/index.ts, src/server/index.ts, src/shared/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.1
8
+ CLI Target: es2022
9
+ CLI Cleaning output folder
10
+ CJS Build start
11
+ ESM Build start
12
+ ESM dist/shared/index.mjs 93.00 B
13
+ ESM dist/server/index.mjs 1.45 KB
14
+ ESM dist/client/index.mjs 381.00 B
15
+ ESM dist/chunk-HZPXP2CE.mjs 310.00 B
16
+ ESM ⚡️ Build success in 280ms
17
+ CJS dist/client/index.js 1.63 KB
18
+ CJS dist/server/index.js 2.85 KB
19
+ CJS dist/shared/index.js 1.32 KB
20
+ CJS ⚡️ Build success in 281ms
21
+ DTS Build start
22
+ DTS ⚡️ Build success in 1917ms
23
+ DTS dist/client/index.d.ts 545.00 B
24
+ DTS dist/server/index.d.ts 1.20 KB
25
+ DTS dist/shared/index.d.ts 88.00 B
26
+ DTS dist/client/index.d.mts 545.00 B
27
+ DTS dist/server/index.d.mts 1.20 KB
28
+ DTS dist/shared/index.d.mts 88.00 B
@@ -0,0 +1,17 @@
1
+
2
+ > @wrelik/analytics@0.2.1 lint /Users/lee/Projects/wrelik-kit/packages/analytics
3
+ > eslint src/
4
+
5
+ Warning: React version was set to "detect" in eslint-plugin-react settings, but the "react" package is not installed. Assuming latest React version for linting.
6
+
7
+ /Users/lee/Projects/wrelik-kit/packages/analytics/src/client.test.ts
8
+ 3:1 warning 'posthog-js' import is restricted from being used. Please use @wrelik/analytics/client instead no-restricted-imports
9
+
10
+ /Users/lee/Projects/wrelik-kit/packages/analytics/src/client.ts
11
+ 5:1 warning 'posthog-js' import is restricted from being used. Please use @wrelik/analytics/client instead no-restricted-imports
12
+
13
+ /Users/lee/Projects/wrelik-kit/packages/analytics/src/shared.ts
14
+ 18:18 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
15
+
16
+ ✖ 3 problems (0 errors, 3 warnings)
17
+
@@ -0,0 +1,15 @@
1
+
2
+ > @wrelik/analytics@2.0.1 test /Users/lee/Projects/wrelik-kit/packages/analytics
3
+ > vitest run --passWithNoTests
4
+
5
+
6
+  RUN  v4.1.2 /Users/lee/Projects/wrelik-kit/packages/analytics
7
+
8
+ ✓ src/shared/index.test.ts (2 tests) 6ms
9
+ ✓ src/server/index.test.ts (2 tests) 141ms
10
+
11
+  Test Files  2 passed (2)
12
+  Tests  4 passed (4)
13
+  Start at  20:04:57
14
+  Duration  1.38s (transform 641ms, setup 0ms, import 657ms, tests 148ms, environment 0ms)
15
+
@@ -0,0 +1,4 @@
1
+
2
+ > @wrelik/analytics@2.0.0 typecheck /Users/lee/Projects/wrelik-kit/packages/analytics
3
+ > tsc --noEmit
4
+
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @wrelik/analytics
2
2
 
3
+ ## 2.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 3262454: Upgrade runtime SDK and workspace tooling dependencies to latest compatible versions, including Clerk, Sentry, AWS SDK, Inngest, Resend, Upstash, Zod, TypeScript, Turbo, Vitest, TSUP, and ESLint.
8
+
9
+ Adopt root ESLint flat config and align wrapper peer ranges for updated SDK majors while preserving package export paths. Also apply a patched transitive Next.js resolution to close audit findings and keep production audit clean.
10
+
11
+ Note: Vite is pinned to the latest 7.x line for runtime compatibility in this environment; this avoids current rolldown native-binding failures seen with Vite 8 under Node 20.18.0.
12
+
13
+ Breaking change: `@wrelik/auth` and `@wrelik/clerk-next` now require `@clerk/nextjs@7.x` via updated peer ranges (`>=7 <8`). Consumers on Clerk v4-v6 must upgrade to Clerk v7 before adopting these versions.
14
+
15
+ - Updated dependencies [3262454]
16
+ - @wrelik/errors@2.0.1
17
+
18
+ ## 2.0.0
19
+
20
+ ### Major Changes
21
+
22
+ - 818ed58: Refactor runtime packages to strict subpath exports (`/server`, `/client`, `/shared`) with side-effect free entrypoints and hard CI/runtime boundary enforcement.
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies [818ed58]
27
+ - @wrelik/errors@2.0.0
28
+
3
29
  ## 0.2.1
4
30
 
5
31
  ### Patch Changes
@@ -1,5 +1,5 @@
1
- // src/shared.ts
2
- import { ValidationError } from "@wrelik/errors";
1
+ // src/shared/index.ts
2
+ import { ValidationError } from "@wrelik/errors/shared";
3
3
  function validateEventName(event) {
4
4
  const parts = event.split(".");
5
5
  if (parts.length < 3) {
@@ -0,0 +1,11 @@
1
+ interface AnalyticsClient {
2
+ identify: (userId: string, traits?: Record<string, unknown>) => void;
3
+ capture: (event: string, properties?: Record<string, unknown>) => void;
4
+ }
5
+ interface AnalyticsClientAdapter {
6
+ identify?: (userId: string, traits?: Record<string, unknown>) => void;
7
+ capture?: (event: string, properties?: Record<string, unknown>) => void;
8
+ }
9
+ declare function createAnalyticsClient(adapter: AnalyticsClientAdapter): AnalyticsClient;
10
+
11
+ export { type AnalyticsClient, type AnalyticsClientAdapter, createAnalyticsClient };
@@ -0,0 +1,11 @@
1
+ interface AnalyticsClient {
2
+ identify: (userId: string, traits?: Record<string, unknown>) => void;
3
+ capture: (event: string, properties?: Record<string, unknown>) => void;
4
+ }
5
+ interface AnalyticsClientAdapter {
6
+ identify?: (userId: string, traits?: Record<string, unknown>) => void;
7
+ capture?: (event: string, properties?: Record<string, unknown>) => void;
8
+ }
9
+ declare function createAnalyticsClient(adapter: AnalyticsClientAdapter): AnalyticsClient;
10
+
11
+ export { type AnalyticsClient, type AnalyticsClientAdapter, createAnalyticsClient };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/client/index.ts
21
+ var client_exports = {};
22
+ __export(client_exports, {
23
+ createAnalyticsClient: () => createAnalyticsClient
24
+ });
25
+ module.exports = __toCommonJS(client_exports);
26
+
27
+ // src/shared/index.ts
28
+ var import_shared = require("@wrelik/errors/shared");
29
+ function validateEventName(event) {
30
+ const parts = event.split(".");
31
+ if (parts.length < 3) {
32
+ throw new import_shared.ValidationError(`Event name "${event}" must follow "app.action.object" format`);
33
+ }
34
+ }
35
+
36
+ // src/client/index.ts
37
+ function createAnalyticsClient(adapter) {
38
+ return {
39
+ identify(userId, traits) {
40
+ adapter.identify?.(userId, traits);
41
+ },
42
+ capture(event, properties = {}) {
43
+ validateEventName(event);
44
+ adapter.capture?.(event, properties);
45
+ }
46
+ };
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ createAnalyticsClient
51
+ });
@@ -0,0 +1,19 @@
1
+ import {
2
+ validateEventName
3
+ } from "../chunk-HZPXP2CE.mjs";
4
+
5
+ // src/client/index.ts
6
+ function createAnalyticsClient(adapter) {
7
+ return {
8
+ identify(userId, traits) {
9
+ adapter.identify?.(userId, traits);
10
+ },
11
+ capture(event, properties = {}) {
12
+ validateEventName(event);
13
+ adapter.capture?.(event, properties);
14
+ }
15
+ };
16
+ }
17
+ export {
18
+ createAnalyticsClient
19
+ };
@@ -0,0 +1,28 @@
1
+ interface AnalyticsServer {
2
+ identify: (userId: string, traits: Record<string, unknown>) => void;
3
+ capture: (event: string, properties?: Record<string, unknown>, options?: {
4
+ userId?: string;
5
+ }) => void;
6
+ shutdown: () => void | Promise<void>;
7
+ }
8
+ declare function createAnalyticsServer(apiKey: string, host?: string): AnalyticsServer;
9
+ /**
10
+ * @deprecated Temporary DRX compatibility singleton. Prefer createAnalyticsServer(...) and explicit dependency wiring.
11
+ */
12
+ declare function initAnalytics(apiKey: string, host?: string): void;
13
+ /**
14
+ * @deprecated Temporary DRX compatibility singleton. Prefer createAnalyticsServer(...).identify(...)
15
+ */
16
+ declare function identify(userId: string, traits: Record<string, unknown>): void;
17
+ /**
18
+ * @deprecated Temporary DRX compatibility singleton. Prefer createAnalyticsServer(...).capture(...)
19
+ */
20
+ declare function capture(event: string, properties?: Record<string, unknown>, options?: {
21
+ userId?: string;
22
+ }): void;
23
+ /**
24
+ * @deprecated Temporary DRX compatibility singleton. Prefer createAnalyticsServer(...).shutdown()
25
+ */
26
+ declare function shutdown(): Promise<void>;
27
+
28
+ export { type AnalyticsServer, capture, createAnalyticsServer, identify, initAnalytics, shutdown };
@@ -0,0 +1,28 @@
1
+ interface AnalyticsServer {
2
+ identify: (userId: string, traits: Record<string, unknown>) => void;
3
+ capture: (event: string, properties?: Record<string, unknown>, options?: {
4
+ userId?: string;
5
+ }) => void;
6
+ shutdown: () => void | Promise<void>;
7
+ }
8
+ declare function createAnalyticsServer(apiKey: string, host?: string): AnalyticsServer;
9
+ /**
10
+ * @deprecated Temporary DRX compatibility singleton. Prefer createAnalyticsServer(...) and explicit dependency wiring.
11
+ */
12
+ declare function initAnalytics(apiKey: string, host?: string): void;
13
+ /**
14
+ * @deprecated Temporary DRX compatibility singleton. Prefer createAnalyticsServer(...).identify(...)
15
+ */
16
+ declare function identify(userId: string, traits: Record<string, unknown>): void;
17
+ /**
18
+ * @deprecated Temporary DRX compatibility singleton. Prefer createAnalyticsServer(...).capture(...)
19
+ */
20
+ declare function capture(event: string, properties?: Record<string, unknown>, options?: {
21
+ userId?: string;
22
+ }): void;
23
+ /**
24
+ * @deprecated Temporary DRX compatibility singleton. Prefer createAnalyticsServer(...).shutdown()
25
+ */
26
+ declare function shutdown(): Promise<void>;
27
+
28
+ export { type AnalyticsServer, capture, createAnalyticsServer, identify, initAnalytics, shutdown };
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/server/index.ts
21
+ var server_exports = {};
22
+ __export(server_exports, {
23
+ capture: () => capture,
24
+ createAnalyticsServer: () => createAnalyticsServer,
25
+ identify: () => identify,
26
+ initAnalytics: () => initAnalytics,
27
+ shutdown: () => shutdown
28
+ });
29
+ module.exports = __toCommonJS(server_exports);
30
+ var import_posthog_node = require("posthog-node");
31
+
32
+ // src/shared/index.ts
33
+ var import_shared = require("@wrelik/errors/shared");
34
+ function validateEventName(event) {
35
+ const parts = event.split(".");
36
+ if (parts.length < 3) {
37
+ throw new import_shared.ValidationError(`Event name "${event}" must follow "app.action.object" format`);
38
+ }
39
+ }
40
+
41
+ // src/server/index.ts
42
+ function createAnalyticsServer(apiKey, host = "https://app.posthog.com") {
43
+ const client = new import_posthog_node.PostHog(apiKey, { host });
44
+ return {
45
+ identify(userId, traits) {
46
+ client.identify({
47
+ distinctId: userId,
48
+ properties: traits
49
+ });
50
+ },
51
+ capture(event, properties = {}, options) {
52
+ validateEventName(event);
53
+ if (!options?.userId) {
54
+ return;
55
+ }
56
+ client.capture({
57
+ distinctId: options.userId,
58
+ event,
59
+ properties
60
+ });
61
+ },
62
+ shutdown() {
63
+ return client.shutdown();
64
+ }
65
+ };
66
+ }
67
+ var analyticsSingleton = null;
68
+ function requireAnalyticsSingleton() {
69
+ if (!analyticsSingleton) {
70
+ throw new Error(
71
+ "@wrelik/analytics/server compatibility API is not initialized. Call initAnalytics(apiKey, host) before identify/capture/shutdown."
72
+ );
73
+ }
74
+ return analyticsSingleton;
75
+ }
76
+ function initAnalytics(apiKey, host) {
77
+ analyticsSingleton = createAnalyticsServer(apiKey, host);
78
+ }
79
+ function identify(userId, traits) {
80
+ requireAnalyticsSingleton().identify(userId, traits);
81
+ }
82
+ function capture(event, properties, options) {
83
+ requireAnalyticsSingleton().capture(event, properties, options);
84
+ }
85
+ async function shutdown() {
86
+ await Promise.resolve(requireAnalyticsSingleton().shutdown());
87
+ }
88
+ // Annotate the CommonJS export names for ESM import in node:
89
+ 0 && (module.exports = {
90
+ capture,
91
+ createAnalyticsServer,
92
+ identify,
93
+ initAnalytics,
94
+ shutdown
95
+ });
@@ -0,0 +1,59 @@
1
+ import {
2
+ validateEventName
3
+ } from "../chunk-HZPXP2CE.mjs";
4
+
5
+ // src/server/index.ts
6
+ import { PostHog } from "posthog-node";
7
+ function createAnalyticsServer(apiKey, host = "https://app.posthog.com") {
8
+ const client = new PostHog(apiKey, { host });
9
+ return {
10
+ identify(userId, traits) {
11
+ client.identify({
12
+ distinctId: userId,
13
+ properties: traits
14
+ });
15
+ },
16
+ capture(event, properties = {}, options) {
17
+ validateEventName(event);
18
+ if (!options?.userId) {
19
+ return;
20
+ }
21
+ client.capture({
22
+ distinctId: options.userId,
23
+ event,
24
+ properties
25
+ });
26
+ },
27
+ shutdown() {
28
+ return client.shutdown();
29
+ }
30
+ };
31
+ }
32
+ var analyticsSingleton = null;
33
+ function requireAnalyticsSingleton() {
34
+ if (!analyticsSingleton) {
35
+ throw new Error(
36
+ "@wrelik/analytics/server compatibility API is not initialized. Call initAnalytics(apiKey, host) before identify/capture/shutdown."
37
+ );
38
+ }
39
+ return analyticsSingleton;
40
+ }
41
+ function initAnalytics(apiKey, host) {
42
+ analyticsSingleton = createAnalyticsServer(apiKey, host);
43
+ }
44
+ function identify(userId, traits) {
45
+ requireAnalyticsSingleton().identify(userId, traits);
46
+ }
47
+ function capture(event, properties, options) {
48
+ requireAnalyticsSingleton().capture(event, properties, options);
49
+ }
50
+ async function shutdown() {
51
+ await Promise.resolve(requireAnalyticsSingleton().shutdown());
52
+ }
53
+ export {
54
+ capture,
55
+ createAnalyticsServer,
56
+ identify,
57
+ initAnalytics,
58
+ shutdown
59
+ };
@@ -0,0 +1,3 @@
1
+ declare function validateEventName(event: string): void;
2
+
3
+ export { validateEventName };
@@ -0,0 +1,3 @@
1
+ declare function validateEventName(event: string): void;
2
+
3
+ export { validateEventName };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/shared/index.ts
21
+ var shared_exports = {};
22
+ __export(shared_exports, {
23
+ validateEventName: () => validateEventName
24
+ });
25
+ module.exports = __toCommonJS(shared_exports);
26
+ var import_shared = require("@wrelik/errors/shared");
27
+ function validateEventName(event) {
28
+ const parts = event.split(".");
29
+ if (parts.length < 3) {
30
+ throw new import_shared.ValidationError(`Event name "${event}" must follow "app.action.object" format`);
31
+ }
32
+ }
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ validateEventName
36
+ });
@@ -0,0 +1,6 @@
1
+ import {
2
+ validateEventName
3
+ } from "../chunk-HZPXP2CE.mjs";
4
+ export {
5
+ validateEventName
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrelik/analytics",
3
- "version": "0.2.1",
3
+ "version": "2.0.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -9,38 +9,48 @@
9
9
  "url": "https://github.com/lwhite702/wrelik-kit.git",
10
10
  "directory": "packages/analytics"
11
11
  },
12
- "main": "./dist/index.js",
13
- "types": "./dist/index.d.ts",
12
+ "sideEffects": false,
14
13
  "exports": {
15
- ".": "./dist/index.js",
16
- "./react-native": "./dist/react-native.js"
14
+ "./server": {
15
+ "types": "./dist/server/index.d.ts",
16
+ "import": "./dist/server/index.mjs",
17
+ "require": "./dist/server/index.js"
18
+ },
19
+ "./client": {
20
+ "types": "./dist/client/index.d.ts",
21
+ "import": "./dist/client/index.mjs",
22
+ "require": "./dist/client/index.js"
23
+ },
24
+ "./shared": {
25
+ "types": "./dist/shared/index.d.ts",
26
+ "import": "./dist/shared/index.mjs",
27
+ "require": "./dist/shared/index.js"
28
+ },
29
+ "./package.json": "./package.json"
17
30
  },
18
31
  "dependencies": {
19
- "posthog-node": "^3.6.3",
20
- "posthog-react-native": "^2.10.1",
21
- "@wrelik/errors": "0.2.1"
32
+ "posthog-node": "^5.28.11",
33
+ "@wrelik/errors": "2.0.1"
22
34
  },
23
35
  "devDependencies": {
24
- "@types/node": "^25.2.0",
25
- "@types/react": "^19.2.10",
26
- "@types/react-native": "^0.73.0",
27
- "auth": "link:packages/auth",
28
- "config": "link:packages/config",
29
- "db": "link:packages/db",
30
- "email": "link:packages/email",
31
- "errors": "link:packages/errors",
32
- "eslint-config": "link:packages/eslint-config",
33
- "jobs": "link:packages/jobs",
34
- "storage": "link:packages/storage",
35
- "tsconfig": "link:packages/tsconfig",
36
- "tsup": "^8.0.1",
37
- "vitest": "^1.2.2",
38
- "@wrelik/eslint-config": "0.1.1",
39
- "@wrelik/tsconfig": "0.1.1"
36
+ "@types/node": "^25.5.2",
37
+ "tsup": "^8.5.1",
38
+ "vite": "^7.3.1",
39
+ "vitest": "^4.1.2",
40
+ "@wrelik/eslint-config": "0.1.2",
41
+ "@wrelik/tsconfig": "0.1.2"
42
+ },
43
+ "wrelik": {
44
+ "runtimes": [
45
+ "server",
46
+ "client",
47
+ "shared"
48
+ ]
40
49
  },
41
50
  "scripts": {
42
- "build": "tsup src/index.ts src/react-native.ts --format cjs,esm --clean",
51
+ "build": "tsup src/server/index.ts src/client/index.ts src/shared/index.ts --format cjs,esm --dts --clean",
43
52
  "lint": "eslint src/",
53
+ "typecheck": "tsc --noEmit",
44
54
  "test": "vitest run --passWithNoTests"
45
55
  }
46
56
  }
@@ -0,0 +1,25 @@
1
+ import { validateEventName } from '../shared';
2
+
3
+ export interface AnalyticsClient {
4
+ identify: (userId: string, traits?: Record<string, unknown>) => void;
5
+ capture: (event: string, properties?: Record<string, unknown>) => void;
6
+ }
7
+
8
+ export interface AnalyticsClientAdapter {
9
+ identify?: (userId: string, traits?: Record<string, unknown>) => void;
10
+ capture?: (event: string, properties?: Record<string, unknown>) => void;
11
+ }
12
+
13
+ export function createAnalyticsClient(adapter: AnalyticsClientAdapter): AnalyticsClient {
14
+
15
+ return {
16
+ identify(userId, traits) {
17
+ adapter.identify?.(userId, traits);
18
+ },
19
+
20
+ capture(event, properties = {}) {
21
+ validateEventName(event);
22
+ adapter.capture?.(event, properties);
23
+ },
24
+ };
25
+ }
@@ -0,0 +1,42 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest';
2
+
3
+ afterEach(() => {
4
+ vi.resetModules();
5
+ vi.clearAllMocks();
6
+ });
7
+
8
+ describe('@wrelik/analytics/server', () => {
9
+ it('compatibility singleton throws before initAnalytics', async () => {
10
+ const mod = await import('./index.js');
11
+ expect(() => mod.capture('drx.user.created', { plan: 'pro' }, { userId: 'u1' })).toThrow(/initAnalytics/i);
12
+ });
13
+
14
+ it('compatibility singleton delegates to the PostHog-backed server after initAnalytics', async () => {
15
+ const identify = vi.fn();
16
+ const capture = vi.fn();
17
+ const shutdown = vi.fn(async () => undefined);
18
+ const PostHog = vi.fn(function PostHogMock() {
19
+ return { identify, capture, shutdown };
20
+ });
21
+
22
+ vi.doMock('posthog-node', () => ({ PostHog }));
23
+
24
+ const mod = await import('./index.js');
25
+ mod.initAnalytics('ph_test', 'https://posthog.example');
26
+ mod.identify('u1', { role: 'admin' });
27
+ mod.capture('drx.user.created', { source: 'web' }, { userId: 'u1' });
28
+ await mod.shutdown();
29
+
30
+ expect(PostHog).toHaveBeenCalledWith('ph_test', { host: 'https://posthog.example' });
31
+ expect(identify).toHaveBeenCalledWith({
32
+ distinctId: 'u1',
33
+ properties: { role: 'admin' },
34
+ });
35
+ expect(capture).toHaveBeenCalledWith({
36
+ distinctId: 'u1',
37
+ event: 'drx.user.created',
38
+ properties: { source: 'web' },
39
+ });
40
+ expect(shutdown).toHaveBeenCalledTimes(1);
41
+ });
42
+ });
@@ -0,0 +1,82 @@
1
+ import { PostHog } from 'posthog-node';
2
+ import { validateEventName } from '../shared';
3
+
4
+ export interface AnalyticsServer {
5
+ identify: (userId: string, traits: Record<string, unknown>) => void;
6
+ capture: (event: string, properties?: Record<string, unknown>, options?: { userId?: string }) => void;
7
+ shutdown: () => void | Promise<void>;
8
+ }
9
+
10
+ export function createAnalyticsServer(apiKey: string, host = 'https://app.posthog.com'): AnalyticsServer {
11
+ const client = new PostHog(apiKey, { host });
12
+
13
+ return {
14
+ identify(userId, traits) {
15
+ client.identify({
16
+ distinctId: userId,
17
+ properties: traits,
18
+ });
19
+ },
20
+
21
+ capture(event, properties = {}, options) {
22
+ validateEventName(event);
23
+ if (!options?.userId) {
24
+ return;
25
+ }
26
+
27
+ client.capture({
28
+ distinctId: options.userId,
29
+ event,
30
+ properties,
31
+ });
32
+ },
33
+
34
+ shutdown() {
35
+ return client.shutdown();
36
+ },
37
+ };
38
+ }
39
+
40
+ let analyticsSingleton: AnalyticsServer | null = null;
41
+
42
+ function requireAnalyticsSingleton(): AnalyticsServer {
43
+ if (!analyticsSingleton) {
44
+ throw new Error(
45
+ '@wrelik/analytics/server compatibility API is not initialized. Call initAnalytics(apiKey, host) before identify/capture/shutdown.',
46
+ );
47
+ }
48
+
49
+ return analyticsSingleton;
50
+ }
51
+
52
+ /**
53
+ * @deprecated Temporary DRX compatibility singleton. Prefer createAnalyticsServer(...) and explicit dependency wiring.
54
+ */
55
+ export function initAnalytics(apiKey: string, host?: string): void {
56
+ analyticsSingleton = createAnalyticsServer(apiKey, host);
57
+ }
58
+
59
+ /**
60
+ * @deprecated Temporary DRX compatibility singleton. Prefer createAnalyticsServer(...).identify(...)
61
+ */
62
+ export function identify(userId: string, traits: Record<string, unknown>): void {
63
+ requireAnalyticsSingleton().identify(userId, traits);
64
+ }
65
+
66
+ /**
67
+ * @deprecated Temporary DRX compatibility singleton. Prefer createAnalyticsServer(...).capture(...)
68
+ */
69
+ export function capture(
70
+ event: string,
71
+ properties?: Record<string, unknown>,
72
+ options?: { userId?: string },
73
+ ): void {
74
+ requireAnalyticsSingleton().capture(event, properties, options);
75
+ }
76
+
77
+ /**
78
+ * @deprecated Temporary DRX compatibility singleton. Prefer createAnalyticsServer(...).shutdown()
79
+ */
80
+ export async function shutdown(): Promise<void> {
81
+ await Promise.resolve(requireAnalyticsSingleton().shutdown());
82
+ }
@@ -0,0 +1,12 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { validateEventName } from './index';
3
+
4
+ describe('@wrelik/analytics/shared', () => {
5
+ it('accepts valid event names', () => {
6
+ expect(() => validateEventName('app.page.view')).not.toThrow();
7
+ });
8
+
9
+ it('rejects invalid event names', () => {
10
+ expect(() => validateEventName('invalid')).toThrow(/must follow/);
11
+ });
12
+ });
@@ -1,6 +1,6 @@
1
- import { ValidationError } from '@wrelik/errors';
1
+ import { ValidationError } from '@wrelik/errors/shared';
2
2
 
3
- export function validateEventName(event: string) {
3
+ export function validateEventName(event: string): void {
4
4
  const parts = event.split('.');
5
5
  if (parts.length < 3) {
6
6
  throw new ValidationError(`Event name "${event}" must follow "app.action.object" format`);
package/tsconfig.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "extends": "@wrelik/tsconfig/node.json",
3
3
  "compilerOptions": {
4
- "outDir": "dist", "skipLibCheck": true
4
+ "outDir": "dist",
5
+ "skipLibCheck": true,
6
+ "lib": ["DOM", "DOM.Iterable", "ES2022"]
5
7
  },
6
8
  "include": ["src"]
7
9
  }
package/dist/index.js DELETED
@@ -1,78 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- capture: () => capture,
24
- identify: () => identify,
25
- initAnalytics: () => initAnalytics,
26
- shutdown: () => shutdown
27
- });
28
- module.exports = __toCommonJS(index_exports);
29
- var import_posthog_node = require("posthog-node");
30
-
31
- // src/shared.ts
32
- var import_errors = require("@wrelik/errors");
33
- function validateEventName(event) {
34
- const parts = event.split(".");
35
- if (parts.length < 3) {
36
- throw new import_errors.ValidationError(`Event name "${event}" must follow "app.action.object" format`);
37
- }
38
- }
39
-
40
- // src/index.ts
41
- var client = null;
42
- function initAnalytics(apiKey, host = "https://app.posthog.com") {
43
- client = new import_posthog_node.PostHog(apiKey, { host });
44
- }
45
- function getClient(safe = false) {
46
- if (!client && !safe) {
47
- throw new Error("Analytics not initialized. Call initAnalytics first.");
48
- }
49
- return client;
50
- }
51
- function identify(userId, traits) {
52
- getClient(true)?.identify({
53
- distinctId: userId,
54
- properties: traits
55
- });
56
- }
57
- function capture(event, properties = {}, options) {
58
- validateEventName(event);
59
- if (!options?.userId) {
60
- console.warn("Analytics capture called without userId");
61
- return;
62
- }
63
- getClient(true)?.capture({
64
- distinctId: options.userId,
65
- event,
66
- properties
67
- });
68
- }
69
- async function shutdown() {
70
- await getClient(true)?.shutdown();
71
- }
72
- // Annotate the CommonJS export names for ESM import in node:
73
- 0 && (module.exports = {
74
- capture,
75
- identify,
76
- initAnalytics,
77
- shutdown
78
- });
package/dist/index.mjs DELETED
@@ -1,43 +0,0 @@
1
- import {
2
- validateEventName
3
- } from "./chunk-ZASOR6XP.mjs";
4
-
5
- // src/index.ts
6
- import { PostHog } from "posthog-node";
7
- var client = null;
8
- function initAnalytics(apiKey, host = "https://app.posthog.com") {
9
- client = new PostHog(apiKey, { host });
10
- }
11
- function getClient(safe = false) {
12
- if (!client && !safe) {
13
- throw new Error("Analytics not initialized. Call initAnalytics first.");
14
- }
15
- return client;
16
- }
17
- function identify(userId, traits) {
18
- getClient(true)?.identify({
19
- distinctId: userId,
20
- properties: traits
21
- });
22
- }
23
- function capture(event, properties = {}, options) {
24
- validateEventName(event);
25
- if (!options?.userId) {
26
- console.warn("Analytics capture called without userId");
27
- return;
28
- }
29
- getClient(true)?.capture({
30
- distinctId: options.userId,
31
- event,
32
- properties
33
- });
34
- }
35
- async function shutdown() {
36
- await getClient(true)?.shutdown();
37
- }
38
- export {
39
- capture,
40
- identify,
41
- initAnalytics,
42
- shutdown
43
- };
@@ -1,73 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/react-native.ts
31
- var react_native_exports = {};
32
- __export(react_native_exports, {
33
- capture: () => capture,
34
- identify: () => identify,
35
- initAnalytics: () => initAnalytics,
36
- shutdown: () => shutdown
37
- });
38
- module.exports = __toCommonJS(react_native_exports);
39
- var import_posthog_react_native = __toESM(require("posthog-react-native"));
40
-
41
- // src/shared.ts
42
- var import_errors = require("@wrelik/errors");
43
- function validateEventName(event) {
44
- const parts = event.split(".");
45
- if (parts.length < 3) {
46
- throw new import_errors.ValidationError(`Event name "${event}" must follow "app.action.object" format`);
47
- }
48
- }
49
-
50
- // src/react-native.ts
51
- function initAnalytics(apiKey, host = "https://app.posthog.com") {
52
- import_posthog_react_native.default.initAsync(apiKey, {
53
- host
54
- });
55
- }
56
- function identify(userId, traits) {
57
- import_posthog_react_native.default.identify(userId, traits);
58
- }
59
- function capture(event, properties = {}, options) {
60
- validateEventName(event);
61
- if (options?.userId) {
62
- }
63
- import_posthog_react_native.default.capture(event, properties);
64
- }
65
- async function shutdown() {
66
- }
67
- // Annotate the CommonJS export names for ESM import in node:
68
- 0 && (module.exports = {
69
- capture,
70
- identify,
71
- initAnalytics,
72
- shutdown
73
- });
@@ -1,28 +0,0 @@
1
- import {
2
- validateEventName
3
- } from "./chunk-ZASOR6XP.mjs";
4
-
5
- // src/react-native.ts
6
- import PostHog from "posthog-react-native";
7
- function initAnalytics(apiKey, host = "https://app.posthog.com") {
8
- PostHog.initAsync(apiKey, {
9
- host
10
- });
11
- }
12
- function identify(userId, traits) {
13
- PostHog.identify(userId, traits);
14
- }
15
- function capture(event, properties = {}, options) {
16
- validateEventName(event);
17
- if (options?.userId) {
18
- }
19
- PostHog.capture(event, properties);
20
- }
21
- async function shutdown() {
22
- }
23
- export {
24
- capture,
25
- identify,
26
- initAnalytics,
27
- shutdown
28
- };
package/src/index.ts DELETED
@@ -1,51 +0,0 @@
1
- /* eslint-disable no-restricted-imports */
2
- import { PostHog } from 'posthog-node';
3
- import { validateEventName } from './shared';
4
-
5
- let client: PostHog | null = null;
6
-
7
- export function initAnalytics(apiKey: string, host = 'https://app.posthog.com') {
8
- client = new PostHog(apiKey, { host });
9
- }
10
-
11
- function getClient(safe = false) {
12
- if (!client && !safe) {
13
- throw new Error('Analytics not initialized. Call initAnalytics first.');
14
- }
15
- return client;
16
- }
17
-
18
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- export function identify(userId: string, traits: Record<string, any>) {
20
- getClient(true)?.identify({
21
- distinctId: userId,
22
- properties: traits,
23
- });
24
- }
25
-
26
- export function capture(
27
- event: string,
28
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
- properties: Record<string, any> = {},
30
- options?: { userId?: string },
31
- ) {
32
- // Validate naming convention: app.action.object
33
- validateEventName(event);
34
-
35
- // If no user is provided, we can't capture server-side easily without anonymous ID
36
- // But usually servers have a userId context.
37
- if (!options?.userId) {
38
- console.warn('Analytics capture called without userId');
39
- return;
40
- }
41
-
42
- getClient(true)?.capture({
43
- distinctId: options.userId,
44
- event,
45
- properties,
46
- });
47
- }
48
-
49
- export async function shutdown() {
50
- await getClient(true)?.shutdown();
51
- }
@@ -1,36 +0,0 @@
1
- import PostHog from 'posthog-react-native';
2
- import { validateEventName } from './shared';
3
-
4
- export function initAnalytics(apiKey: string, host = 'https://app.posthog.com') {
5
- PostHog.initAsync(apiKey, {
6
- host,
7
- });
8
- }
9
-
10
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
- export function identify(userId: string, traits?: Record<string, any>) {
12
- // @ts-expect-error - PostHog RN types might be missing or different version
13
- PostHog.identify(userId, traits);
14
- }
15
-
16
- export function capture(
17
- event: string,
18
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- properties: Record<string, any> = {},
20
- options?: { userId?: string; tenantId?: string },
21
- ) {
22
- validateEventName(event);
23
-
24
- // merge options into properties if needed, or handle separately if PostHog RN supports it
25
- // Usually capturing with explicit distinctId requires identifying first
26
- if (options?.userId) {
27
- // Optional: re-identify? No, usually not done on every capture unless user switched
28
- }
29
-
30
- // @ts-expect-error - PostHog RN types might be missing or different version
31
- PostHog.capture(event, properties);
32
- }
33
-
34
- export async function shutdown() {
35
- // PostHog RN doesn't need explicit shutdown usually
36
- }
@@ -1,14 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { validateEventName } from './shared';
3
-
4
- describe('Analytics Shared', () => {
5
- it('validates correct event names', () => {
6
- expect(() => validateEventName('app.page.view')).not.toThrow();
7
- expect(() => validateEventName('user.signup.success')).not.toThrow();
8
- });
9
-
10
- it('throws on invalid event names', () => {
11
- expect(() => validateEventName('invalid')).toThrow(/must follow/);
12
- expect(() => validateEventName('almost.valid')).toThrow(/must follow/);
13
- });
14
- });