@byline/analytics 4.16.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 +373 -0
- package/README.md +41 -0
- package/dist/analytics.d.ts +40 -0
- package/dist/analytics.js +221 -0
- package/dist/analytics.test.node.d.ts +8 -0
- package/dist/analytics.test.node.js +216 -0
- package/dist/browser-boundary.test.node.d.ts +8 -0
- package/dist/browser-boundary.test.node.js +26 -0
- package/dist/config.d.ts +52 -0
- package/dist/config.js +92 -0
- package/dist/config.test.node.d.ts +8 -0
- package/dist/config.test.node.js +30 -0
- package/dist/crawler-user-agents.d.ts +8 -0
- package/dist/crawler-user-agents.js +11 -0
- package/dist/date.d.ts +13 -0
- package/dist/date.js +31 -0
- package/dist/dedupe.d.ts +18 -0
- package/dist/dedupe.js +37 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +15 -0
- package/dist/maintenance.d.ts +29 -0
- package/dist/maintenance.js +68 -0
- package/dist/maintenance.test.node.d.ts +8 -0
- package/dist/maintenance.test.node.js +46 -0
- package/dist/metrics.d.ts +18 -0
- package/dist/metrics.js +67 -0
- package/dist/normalize.d.ts +21 -0
- package/dist/normalize.js +90 -0
- package/dist/privacy-statement.d.ts +29 -0
- package/dist/privacy-statement.js +43 -0
- package/dist/privacy-statement.test.node.d.ts +8 -0
- package/dist/privacy-statement.test.node.js +32 -0
- package/dist/runtime.d.ts +15 -0
- package/dist/runtime.js +33 -0
- package/dist/types.d.ts +166 -0
- package/dist/types.js +8 -0
- package/dist/visitor.d.ts +10 -0
- package/dist/visitor.js +24 -0
- package/dist/visitor.test.node.d.ts +8 -0
- package/dist/visitor.test.node.js +19 -0
- package/package.json +74 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
/** Length-prefix both UTF-8 components so no pair can share an ambiguous encoding. */
|
|
9
|
+
export declare function canonicalVisitorIdentity(clientIp: string, userAgent: string): Uint8Array;
|
|
10
|
+
export declare function hashAnalyticsVisitor(dailySalt: Uint8Array, clientIp: string, userAgent: string): string;
|
package/dist/visitor.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
import { createHmac } from 'node:crypto';
|
|
9
|
+
/** Length-prefix both UTF-8 components so no pair can share an ambiguous encoding. */
|
|
10
|
+
export function canonicalVisitorIdentity(clientIp, userAgent) {
|
|
11
|
+
const ip = Buffer.from(clientIp, 'utf8');
|
|
12
|
+
const ua = Buffer.from(userAgent, 'utf8');
|
|
13
|
+
const output = Buffer.allocUnsafe(8 + ip.length + ua.length);
|
|
14
|
+
output.writeUInt32BE(ip.length, 0);
|
|
15
|
+
ip.copy(output, 4);
|
|
16
|
+
output.writeUInt32BE(ua.length, 4 + ip.length);
|
|
17
|
+
ua.copy(output, 8 + ip.length);
|
|
18
|
+
return output;
|
|
19
|
+
}
|
|
20
|
+
export function hashAnalyticsVisitor(dailySalt, clientIp, userAgent) {
|
|
21
|
+
return createHmac('sha256', dailySalt)
|
|
22
|
+
.update(canonicalVisitorIdentity(clientIp, userAgent))
|
|
23
|
+
.digest('hex');
|
|
24
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
import { describe, expect, it } from 'vitest';
|
|
9
|
+
import { canonicalVisitorIdentity, hashAnalyticsVisitor } from './visitor.js';
|
|
10
|
+
describe('visitor identity', () => {
|
|
11
|
+
it('length-prefixes components so concatenation cannot be ambiguous', () => {
|
|
12
|
+
expect(canonicalVisitorIdentity('ab', 'c')).not.toEqual(canonicalVisitorIdentity('a', 'bc'));
|
|
13
|
+
});
|
|
14
|
+
it('changes the visitor hash when the daily salt changes', () => {
|
|
15
|
+
const first = hashAnalyticsVisitor(new Uint8Array(32).fill(1), '203.0.113.1', 'Browser/1');
|
|
16
|
+
const second = hashAnalyticsVisitor(new Uint8Array(32).fill(2), '203.0.113.1', 'Browser/1');
|
|
17
|
+
expect(first).not.toBe(second);
|
|
18
|
+
});
|
|
19
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@byline/analytics",
|
|
3
|
+
"private": false,
|
|
4
|
+
"license": "MPL-2.0",
|
|
5
|
+
"version": "4.16.0",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=20.9.0"
|
|
8
|
+
},
|
|
9
|
+
"description": "Privacy-focused, database-neutral web analytics for Byline CMS",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"cms",
|
|
12
|
+
"headless cms",
|
|
13
|
+
"analytics",
|
|
14
|
+
"privacy",
|
|
15
|
+
"cookieless"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://github.com/Byline-CMS/bylinecms.dev",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/Byline-CMS/bylinecms.dev/issues"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/Byline-CMS/bylinecms.dev.git",
|
|
24
|
+
"directory": "packages/analytics"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "dist/index.js",
|
|
28
|
+
"index": "dist/index.js",
|
|
29
|
+
"types": "dist/index.d.ts",
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"require": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./config": {
|
|
38
|
+
"types": "./dist/config.d.ts",
|
|
39
|
+
"import": "./dist/config.js",
|
|
40
|
+
"require": "./dist/config.js"
|
|
41
|
+
},
|
|
42
|
+
"./package.json": "./package.json"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist"
|
|
46
|
+
],
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"isbot": "^5.2.1",
|
|
49
|
+
"@byline/core": "4.16.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@biomejs/biome": "2.5.9",
|
|
53
|
+
"@types/node": "^26.2.0",
|
|
54
|
+
"chokidar": "^5.0.0",
|
|
55
|
+
"chokidar-cli": "^3.0.0",
|
|
56
|
+
"npm-run-all": "^4.1.5",
|
|
57
|
+
"tsc-alias": "^1.9.2",
|
|
58
|
+
"typescript": "^7.0.2",
|
|
59
|
+
"vitest": "^4.1.11"
|
|
60
|
+
},
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "public",
|
|
63
|
+
"registry": "https://registry.npmjs.org/"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"dev": "chokidar 'src/**/*' -c 'npm-run-all build'",
|
|
67
|
+
"build": "tsc -p tsconfig.json && tsc-alias",
|
|
68
|
+
"clean": "node scripts/clean.js node_modules dist build .turbo",
|
|
69
|
+
"lint": "biome check --write --unsafe --diagnostic-level=error",
|
|
70
|
+
"test": "vitest run --mode=node",
|
|
71
|
+
"test:watch": "vitest --mode=node",
|
|
72
|
+
"typecheck": "tsc --noEmit"
|
|
73
|
+
}
|
|
74
|
+
}
|