@macroui/event-tracker 1.3.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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +343 -0
  3. package/bin/event-tracker-suggest.mjs +141 -0
  4. package/bin/event-tracker.mjs +157 -0
  5. package/dist/event-tracker.cjs +3449 -0
  6. package/dist/event-tracker.js +3455 -0
  7. package/dist/event-tracker.min.js +1 -0
  8. package/dist/event-tracker.mjs +3402 -0
  9. package/dist/plugin/auto-track.cjs +201 -0
  10. package/dist/plugin/auto-track.mjs +199 -0
  11. package/dist/plugin/debug-sender.cjs +214 -0
  12. package/dist/plugin/debug-sender.mjs +211 -0
  13. package/dist/plugin/encrypt.cjs +284 -0
  14. package/dist/plugin/encrypt.mjs +275 -0
  15. package/dist/plugin/exposure.cjs +121 -0
  16. package/dist/plugin/exposure.mjs +119 -0
  17. package/dist/plugin/indexeddb-sender.cjs +94 -0
  18. package/dist/plugin/indexeddb-sender.mjs +92 -0
  19. package/dist/plugin/pageleave.cjs +74 -0
  20. package/dist/plugin/pageleave.mjs +72 -0
  21. package/dist/plugin/pageload.cjs +198 -0
  22. package/dist/plugin/pageload.mjs +196 -0
  23. package/dist/plugin/session-event.cjs +142 -0
  24. package/dist/plugin/session-event.mjs +140 -0
  25. package/dist/plugin/webview-bridge.cjs +111 -0
  26. package/dist/plugin/webview-bridge.mjs +109 -0
  27. package/dist/types/core/env.d.ts +10 -0
  28. package/dist/types/core/errors.d.ts +76 -0
  29. package/dist/types/core/failed-queue.d.ts +24 -0
  30. package/dist/types/core/identity-api.d.ts +6 -0
  31. package/dist/types/core/identity.d.ts +39 -0
  32. package/dist/types/core/instance-channel.d.ts +34 -0
  33. package/dist/types/core/lifecycle.d.ts +26 -0
  34. package/dist/types/core/logger.d.ts +13 -0
  35. package/dist/types/core/plugin.d.ts +60 -0
  36. package/dist/types/core/profile-api.d.ts +6 -0
  37. package/dist/types/core/profile-store.d.ts +23 -0
  38. package/dist/types/core/register-api.d.ts +22 -0
  39. package/dist/types/core/retry-policy.d.ts +33 -0
  40. package/dist/types/core/send-pipeline.d.ts +55 -0
  41. package/dist/types/core/signed-identity.d.ts +29 -0
  42. package/dist/types/core/stage.d.ts +48 -0
  43. package/dist/types/core/track-api.d.ts +6 -0
  44. package/dist/types/core/tracker.d.ts +130 -0
  45. package/dist/types/core/uuid.d.ts +4 -0
  46. package/dist/types/index.d.ts +40 -0
  47. package/dist/types/plugins/auto-track/index.d.ts +21 -0
  48. package/dist/types/plugins/debug-sender/index.d.ts +24 -0
  49. package/dist/types/plugins/encrypt/index.d.ts +56 -0
  50. package/dist/types/plugins/exposure/index.d.ts +18 -0
  51. package/dist/types/plugins/indexeddb-sender/index.d.ts +15 -0
  52. package/dist/types/plugins/pageleave/index.d.ts +12 -0
  53. package/dist/types/plugins/pageload/index.d.ts +14 -0
  54. package/dist/types/plugins/session-event/index.d.ts +14 -0
  55. package/dist/types/plugins/webview-bridge/index.d.ts +33 -0
  56. package/dist/types/presets/preset-properties.d.ts +25 -0
  57. package/dist/types/send/ajax-sender.d.ts +11 -0
  58. package/dist/types/send/batch-sender.d.ts +17 -0
  59. package/dist/types/send/beacon-sender.d.ts +10 -0
  60. package/dist/types/send/encode.d.ts +8 -0
  61. package/dist/types/send/image-sender.d.ts +10 -0
  62. package/dist/types/send/sender.d.ts +20 -0
  63. package/dist/types/storage/indexeddb-store.d.ts +14 -0
  64. package/dist/types/storage/store.d.ts +56 -0
  65. package/dist/types/types/common.d.ts +26 -0
  66. package/dist/types/types/config.d.ts +117 -0
  67. package/dist/types/types/constants.d.ts +110 -0
  68. package/dist/types/types/index.d.ts +25 -0
  69. package/dist/types/types.test-d.d.ts +5 -0
  70. package/dist/types.test-d.ts +103 -0
  71. package/package.json +218 -0
@@ -0,0 +1,103 @@
1
+ /**
2
+ * 公共 API 类型测试(tsd)
3
+ * 验证公开类型签名稳定
4
+ */
5
+
6
+ import { expectType, expectAssignable, expectNotAssignable } from 'tsd';
7
+ import { EventTracker } from './types/index.js';
8
+ import type { TrackerConfig, EventData, Callback, SendType, StorageType, ServerURL, StageName, HookName, Plugin, InstallContext, StageInterceptor, Lifecycle, SDKError } from './types/index.js';
9
+ import type { SignedIdentity } from './types/core/signed-identity.js';
10
+
11
+ // ============ EventTracker ============
12
+ expectType<EventTracker>(new EventTracker());
13
+ expectAssignable<{ track: Function }>(new EventTracker());
14
+ expectNotAssignable<EventTracker>({});
15
+
16
+ // ============ TrackerConfig ============
17
+ const cfg: TrackerConfig = {
18
+ app_id: 'demo',
19
+ server_url: 'https://api.test/sa',
20
+ send_type: 'image',
21
+ storage_type: 'memory',
22
+ debug: 1,
23
+ };
24
+ expectAssignable<TrackerConfig>(cfg);
25
+ expectAssignable<TrackerConfig>({ app_id: 'a', server_url: 'https://x' });
26
+
27
+ const single: ServerURL = 'https://api.test';
28
+ const multi: ServerURL = ['https://a.test', 'https://b.test'];
29
+ expectAssignable<ServerURL>(single);
30
+ expectAssignable<ServerURL>(multi);
31
+
32
+ // ============ EventData ============
33
+ const ev: EventData = {
34
+ type: 'track',
35
+ event: 'demo',
36
+ time: Date.now(),
37
+ distinct_id: 'd',
38
+ properties: { x: 1 },
39
+ };
40
+ expectAssignable<EventData>(ev);
41
+ expectAssignable<EventData>({
42
+ type: 'profile_set',
43
+ time: 1,
44
+ distinct_id: 'd',
45
+ properties: { name: 'Alice' },
46
+ });
47
+
48
+ // ============ Callback ============
49
+ const cb: Callback = (err: Error | null) => { void err; };
50
+ expectAssignable<Callback>(cb);
51
+
52
+ // ============ SendType / StorageType ============
53
+ const st: SendType = 'beacon';
54
+ expectAssignable<SendType>(st);
55
+ const sto: StorageType = 'localStorage';
56
+ expectAssignable<StorageType>(sto);
57
+
58
+ // ============ StageName / HookName ============
59
+ expectAssignable<StageName>('buildDataStage');
60
+ expectAssignable<StageName>('businessStage');
61
+ expectAssignable<StageName>('sendDataStage');
62
+ expectAssignable<HookName>('sdkReady');
63
+ expectAssignable<HookName>('sdkAfterInitPara');
64
+
65
+ // ============ Plugin / InstallContext ============
66
+ const plugin: Plugin = {
67
+ name: 'demo',
68
+ install(ctx: InstallContext) {
69
+ expectAssignable<TrackerConfig>(ctx.config);
70
+ expectAssignable<EventTracker>(ctx.sdk);
71
+ },
72
+ };
73
+ expectAssignable<Plugin>(plugin);
74
+
75
+ // ============ StageInterceptor ============
76
+ const interceptor: StageInterceptor<unknown> = {
77
+ name: 'demo',
78
+ priority: 10,
79
+ entry(ctx: { data: unknown; meta: any; cancellationToken: any; owner?: unknown }) {
80
+ expectAssignable<unknown>(ctx.data);
81
+ return undefined;
82
+ },
83
+ };
84
+ expectAssignable<StageInterceptor<unknown>>(interceptor);
85
+
86
+ // ============ Lifecycle(type-only) ============
87
+ expectAssignable<Lifecycle>({} as Lifecycle);
88
+
89
+ // ============ Errors ============
90
+ expectAssignable<SDKError>({} as SDKError);
91
+
92
+ // ============ SignedIdentity ============
93
+ const si: SignedIdentity = {
94
+ sign: (v: string) => v,
95
+ verify: (v: string, sig: string) => v === sig,
96
+ encode: (v: string) => v,
97
+ decode: (v: string) => v,
98
+ signAsync: async (v: string) => v,
99
+ verifyAsync: async (v: string, s: string) => v === s,
100
+ encodeAsync: async (v: string) => v,
101
+ decodeAsync: async (v: string) => v,
102
+ };
103
+ expectAssignable<SignedIdentity>(si);
package/package.json ADDED
@@ -0,0 +1,218 @@
1
+ {
2
+ "name": "@macroui/event-tracker",
3
+ "version": "1.3.0",
4
+ "description": "A self-developed web event tracking SDK, inspired by Sensors Analytics. Supports image/beacon/ajax/batch send, full auto-tracking, WebView bridge, and pluggable encryption.",
5
+ "keywords": [
6
+ "analytics",
7
+ "tracking",
8
+ "sdk",
9
+ "macroui",
10
+ "event",
11
+ "埋点"
12
+ ],
13
+ "author": "macroui",
14
+ "license": "MIT",
15
+ "type": "module",
16
+ "main": "./dist/event-tracker.cjs",
17
+ "module": "./dist/event-tracker.mjs",
18
+ "browser": "./dist/event-tracker.min.js",
19
+ "types": "./dist/types/index.d.ts",
20
+ "tsd": {
21
+ "directory": "dist",
22
+ "files": [
23
+ "types.test-d.ts"
24
+ ],
25
+ "typings": [
26
+ "types/index.d.ts",
27
+ "core/errors.d.ts",
28
+ "core/lifecycle.d.ts",
29
+ "core/signed-identity.d.ts"
30
+ ]
31
+ },
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/types/index.d.ts",
35
+ "import": "./dist/event-tracker.mjs",
36
+ "require": "./dist/event-tracker.cjs",
37
+ "browser": "./dist/event-tracker.min.js",
38
+ "default": "./dist/event-tracker.cjs"
39
+ },
40
+ "./plugin/encrypt": {
41
+ "types": "./dist/types/plugin/encrypt.d.ts",
42
+ "import": "./dist/plugin/encrypt.mjs",
43
+ "require": "./dist/plugin/encrypt.cjs"
44
+ },
45
+ "./plugin/auto-track": {
46
+ "types": "./dist/types/plugin/auto-track.d.ts",
47
+ "import": "./dist/plugin/auto-track.mjs",
48
+ "require": "./dist/plugin/auto-track.cjs"
49
+ },
50
+ "./plugin/webview-bridge": {
51
+ "types": "./dist/types/plugin/webview-bridge.d.ts",
52
+ "import": "./dist/plugin/webview-bridge.mjs",
53
+ "require": "./dist/plugin/webview-bridge.cjs"
54
+ },
55
+ "./plugin/pageload": {
56
+ "types": "./dist/types/plugin/pageload.d.ts",
57
+ "import": "./dist/plugin/pageload.mjs",
58
+ "require": "./dist/plugin/pageload.cjs"
59
+ },
60
+ "./plugin/pageleave": {
61
+ "types": "./dist/types/plugin/pageleave.d.ts",
62
+ "import": "./dist/plugin/pageleave.mjs",
63
+ "require": "./dist/plugin/pageleave.cjs"
64
+ },
65
+ "./plugin/exposure": {
66
+ "types": "./dist/types/plugin/exposure.d.ts",
67
+ "import": "./dist/plugin/exposure.mjs",
68
+ "require": "./dist/plugin/exposure.cjs"
69
+ },
70
+ "./plugin/session-event": {
71
+ "types": "./dist/types/plugin/session-event.d.ts",
72
+ "import": "./dist/plugin/session-event.mjs",
73
+ "require": "./dist/plugin/session-event.cjs"
74
+ },
75
+ "./plugin/debug-sender": {
76
+ "types": "./dist/types/plugin/debug-sender.d.ts",
77
+ "import": "./dist/plugin/debug-sender.mjs",
78
+ "require": "./dist/plugin/debug-sender.cjs"
79
+ },
80
+ "./plugin/indexeddb-sender": {
81
+ "types": "./dist/types/plugin/indexeddb-sender.d.ts",
82
+ "import": "./dist/plugin/indexeddb-sender.mjs",
83
+ "require": "./dist/plugin/indexeddb-sender.cjs"
84
+ },
85
+ "./plugin/otel-bridge": {
86
+ "types": "./dist/types/plugin/otel-bridge.d.ts",
87
+ "import": "./dist/plugin/otel-bridge.mjs",
88
+ "require": "./dist/plugin/otel-bridge.cjs"
89
+ },
90
+ "./plugin/experiment": {
91
+ "types": "./dist/types/plugin/experiment.d.ts",
92
+ "import": "./dist/plugin/experiment.mjs",
93
+ "require": "./dist/plugin/experiment.cjs"
94
+ },
95
+ "./plugin/predictive-batcher": {
96
+ "types": "./dist/types/plugin/predictive-batcher.d.ts",
97
+ "import": "./dist/plugin/predictive-batcher.mjs",
98
+ "require": "./dist/plugin/predictive-batcher.cjs"
99
+ },
100
+ "./plugin/otel-exporter": {
101
+ "types": "./dist/types/plugin/otel-exporter.d.ts",
102
+ "import": "./dist/plugin/otel-exporter.mjs",
103
+ "require": "./dist/plugin/otel-exporter.cjs"
104
+ },
105
+ "./plugin/pii-detector": {
106
+ "types": "./dist/types/plugin/pii-detector.d.ts",
107
+ "import": "./dist/plugin/pii-detector.mjs",
108
+ "require": "./dist/plugin/pii-detector.cjs"
109
+ },
110
+ "./plugin/privacy": {
111
+ "types": "./dist/types/plugin/privacy.d.ts",
112
+ "import": "./dist/plugin/privacy.mjs",
113
+ "require": "./dist/plugin/privacy.cjs"
114
+ },
115
+ "./plugin/cross-domain": {
116
+ "types": "./dist/types/plugin/cross-domain.d.ts",
117
+ "import": "./dist/plugin/cross-domain.mjs",
118
+ "require": "./dist/plugin/cross-domain.cjs"
119
+ },
120
+ "./plugin/schema-registry": {
121
+ "types": "./dist/types/plugin/schema-registry.d.ts",
122
+ "import": "./dist/plugin/schema-registry.mjs",
123
+ "require": "./dist/plugin/schema-registry.cjs"
124
+ },
125
+ "./plugin/rate-limiter": {
126
+ "types": "./dist/types/plugin/rate-limiter.d.ts",
127
+ "import": "./dist/plugin/rate-limiter.mjs",
128
+ "require": "./dist/plugin/rate-limiter.cjs"
129
+ },
130
+ "./plugin/csp-compliant": {
131
+ "types": "./dist/types/plugin/csp-compliant.d.ts",
132
+ "import": "./dist/plugin/csp-compliant.mjs",
133
+ "require": "./dist/plugin/csp-compliant.cjs"
134
+ },
135
+ "./plugin/audience-sync": {
136
+ "types": "./dist/types/plugin/audience-sync.d.ts",
137
+ "import": "./dist/plugin/audience-sync.mjs",
138
+ "require": "./dist/plugin/audience-sync.cjs"
139
+ },
140
+ "./edge": {
141
+ "types": "./dist/types/edge/index.d.ts",
142
+ "import": "./dist/edge/index.mjs",
143
+ "require": "./dist/edge/index.cjs"
144
+ },
145
+ "./federation": {
146
+ "import": "./dist/federation.mjs",
147
+ "require": "./dist/federation.cjs"
148
+ },
149
+ "./stats": {
150
+ "types": "./dist/types/stats.d.ts",
151
+ "import": "./dist/stats.mjs",
152
+ "require": "./dist/stats.cjs"
153
+ }
154
+ },
155
+ "files": [
156
+ "dist",
157
+ "README.md",
158
+ "LICENSE",
159
+ "bin"
160
+ ],
161
+ "bin": {
162
+ "event-tracker": "./bin/event-tracker.mjs",
163
+ "event-tracker-suggest": "./bin/event-tracker-suggest.mjs"
164
+ },
165
+ "scripts": {
166
+ "build:js": "rollup -c rollup.config.mjs",
167
+ "build:dts": "tsc -p tsconfig.dts.json",
168
+ "build": "npm run build:js && npm run build:dts",
169
+ "dev": "rollup -c rollup.config.mjs -w",
170
+ "test": "vitest run",
171
+ "test:watch": "vitest",
172
+ "test:cov": "vitest run --coverage",
173
+ "test:bench": "vitest run test/bench.test.ts",
174
+ "test:types": "tsc -p tsconfig.dts.json && cp src/types.test-d.ts dist/types.test-d.ts && tsd",
175
+ "typecheck": "tsc --noEmit",
176
+ "lint": "eslint 'src/**/*.ts' 'test/**/*.ts'",
177
+ "lint:fix": "eslint 'src/**/*.ts' 'test/**/*.ts' --fix",
178
+ "format": "prettier --write 'src/**/*.{ts,md}' 'test/**/*.ts' '*.md'",
179
+ "format:check": "prettier --check 'src/**/*.{ts,md}' 'test/**/*.ts' '*.md'",
180
+ "typedoc": "typedoc --options typedoc.json",
181
+ "visualize": "ANALYZE=1 rollup -c rollup.config.mjs",
182
+ "prepare": "husky",
183
+ "prepublishOnly": "npm run typecheck && npm test && npm run build"
184
+ },
185
+ "devDependencies": {
186
+ "@commitlint/cli": "^21.2.0",
187
+ "@commitlint/config-conventional": "^21.2.0",
188
+ "@rollup/plugin-commonjs": "^28.0.1",
189
+ "@rollup/plugin-node-resolve": "^15.3.0",
190
+ "@rollup/plugin-terser": "^0.4.4",
191
+ "@rollup/plugin-typescript": "^12.1.1",
192
+ "@types/jest": "^29.5.14",
193
+ "@types/node": "^22.10.1",
194
+ "@typescript-eslint/eslint-plugin": "^8.63.0",
195
+ "@typescript-eslint/parser": "^8.63.0",
196
+ "@vitest/coverage-v8": "^2.1.5",
197
+ "ajv": "^8.17.1",
198
+ "commitlint": "^19.8.1",
199
+ "eslint": "^9.39.4",
200
+ "fast-check": "^3.23.2",
201
+ "husky": "^9.1.7",
202
+ "jest": "^29.7.0",
203
+ "jest-environment-jsdom": "^30.4.1",
204
+ "prettier": "^3.9.4",
205
+ "rollup": "^4.28.0",
206
+ "rollup-plugin-visualizer": "^5.13.1",
207
+ "ts-jest": "^29.2.5",
208
+ "tsd": "^0.31.2",
209
+ "tslib": "^2.8.1",
210
+ "typedoc": "^0.27.6",
211
+ "typescript": "^5.7.2",
212
+ "vitest": "^2.1.5"
213
+ },
214
+ "engines": {
215
+ "node": ">=16"
216
+ },
217
+ "sideEffects": false
218
+ }