@nodewrite-labs/analytics-sdk 0.0.0-stage → 0.2.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 +21 -0
- package/README.md +119 -2
- package/dist/chunk-F7BY2JQ3.js +9 -0
- package/dist/chunk-GVOESWHZ.js +270 -0
- package/dist/chunk-GWOVVKP3.js +179 -0
- package/dist/chunk-Q4JRXZ6M.js +132 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.js +219 -0
- package/dist/event-body-fpV2mYpY.d.ts +18 -0
- package/dist/event-store-BH-ZR3yD.d.ts +72 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +49 -0
- package/dist/options-Dpx2vs4R.d.ts +29 -0
- package/dist/payload/admin-view.d.ts +6 -0
- package/dist/payload/admin-view.js +290 -0
- package/dist/payload/index.d.ts +77 -0
- package/dist/payload/index.js +114 -0
- package/dist/payload/nav-link.d.ts +10 -0
- package/dist/payload/nav-link.js +8 -0
- package/dist/postgres/index.d.ts +17 -0
- package/dist/postgres/index.js +156 -0
- package/dist/server/index.d.ts +41 -0
- package/dist/server/index.js +9 -0
- package/package.json +90 -6
- package/src/postgres/schema.sql +12 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { c as RequestGeo } from '../options-Dpx2vs4R.js';
|
|
2
|
+
import { AnalyticsServerOptions } from '../index.js';
|
|
3
|
+
import { AnalyticsEventStore } from '../index.js';
|
|
4
|
+
|
|
5
|
+
/** Reads `country` and `city` from the request object the app passed in. */
|
|
6
|
+
declare function readRequestGeo(request: object): RequestGeo;
|
|
7
|
+
|
|
8
|
+
type AnalyticsHeaderBag = Headers | Record<string, string | string[] | undefined>;
|
|
9
|
+
|
|
10
|
+
interface AnalyticsEventRequest {
|
|
11
|
+
body?: unknown;
|
|
12
|
+
headers?: AnalyticsHeaderBag;
|
|
13
|
+
request?: Request;
|
|
14
|
+
country?: unknown;
|
|
15
|
+
city?: unknown;
|
|
16
|
+
}
|
|
17
|
+
interface RecordAnalyticsEventDeps {
|
|
18
|
+
store: AnalyticsEventStore;
|
|
19
|
+
options: AnalyticsServerOptions;
|
|
20
|
+
now?: () => string;
|
|
21
|
+
}
|
|
22
|
+
interface RecordAnalyticsEventResult {
|
|
23
|
+
status: number;
|
|
24
|
+
body: {
|
|
25
|
+
id: string;
|
|
26
|
+
} | null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Validates one analytics request and writes it through the store.
|
|
30
|
+
*
|
|
31
|
+
* A stored view or click returns status 200 and `{ id }`.
|
|
32
|
+
* Status 204 and a null body means analytics is disabled, clicks are off, or a duration was recorded.
|
|
33
|
+
* Status 400 and a null body means the request cannot be stored.
|
|
34
|
+
* `occurredAt` comes from `deps.now`, otherwise the server clock.
|
|
35
|
+
* Pass a Fetch `Request`, or `{ body, country, city }`. `request` is read when `body` is omitted.
|
|
36
|
+
* Country and city are the properties on that object. The JSON body is not a source for them.
|
|
37
|
+
*/
|
|
38
|
+
declare function recordAnalyticsEvent(request: AnalyticsEventRequest | Request, deps: RecordAnalyticsEventDeps): Promise<RecordAnalyticsEventResult>;
|
|
39
|
+
|
|
40
|
+
export { RequestGeo, readRequestGeo, recordAnalyticsEvent };
|
|
41
|
+
export type { AnalyticsEventRequest, AnalyticsHeaderBag, RecordAnalyticsEventDeps, RecordAnalyticsEventResult };
|
package/package.json
CHANGED
|
@@ -1,6 +1,90 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@nodewrite-labs/analytics-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@nodewrite-labs/analytics-sdk",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Analytics SDK for page views and named clicks, with Postgres storage and a Payload admin screen.",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"packageManager": "pnpm@12.11.2",
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=22"
|
|
11
|
+
},
|
|
12
|
+
"workspaces": [
|
|
13
|
+
"playground"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./client": {
|
|
24
|
+
"types": "./dist/client/index.d.ts",
|
|
25
|
+
"import": "./dist/client/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./server": {
|
|
28
|
+
"types": "./dist/server/index.d.ts",
|
|
29
|
+
"import": "./dist/server/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./postgres": {
|
|
32
|
+
"types": "./dist/postgres/index.d.ts",
|
|
33
|
+
"import": "./dist/postgres/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./payload": {
|
|
36
|
+
"types": "./dist/payload/index.d.ts",
|
|
37
|
+
"import": "./dist/payload/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./payload/admin-view": {
|
|
40
|
+
"types": "./dist/payload/admin-view.d.ts",
|
|
41
|
+
"import": "./dist/payload/admin-view.js"
|
|
42
|
+
},
|
|
43
|
+
"./payload/nav-link": {
|
|
44
|
+
"types": "./dist/payload/nav-link.d.ts",
|
|
45
|
+
"import": "./dist/payload/nav-link.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist",
|
|
50
|
+
"src/postgres/schema.sql",
|
|
51
|
+
"README.md"
|
|
52
|
+
],
|
|
53
|
+
"scripts": {
|
|
54
|
+
"typecheck": "tsc --noEmit",
|
|
55
|
+
"test": "vitest run",
|
|
56
|
+
"build": "tsup"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@payloadcms/next": "*",
|
|
60
|
+
"payload": "*",
|
|
61
|
+
"pg": "*"
|
|
62
|
+
},
|
|
63
|
+
"peerDependenciesMeta": {
|
|
64
|
+
"@payloadcms/next": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"payload": {
|
|
68
|
+
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"pg": {
|
|
71
|
+
"optional": true
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"devDependencies": {
|
|
75
|
+
"@payloadcms/next": "3.92.0",
|
|
76
|
+
"@types/node": "^22.20.5",
|
|
77
|
+
"@types/pg": "^8.23.1",
|
|
78
|
+
"@types/react": "19.2.14",
|
|
79
|
+
"esbuild": "^0.28.2",
|
|
80
|
+
"graphql": "^16.14.2",
|
|
81
|
+
"jsdom": "^30.1.3",
|
|
82
|
+
"payload": "3.92.0",
|
|
83
|
+
"pg": "^8.23.1",
|
|
84
|
+
"react": "^19.3.1",
|
|
85
|
+
"tsup": "^9.0.0",
|
|
86
|
+
"typescript": "6.0.3",
|
|
87
|
+
"vite": "^8.3.5",
|
|
88
|
+
"vitest": "^5.0.5"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS analytics_event (
|
|
2
|
+
id uuid primary key,
|
|
3
|
+
kind text not null,
|
|
4
|
+
path text not null,
|
|
5
|
+
locale text,
|
|
6
|
+
occurred_at timestamptz not null,
|
|
7
|
+
duration_seconds integer,
|
|
8
|
+
country text,
|
|
9
|
+
city text,
|
|
10
|
+
session_id text,
|
|
11
|
+
event_name text
|
|
12
|
+
);
|