@cogenta/analytics 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 ADDED
@@ -0,0 +1,373 @@
1
+ Mozilla Public License Version 2.0
2
+ ==================================
3
+
4
+ 1. Definitions
5
+ --------------
6
+
7
+ 1.1. "Contributor"
8
+ means each individual or legal entity that creates, contributes to
9
+ the creation of, or owns Covered Software.
10
+
11
+ 1.2. "Contributor Version"
12
+ means the combination of the Contributions of others (if any) used
13
+ by a Contributor and that particular Contributor's Contribution.
14
+
15
+ 1.3. "Contribution"
16
+ means Covered Software of a particular Contributor.
17
+
18
+ 1.4. "Covered Software"
19
+ means Source Code Form to which the initial Contributor has attached
20
+ the notice in Exhibit A, the Executable Form of such Source Code
21
+ Form, and Modifications of such Source Code Form, in each case
22
+ including portions thereof.
23
+
24
+ 1.5. "Incompatible With Secondary Licenses"
25
+ means
26
+
27
+ (a) that the initial Contributor has attached the notice described
28
+ in Exhibit B to the Covered Software; or
29
+
30
+ (b) that the Covered Software was made available under the terms of
31
+ version 1.1 or earlier of the License, but not also under the
32
+ terms of a Secondary License.
33
+
34
+ 1.6. "Executable Form"
35
+ means any form of the work other than Source Code Form.
36
+
37
+ 1.7. "Larger Work"
38
+ means a work that combines Covered Software with other material, in
39
+ a separate file or files, that is not Covered Software.
40
+
41
+ 1.8. "License"
42
+ means this document.
43
+
44
+ 1.9. "Licensable"
45
+ means having the right to grant, to the maximum extent possible,
46
+ whether at the time of the initial grant or subsequently, any and
47
+ all of the rights conveyed by this License.
48
+
49
+ 1.10. "Modifications"
50
+ means any of the following:
51
+
52
+ (a) any file in Source Code Form that results from an addition to,
53
+ deletion from, or modification of the contents of Covered
54
+ Software; or
55
+
56
+ (b) any new file in Source Code Form that contains any Covered
57
+ Software.
58
+
59
+ 1.11. "Patent Claims" of a Contributor
60
+ means any patent claim(s), including without limitation, method,
61
+ process, and apparatus claims, in any patent Licensable by such
62
+ Contributor that would be infringed, but for the grant of the
63
+ License, by the making, using, selling, offering for sale, having
64
+ made, import, or transfer of either its Contributions or its
65
+ Contributor Version.
66
+
67
+ 1.12. "Secondary License"
68
+ means either the GNU General Public License, Version 2.0, the GNU
69
+ Lesser General Public License, Version 2.1, the GNU Affero General
70
+ Public License, Version 3.0, or any later versions of those
71
+ licenses.
72
+
73
+ 1.13. "Source Code Form"
74
+ means the form of the work preferred for making modifications.
75
+
76
+ 1.14. "You" (or "Your")
77
+ means an individual or a legal entity exercising rights under this
78
+ License. For legal entities, "You" includes any entity that
79
+ controls, is controlled by, or is under common control with You. For
80
+ purposes of this definition, "control" means (a) the power, direct
81
+ or indirect, to cause the direction or management of such entity,
82
+ whether by contract or otherwise, or (b) ownership of more than
83
+ fifty percent (50%) of the outstanding shares or beneficial
84
+ ownership of such entity.
85
+
86
+ 2. License Grants and Conditions
87
+ --------------------------------
88
+
89
+ 2.1. Grants
90
+
91
+ Each Contributor hereby grants You a world-wide, royalty-free,
92
+ non-exclusive license:
93
+
94
+ (a) under intellectual property rights (other than patent or trademark)
95
+ Licensable by such Contributor to use, reproduce, make available,
96
+ modify, display, perform, distribute, and otherwise exploit its
97
+ Contributions, either on an unmodified basis, with Modifications, or
98
+ as part of a Larger Work; and
99
+
100
+ (b) under Patent Claims of such Contributor to make, use, sell, offer
101
+ for sale, have made, import, and otherwise transfer either its
102
+ Contributions or its Contributor Version.
103
+
104
+ 2.2. Effective Date
105
+
106
+ The licenses granted in Section 2.1 with respect to any Contribution
107
+ become effective for each Contribution on the date the Contributor first
108
+ distributes such Contribution.
109
+
110
+ 2.3. Limitations on Grant Scope
111
+
112
+ The licenses granted in this Section 2 are the only rights granted under
113
+ this License. No additional rights or licenses will be implied from the
114
+ distribution or licensing of Covered Software under this License.
115
+ Notwithstanding Section 2.1(b) above, no patent license is granted by a
116
+ Contributor:
117
+
118
+ (a) for any code that a Contributor has removed from Covered Software;
119
+ or
120
+
121
+ (b) for infringements caused by: (i) Your and any other third party's
122
+ modifications of Covered Software, or (ii) the combination of its
123
+ Contributions with other software (except as part of its Contributor
124
+ Version); or
125
+
126
+ (c) under Patent Claims infringed by Covered Software in the absence of
127
+ its Contributions.
128
+
129
+ This License does not grant any rights in the trademarks, service marks,
130
+ or logos of any Contributor (except as may be necessary to comply with
131
+ the notice requirements in Section 3.4).
132
+
133
+ 2.4. Subsequent Licenses
134
+
135
+ No Contributor makes additional grants as a result of Your choice to
136
+ distribute the Covered Software under a subsequent version of this
137
+ License (see Section 10.2) or under the terms of a Secondary License (if
138
+ permitted under the terms of Section 3.3).
139
+
140
+ 2.5. Representation
141
+
142
+ Each Contributor represents that the Contributor believes its
143
+ Contributions are its original creation(s) or it has sufficient rights
144
+ to grant the rights to its Contributions conveyed by this License.
145
+
146
+ 2.6. Fair Use
147
+
148
+ This License is not intended to limit any rights You have under
149
+ applicable copyright doctrines of fair use, fair dealing, or other
150
+ equivalents.
151
+
152
+ 2.7. Conditions
153
+
154
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155
+ in Section 2.1.
156
+
157
+ 3. Responsibilities
158
+ -------------------
159
+
160
+ 3.1. Distribution of Source Form
161
+
162
+ All distribution of Covered Software in Source Code Form, including any
163
+ Modifications that You create or to which You contribute, must be under
164
+ the terms of this License. You must inform recipients that the Source
165
+ Code Form of the Covered Software is governed by the terms of this
166
+ License, and how they can obtain a copy of this License. You may not
167
+ attempt to alter or restrict the recipients' rights in the Source Code
168
+ Form.
169
+
170
+ 3.2. Distribution of Executable Form
171
+
172
+ If You distribute Covered Software in Executable Form then:
173
+
174
+ (a) such Covered Software must also be made available in Source Code
175
+ Form, as described in Section 3.1, and You must inform recipients of
176
+ the Executable Form how they can obtain a copy of such Source Code
177
+ Form by reasonable means in a timely manner, at a charge no more
178
+ than the cost of distribution to the recipient; and
179
+
180
+ (b) You may distribute such Executable Form under the terms of this
181
+ License, or sublicense it under different terms, provided that the
182
+ license for the Executable Form does not attempt to limit or alter
183
+ the recipients' rights in the Source Code Form under this License.
184
+
185
+ 3.3. Distribution of a Larger Work
186
+
187
+ You may create and distribute a Larger Work under terms of Your choice,
188
+ provided that You also comply with the requirements of this License for
189
+ the Covered Software. If the Larger Work is a combination of Covered
190
+ Software with a work governed by one or more Secondary Licenses, and the
191
+ Covered Software is not Incompatible With Secondary Licenses, this
192
+ License permits You to additionally distribute such Covered Software
193
+ under the terms of such Secondary License(s), so that the recipient of
194
+ the Larger Work may, at their option, further distribute the Covered
195
+ Software under the terms of either this License or such Secondary
196
+ License(s).
197
+
198
+ 3.4. Notices
199
+
200
+ You may not remove or alter the substance of any license notices
201
+ (including copyright notices, patent notices, disclaimers of warranty,
202
+ or limitations of liability) contained within the Source Code Form of
203
+ the Covered Software, except that You may alter any license notices to
204
+ the extent required to remedy known factual inaccuracies.
205
+
206
+ 3.5. Application of Additional Terms
207
+
208
+ You may choose to offer, and to charge a fee for, warranty, support,
209
+ indemnity or liability obligations to one or more recipients of Covered
210
+ Software. However, You may do so only on Your own behalf, and not on
211
+ behalf of any Contributor. You must make it absolutely clear that any
212
+ such warranty, support, indemnity, or liability obligation is offered by
213
+ You alone, and You hereby agree to indemnify every Contributor for any
214
+ liability incurred by such Contributor as a result of warranty, support,
215
+ indemnity or liability terms You offer. You may include additional
216
+ disclaimers of warranty and limitations of liability specific to any
217
+ jurisdiction.
218
+
219
+ 4. Inability to Comply Due to Statute or Regulation
220
+ ---------------------------------------------------
221
+
222
+ If it is impossible for You to comply with any of the terms of this
223
+ License with respect to some or all of the Covered Software due to
224
+ statute, judicial order, or regulation then You must: (a) comply with
225
+ the terms of this License to the maximum extent possible; and (b)
226
+ describe the limitations and the code they affect. Such description must
227
+ be placed in a text file included with all distributions of the Covered
228
+ Software under this License. Except to the extent prohibited by statute
229
+ or regulation, such description must be sufficiently detailed for a
230
+ recipient of ordinary skill to be able to understand it.
231
+
232
+ 5. Termination
233
+ --------------
234
+
235
+ 5.1. The rights granted under this License will terminate automatically
236
+ if You fail to comply with any of its terms. However, if You become
237
+ compliant, then the rights granted under this License from a particular
238
+ Contributor are reinstated (a) provisionally, unless and until such
239
+ Contributor explicitly and finally terminates Your grants, and (b) on an
240
+ ongoing basis, if such Contributor fails to notify You of the
241
+ non-compliance by some reasonable means prior to 60 days after You have
242
+ come back into compliance. Moreover, Your grants from a particular
243
+ Contributor are reinstated on an ongoing basis if such Contributor
244
+ notifies You of the non-compliance by some reasonable means, this is the
245
+ first time You have received notice of non-compliance with this License
246
+ from such Contributor, and You become compliant prior to 30 days after
247
+ Your receipt of the notice.
248
+
249
+ 5.2. If You initiate litigation against any entity by asserting a patent
250
+ infringement claim (excluding declaratory judgment actions,
251
+ counter-claims, and cross-claims) alleging that a Contributor Version
252
+ directly or indirectly infringes any patent, then the rights granted to
253
+ You by any and all Contributors for the Covered Software under Section
254
+ 2.1 of this License shall terminate.
255
+
256
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257
+ end user license agreements (excluding distributors and resellers) which
258
+ have been validly granted by You or Your distributors under this License
259
+ prior to termination shall survive termination.
260
+
261
+ ************************************************************************
262
+ * *
263
+ * 6. Disclaimer of Warranty *
264
+ * ------------------------- *
265
+ * *
266
+ * Covered Software is provided under this License on an "as is" *
267
+ * basis, without warranty of any kind, either expressed, implied, or *
268
+ * statutory, including, without limitation, warranties that the *
269
+ * Covered Software is free of defects, merchantable, fit for a *
270
+ * particular purpose or non-infringing. The entire risk as to the *
271
+ * quality and performance of the Covered Software is with You. *
272
+ * Should any Covered Software prove defective in any respect, You *
273
+ * (not any Contributor) assume the cost of any necessary servicing, *
274
+ * repair, or correction. This disclaimer of warranty constitutes an *
275
+ * essential part of this License. No use of any Covered Software is *
276
+ * authorized under this License except under this disclaimer. *
277
+ * *
278
+ ************************************************************************
279
+
280
+ ************************************************************************
281
+ * *
282
+ * 7. Limitation of Liability *
283
+ * -------------------------- *
284
+ * *
285
+ * Under no circumstances and under no legal theory, whether tort *
286
+ * (including negligence), contract, or otherwise, shall any *
287
+ * Contributor, or anyone who distributes Covered Software as *
288
+ * permitted above, be liable to You for any direct, indirect, *
289
+ * special, incidental, or consequential damages of any character *
290
+ * including, without limitation, damages for lost profits, loss of *
291
+ * goodwill, work stoppage, computer failure or malfunction, or any *
292
+ * and all other commercial damages or losses, even if such party *
293
+ * shall have been informed of the possibility of such damages. This *
294
+ * limitation of liability shall not apply to liability for death or *
295
+ * personal injury resulting from such party's negligence to the *
296
+ * extent applicable law prohibits such limitation. Some *
297
+ * jurisdictions do not allow the exclusion or limitation of *
298
+ * incidental or consequential damages, so this exclusion and *
299
+ * limitation may not apply to You. *
300
+ * *
301
+ ************************************************************************
302
+
303
+ 8. Litigation
304
+ -------------
305
+
306
+ Any litigation relating to this License may be brought only in the
307
+ courts of a jurisdiction where the defendant maintains its principal
308
+ place of business and such litigation shall be governed by laws of that
309
+ jurisdiction, without reference to its conflict-of-law provisions.
310
+ Nothing in this Section shall prevent a party's ability to bring
311
+ cross-claims or counter-claims.
312
+
313
+ 9. Miscellaneous
314
+ ----------------
315
+
316
+ This License represents the complete agreement concerning the subject
317
+ matter hereof. If any provision of this License is held to be
318
+ unenforceable, such provision shall be reformed only to the extent
319
+ necessary to make it enforceable. Any law or regulation which provides
320
+ that the language of a contract shall be construed against the drafter
321
+ shall not be used to construe this License against a Contributor.
322
+
323
+ 10. Versions of the License
324
+ ---------------------------
325
+
326
+ 10.1. New Versions
327
+
328
+ Mozilla Foundation is the license steward. Except as provided in Section
329
+ 10.3, no one other than the license steward has the right to modify or
330
+ publish new versions of this License. Each version will be given a
331
+ distinguishing version number.
332
+
333
+ 10.2. Effect of New Versions
334
+
335
+ You may distribute the Covered Software under the terms of the version
336
+ of the License under which You originally received the Covered Software,
337
+ or under the terms of any subsequent version published by the license
338
+ steward.
339
+
340
+ 10.3. Modified Versions
341
+
342
+ If you create software not governed by this License, and you want to
343
+ create a new license for such software, you may create and use a
344
+ modified version of this License if you rename the license and remove
345
+ any references to the name of the license steward (except to note that
346
+ such modified license differs from this License).
347
+
348
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary
349
+ Licenses
350
+
351
+ If You choose to distribute Source Code Form that is Incompatible With
352
+ Secondary Licenses under the terms of this version of the License, the
353
+ notice described in Exhibit B of this License must be attached.
354
+
355
+ Exhibit A - Source Code Form License Notice
356
+ -------------------------------------------
357
+
358
+ This Source Code Form is subject to the terms of the Mozilla Public
359
+ License, v. 2.0. If a copy of the MPL was not distributed with this
360
+ file, You can obtain one at https://mozilla.org/MPL/2.0/.
361
+
362
+ If it is not possible or desirable to put the notice in a particular
363
+ file, then You may include the notice in a location (such as a LICENSE
364
+ file in a relevant directory) where a recipient would be likely to look
365
+ for such a notice.
366
+
367
+ You may add additional accurate notices of copyright ownership.
368
+
369
+ Exhibit B - "Incompatible With Secondary Licenses" Notice
370
+ ---------------------------------------------------------
371
+
372
+ This Source Code Form is "Incompatible With Secondary Licenses", as
373
+ defined by the Mozilla Public License, v. 2.0.
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Device category derived from a User-Agent, and nothing else kept from it.
3
+ *
4
+ * The raw header can carry very specific device/browser build strings and, on
5
+ * some vendors, near-unique combinations — close enough to a fingerprint that
6
+ * storing it defeats the point of the daily session hash (`session-hash.ts`).
7
+ * So the full string is reduced to one of four buckets *before* anything ever
8
+ * reaches a database row, and the caller never gets the original text back.
9
+ */
10
+ export declare const DEVICE_CATEGORIES: readonly ['desktop', 'mobile', 'tablet', 'other'];
11
+ export type DeviceCategory = (typeof DEVICE_CATEGORIES)[number];
12
+ /**
13
+ * Classifies a User-Agent string into a coarse device category.
14
+ *
15
+ * Order matters: a tablet UA usually also matches a mobile pattern (Android
16
+ * tablets carry "Android" without "Mobile"; iPads pre-iPadOS 13 said
17
+ * "iPad" outright), so tablet detection runs first.
18
+ */
19
+ export declare function classifyDevice(userAgent: string | null | undefined): DeviceCategory;
20
+ //# sourceMappingURL=device.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,YAAI,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAU,CAAA;AAElF,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE/D;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,cAAc,CAkCnF"}
package/dist/device.js ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Device category derived from a User-Agent, and nothing else kept from it.
3
+ *
4
+ * The raw header can carry very specific device/browser build strings and, on
5
+ * some vendors, near-unique combinations — close enough to a fingerprint that
6
+ * storing it defeats the point of the daily session hash (`session-hash.ts`).
7
+ * So the full string is reduced to one of four buckets *before* anything ever
8
+ * reaches a database row, and the caller never gets the original text back.
9
+ */
10
+ export const DEVICE_CATEGORIES = ['desktop', 'mobile', 'tablet', 'other'];
11
+ /**
12
+ * Classifies a User-Agent string into a coarse device category.
13
+ *
14
+ * Order matters: a tablet UA usually also matches a mobile pattern (Android
15
+ * tablets carry "Android" without "Mobile"; iPads pre-iPadOS 13 said
16
+ * "iPad" outright), so tablet detection runs first.
17
+ */
18
+ export function classifyDevice(userAgent) {
19
+ if (userAgent === null || userAgent === undefined || userAgent.trim().length === 0) {
20
+ return 'other';
21
+ }
22
+ const ua = userAgent.toLowerCase();
23
+ const isTablet = ua.includes('ipad') ||
24
+ ua.includes('tablet') ||
25
+ ua.includes('playbook') ||
26
+ ua.includes('kindle') ||
27
+ ua.includes('silk') ||
28
+ (ua.includes('android') && !ua.includes('mobile'));
29
+ if (isTablet)
30
+ return 'tablet';
31
+ const isMobile = ua.includes('mobi') ||
32
+ ua.includes('iphone') ||
33
+ ua.includes('ipod') ||
34
+ ua.includes('android') ||
35
+ ua.includes('windows phone') ||
36
+ ua.includes('blackberry');
37
+ if (isMobile)
38
+ return 'mobile';
39
+ const isDesktop = ua.includes('windows nt') ||
40
+ ua.includes('macintosh') ||
41
+ ua.includes('linux') ||
42
+ ua.includes('cros') ||
43
+ ua.includes('x11');
44
+ if (isDesktop)
45
+ return 'desktop';
46
+ return 'other';
47
+ }
48
+ //# sourceMappingURL=device.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device.js","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAU,CAAA;AAIlF;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,SAAoC;IACjE,IAAI,SAAS,KAAK,IAAI,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnF,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,MAAM,EAAE,GAAG,SAAS,CAAC,WAAW,EAAE,CAAA;IAElC,MAAM,QAAQ,GACZ,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC;QACnB,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACrB,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC;QACvB,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACrB,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC;QACnB,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAA;IACpD,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAA;IAE7B,MAAM,QAAQ,GACZ,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC;QACnB,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACrB,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC;QACnB,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC;QACtB,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;QAC5B,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAA;IAC3B,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAA;IAE7B,MAAM,SAAS,GACb,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC;QACzB,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC;QACxB,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC;QACpB,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC;QACnB,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACpB,IAAI,SAAS;QAAE,OAAO,SAAS,CAAA;IAE/B,OAAO,OAAO,CAAA;AAChB,CAAC"}
@@ -0,0 +1,10 @@
1
+ export type { DeviceCategory } from './device.js';
2
+ export { classifyDevice, DEVICE_CATEGORIES } from './device.js';
3
+ export { extractReferrerDomain } from './referrer.js';
4
+ export type { DailySaltStore } from './session-hash.js';
5
+ export { createDailySaltStore, hashSession, utcDateKey } from './session-hash.js';
6
+ export type { AnalyticsStore } from './store.js';
7
+ export { createAnalyticsStore, DEFAULT_SUMMARY_LIMIT } from './store.js';
8
+ export { ensureAnalyticsTables, TABLES as ANALYTICS_TABLES } from './tables.js';
9
+ export type { AnalyticsEvent, AnalyticsSummary, CountedDevice, CountedPath, CountedReferrer, DailyViews, RecordEventInput, RecordEventResult, SummaryOptions, } from './types.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACjF,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC/E,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,GACf,MAAM,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export { classifyDevice, DEVICE_CATEGORIES } from './device.js';
2
+ export { extractReferrerDomain } from './referrer.js';
3
+ export { createDailySaltStore, hashSession, utcDateKey } from './session-hash.js';
4
+ export { createAnalyticsStore, DEFAULT_SUMMARY_LIMIT } from './store.js';
5
+ export { ensureAnalyticsTables, TABLES as ANALYTICS_TABLES } from './tables.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAErD,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEjF,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAA"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Reduces a `Referer` header to a bare domain, never the full URL.
3
+ *
4
+ * A full referrer URL routinely carries a search query, a document id, or a
5
+ * session token that belongs to the *other* site's visitor — recording it
6
+ * verbatim would leak that visitor's data through this one's analytics. The
7
+ * domain is the only part that answers "where did this visit come from",
8
+ * which is the only question this feature exists to answer.
9
+ */
10
+ export declare function extractReferrerDomain(referrer: string | null | undefined, siteHost?: string | null | undefined): string | undefined;
11
+ //# sourceMappingURL=referrer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"referrer.d.ts","sourceRoot":"","sources":["../src/referrer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACnC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACnC,MAAM,GAAG,SAAS,CAuBpB"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Reduces a `Referer` header to a bare domain, never the full URL.
3
+ *
4
+ * A full referrer URL routinely carries a search query, a document id, or a
5
+ * session token that belongs to the *other* site's visitor — recording it
6
+ * verbatim would leak that visitor's data through this one's analytics. The
7
+ * domain is the only part that answers "where did this visit come from",
8
+ * which is the only question this feature exists to answer.
9
+ */
10
+ export function extractReferrerDomain(referrer, siteHost) {
11
+ if (referrer === null || referrer === undefined || referrer.trim().length === 0) {
12
+ return undefined;
13
+ }
14
+ let url;
15
+ try {
16
+ url = new URL(referrer);
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ if (url.protocol !== 'http:' && url.protocol !== 'https:')
22
+ return undefined;
23
+ const host = url.hostname.toLowerCase();
24
+ // Navigation from the site to itself is not a "referrer" worth recording —
25
+ // every internal page-to-page click would otherwise show up as its own
26
+ // top "referrer", drowning out the external sources the feature is for.
27
+ if (siteHost !== undefined && siteHost !== null && host === siteHost.toLowerCase()) {
28
+ return undefined;
29
+ }
30
+ return host;
31
+ }
32
+ //# sourceMappingURL=referrer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"referrer.js","sourceRoot":"","sources":["../src/referrer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAAmC,EACnC,QAAoC;IAEpC,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChF,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,IAAI,GAAQ,CAAA;IACZ,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAA;IACzB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAA;IAE3E,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAA;IACvC,2EAA2E;IAC3E,uEAAuE;IACvE,wEAAwE;IACxE,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI,IAAI,IAAI,KAAK,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC;QACnF,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { type DatabaseHandle } from '@cogenta/core';
2
+ export declare function dailySaltTableName(): string;
3
+ export declare function ensureDailySaltTable(db: DatabaseHandle): Promise<void>;
4
+ /** `YYYY-MM-DD`, always UTC so the salt's day boundary never depends on server timezone. */
5
+ export declare function utcDateKey(at: number): string;
6
+ export interface DailySaltStore {
7
+ /** Returns today's salt, minting and persisting one the first time it is asked for. */
8
+ getSalt(day: string): Promise<string>;
9
+ /**
10
+ * Deletes salts older than `retainDays`. Not load-bearing for the
11
+ * cross-day-unlinkability guarantee above (a stale salt alone cannot be
12
+ * turned back into an IP address) — this exists as defence in depth, so a
13
+ * database that is kept around for a long time does not accumulate salts
14
+ * it no longer has any use for.
15
+ */
16
+ purgeOlderThan(cutoffDay: string): Promise<number>;
17
+ }
18
+ export declare function createDailySaltStore(db: DatabaseHandle, now?: () => number): DailySaltStore;
19
+ /** `sha256(salt | ip | device)`, hex-encoded. Never reversible back to the IP without the salt *and* the original IP. */
20
+ export declare function hashSession(salt: string, ip: string, device: string): string;
21
+ //# sourceMappingURL=session-hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-hash.d.ts","sourceRoot":"","sources":["../src/session-hash.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,cAAc,EAAmB,MAAM,eAAe,CAAA;AA2BlF,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,wBAAsB,oBAAoB,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ5E;AAED,4FAA4F;AAC5F,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,MAAM,WAAW,cAAc;IAC7B,uFAAuF;IACvF,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IACrC;;;;;;OAMG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CACnD;AAED,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,cAAc,EAClB,GAAG,GAAE,MAAM,MAAiB,GAC3B,cAAc,CAwChB;AAED,yHAAyH;AACzH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE5E"}
@@ -0,0 +1,81 @@
1
+ import { createHash, randomBytes } from 'node:crypto';
2
+ import { CogentaError, identifier, sql } from '@cogenta/core';
3
+ /**
4
+ * The privacy core of this package.
5
+ *
6
+ * `sessionHash = sha256(dailySalt | ip | deviceCategory)`. It stands in for a
7
+ * visitor without ever storing a cookie, an IP address, or any other
8
+ * persistent identifier:
9
+ *
10
+ * - The IP address is only ever used as an *input* to the hash, in memory,
11
+ * for the single request being recorded. It is never written to a row.
12
+ * - `dailySalt` is a random value minted once per calendar day (UTC) and
13
+ * never reused across days. Because the salt changes, the *same* visitor
14
+ * (same IP, same device) produces a *different*, unrelated hash on every
15
+ * new day — there is no way to compute "was this the same person as
16
+ * yesterday" from the stored data, even with full database access, because
17
+ * recomputing yesterday's hash needs yesterday's IP, which was never kept.
18
+ * - Two different visitors on the same day get different hashes (barring a
19
+ * SHA-256 collision), which is what makes the hash usable for counting
20
+ * unique visitors *within* one day.
21
+ *
22
+ * This is the whole mechanism: no cookie is ever set, and nothing links one
23
+ * day's traffic to the next.
24
+ */
25
+ const TABLE = 'cogenta_analytics_daily_salts';
26
+ export function dailySaltTableName() {
27
+ return TABLE;
28
+ }
29
+ export async function ensureDailySaltTable(db) {
30
+ const table = identifier(TABLE, db.dialect);
31
+ await db.query(sql `
32
+ create table if not exists ${table} (
33
+ day text not null primary key,
34
+ salt text not null,
35
+ created_at text not null
36
+ )`);
37
+ }
38
+ /** `YYYY-MM-DD`, always UTC so the salt's day boundary never depends on server timezone. */
39
+ export function utcDateKey(at) {
40
+ return new Date(at).toISOString().slice(0, 10);
41
+ }
42
+ export function createDailySaltStore(db, now = Date.now) {
43
+ const table = identifier(TABLE, db.dialect);
44
+ return {
45
+ getSalt: async (day) => {
46
+ const existing = await db.query(sql `select salt from ${table} where day = ${day}`);
47
+ const found = existing.rows[0];
48
+ if (found !== undefined)
49
+ return found.salt;
50
+ const salt = randomBytes(32).toString('hex');
51
+ try {
52
+ await db.query(sql `insert into ${table} (day, salt, created_at) values (${day}, ${salt}, ${new Date(now()).toISOString()})`);
53
+ return salt;
54
+ }
55
+ catch {
56
+ // Lost a race with another request minting the same day's salt first —
57
+ // read back what won, rather than every concurrent request minting
58
+ // its own (which would silently split one day into several cohorts).
59
+ const raced = await db.query(sql `select salt from ${table} where day = ${day}`);
60
+ const winner = raced.rows[0];
61
+ if (winner !== undefined)
62
+ return winner.salt;
63
+ throw new CogentaError({
64
+ code: 'ANALYTICS_SALT_UNAVAILABLE',
65
+ message: `Could not read back the daily salt for ${day} after an insert conflict.`,
66
+ hint: 'This should only happen under a database fault mid-write. Retry the request; if it keeps happening, check the database connection.',
67
+ details: { day },
68
+ });
69
+ }
70
+ },
71
+ purgeOlderThan: async (cutoffDay) => {
72
+ const result = await db.query(sql `delete from ${table} where day < ${cutoffDay}`);
73
+ return result.rowsAffected;
74
+ },
75
+ };
76
+ }
77
+ /** `sha256(salt | ip | device)`, hex-encoded. Never reversible back to the IP without the salt *and* the original IP. */
78
+ export function hashSession(salt, ip, device) {
79
+ return createHash('sha256').update(`${salt}|${ip}|${device}`, 'utf8').digest('hex');
80
+ }
81
+ //# sourceMappingURL=session-hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-hash.js","sourceRoot":"","sources":["../src/session-hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,YAAY,EAAuB,UAAU,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AAElF;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,MAAM,KAAK,GAAG,+BAA+B,CAAA;AAE7C,MAAM,UAAU,kBAAkB;IAChC,OAAO,KAAK,CAAA;AACd,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,EAAkB;IAC3D,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,CAAA;IAC3C,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,CAAA;iCACa,KAAK;;;;MAIhC,CAAC,CAAA;AACP,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,UAAU,CAAC,EAAU;IACnC,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;AAChD,CAAC;AAe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AE,EAAE,GAAG,EAAE;iBACjB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAED,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE;YAClC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,CAAA,eAAe,KAAK,gBAAgB,SAAS,EAAE,CAAC,CAAA;YACjF,OAAO,MAAM,CAAC,YAAY,CAAA;QAC5B,CAAC;KACF,CAAA;AACH,CAAC;AAED,yHAAyH;AACzH,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,EAAU,EAAE,MAAc;IAClE,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,IAAI,EAAE,IAAI,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACrF,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { type DatabaseHandle } from '@cogenta/core';
2
+ import type { AnalyticsSummary, RecordEventInput, RecordEventResult, SummaryOptions } from './types.js';
3
+ export declare const DEFAULT_SUMMARY_LIMIT = 10;
4
+ export interface AnalyticsStore {
5
+ /**
6
+ * Records one page view. Never throws for a malformed or abusive request —
7
+ * a public beacon endpoint is a bonus feature (R1/R2 spirit: the site works
8
+ * without it), so the worst an attacker or a broken client can do is have
9
+ * their event silently dropped. `recorded: false` says which happened.
10
+ */
11
+ recordEvent(input: RecordEventInput, now?: number): Promise<RecordEventResult>;
12
+ getSummary(options: SummaryOptions): Promise<AnalyticsSummary>;
13
+ }
14
+ export declare function createAnalyticsStore(db: DatabaseHandle, now?: () => number): AnalyticsStore;
15
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAA0B,MAAM,eAAe,CAAA;AAK3E,OAAO,KAAK,EACV,gBAAgB,EAKhB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACf,MAAM,YAAY,CAAA;AAqBnB,eAAO,MAAM,qBAAqB,KAAK,CAAA;AAEvC,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,WAAW,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;IAC9E,UAAU,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA;CAC/D;AAED,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,cAAc,EAClB,GAAG,GAAE,MAAM,MAAiB,GAC3B,cAAc,CAgHhB"}
package/dist/store.js ADDED
@@ -0,0 +1,130 @@
1
+ import { identifier, newId, sql } from '@cogenta/core';
2
+ import { classifyDevice } from './device.js';
3
+ import { extractReferrerDomain } from './referrer.js';
4
+ import { createDailySaltStore, hashSession, utcDateKey } from './session-hash.js';
5
+ import { TABLES } from './tables.js';
6
+ /** Longer than this is not a path, it is an attempt to make the events table work. */
7
+ const MAX_PATH_LENGTH = 512;
8
+ /**
9
+ * How many beacons the same session hash may fire inside the window below
10
+ * before further ones are silently dropped.
11
+ *
12
+ * This is abuse-resistance, not user throttling: a real visit fires exactly
13
+ * one beacon per page view, so this only ever engages against a script
14
+ * hammering the endpoint. It reuses the same "count recent rows for a
15
+ * subject" shape as `@cogenta/auth`'s login rate limiter
16
+ * (`packages/auth/src/rate-limit.ts`), sized very differently — a login limiter
17
+ * defends a few attempts per fifteen minutes, this defends a public,
18
+ * unauthenticated, no-op-on-abuse endpoint that must never itself break page
19
+ * rendering, so it drops rather than throws (see `recordEvent` below).
20
+ */
21
+ const RATE_LIMIT_WINDOW_MS = 60_000;
22
+ const RATE_LIMIT_MAX_EVENTS = 60;
23
+ export const DEFAULT_SUMMARY_LIMIT = 10;
24
+ export function createAnalyticsStore(db, now = Date.now) {
25
+ const events = identifier(TABLES.events, db.dialect);
26
+ const saltStore = createDailySaltStore(db, now);
27
+ async function withinRateLimit(sessionHash, at) {
28
+ const since = new Date(at - RATE_LIMIT_WINDOW_MS).toISOString();
29
+ const result = await db.query(sql `select count(*) as n from ${events} where session_hash = ${sessionHash} and at >= ${since}`);
30
+ return Number(result.rows[0]?.n ?? 0) < RATE_LIMIT_MAX_EVENTS;
31
+ }
32
+ return {
33
+ recordEvent: async (input, at) => {
34
+ const timestamp = at ?? now();
35
+ const path = normalisePath(input.path);
36
+ if (path === undefined)
37
+ return { recorded: false };
38
+ const device = classifyDevice(input.userAgent);
39
+ const referrerDomain = extractReferrerDomain(input.referrer, input.siteHost);
40
+ const day = utcDateKey(timestamp);
41
+ const salt = await saltStore.getSalt(day);
42
+ const sessionHash = hashSession(salt, input.ip, device);
43
+ if (!(await withinRateLimit(sessionHash, timestamp))) {
44
+ return { recorded: false };
45
+ }
46
+ await db.query(sql `
47
+ insert into ${events} (id, at, path, referrer_domain, device, session_hash)
48
+ values (
49
+ ${newId(now)},
50
+ ${new Date(timestamp).toISOString()},
51
+ ${path},
52
+ ${referrerDomain ?? null},
53
+ ${device},
54
+ ${sessionHash}
55
+ )`);
56
+ return { recorded: true };
57
+ },
58
+ getSummary: async (options) => {
59
+ const since = options.since;
60
+ const until = options.until ?? new Date(now());
61
+ const sinceIso = since.toISOString();
62
+ const untilIso = until.toISOString();
63
+ const rowLimit = options.limit ?? DEFAULT_SUMMARY_LIMIT;
64
+ const totalResult = await db.query(sql `
65
+ select count(*) as n from ${events} where at >= ${sinceIso} and at <= ${untilIso}`);
66
+ const uniqueResult = await db.query(sql `
67
+ select count(distinct session_hash) as n from ${events}
68
+ where at >= ${sinceIso} and at <= ${untilIso}`);
69
+ const topPagesResult = await db.query(sql `
70
+ select path, count(*) as n from ${events}
71
+ where at >= ${sinceIso} and at <= ${untilIso}
72
+ group by path
73
+ order by count(*) desc
74
+ limit ${rowLimit}`);
75
+ const topReferrersResult = await db.query(sql `
76
+ select referrer_domain, count(*) as n from ${events}
77
+ where at >= ${sinceIso} and at <= ${untilIso} and referrer_domain is not null
78
+ group by referrer_domain
79
+ order by count(*) desc
80
+ limit ${rowLimit}`);
81
+ const deviceResult = await db.query(sql `
82
+ select device, count(*) as n from ${events}
83
+ where at >= ${sinceIso} and at <= ${untilIso}
84
+ group by device
85
+ order by count(*) desc`);
86
+ const dailyResult = await db.query(sql `
87
+ select substr(at, 1, 10) as day, count(*) as n from ${events}
88
+ where at >= ${sinceIso} and at <= ${untilIso}
89
+ group by substr(at, 1, 10)
90
+ order by day asc`);
91
+ const topPages = topPagesResult.rows.map((row) => ({
92
+ path: row.path,
93
+ views: Number(row.n),
94
+ }));
95
+ const topReferrers = topReferrersResult.rows.map((row) => ({
96
+ domain: row.referrer_domain,
97
+ views: Number(row.n),
98
+ }));
99
+ const deviceBreakdown = deviceResult.rows.map((row) => ({
100
+ device: row.device,
101
+ views: Number(row.n),
102
+ }));
103
+ const dailyViews = dailyResult.rows.map((row) => ({
104
+ day: row.day,
105
+ views: Number(row.n),
106
+ }));
107
+ return {
108
+ since: sinceIso,
109
+ until: untilIso,
110
+ totalViews: Number(totalResult.rows[0]?.n ?? 0),
111
+ uniqueVisitors: Number(uniqueResult.rows[0]?.n ?? 0),
112
+ topPages,
113
+ topReferrers,
114
+ deviceBreakdown,
115
+ dailyViews,
116
+ };
117
+ },
118
+ };
119
+ }
120
+ function normalisePath(path) {
121
+ if (typeof path !== 'string')
122
+ return undefined;
123
+ const trimmed = path.trim();
124
+ if (trimmed.length === 0 || trimmed.length > MAX_PATH_LENGTH)
125
+ return undefined;
126
+ if (!trimmed.startsWith('/'))
127
+ return undefined;
128
+ return trimmed;
129
+ }
130
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AAC3E,OAAO,EAAE,cAAc,EAAuB,MAAM,aAAa,CAAA;AAC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only events: 'cogenta_analytics_events';
4
+ };
5
+ /**
6
+ * Creates the events table (and the daily-salt table from `session-hash.ts`)
7
+ * if they are not already there. Same idempotent, dialect-agnostic pattern as
8
+ * `@cogenta/auth`'s `ensureAuthTables` — no formal up/down migration, because
9
+ * nothing here is ever destructively altered after creation.
10
+ */
11
+ export declare function ensureAnalyticsTables(db: DatabaseHandle): Promise<void>;
12
+ //# sourceMappingURL=tables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../src/tables.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EAKpB,MAAM,eAAe,CAAA;AAGtB,eAAO,MAAM,MAAM;aACjB,MAAM,EAAE,0BAA0B;CAC1B,CAAA;AAMV;;;;;GAKG;AACH,wBAAsB,qBAAqB,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAiC7E"}
package/dist/tables.js ADDED
@@ -0,0 +1,46 @@
1
+ import { identifier, sql, unsafeRaw, } from '@cogenta/core';
2
+ import { ensureDailySaltTable } from './session-hash.js';
3
+ export const TABLES = {
4
+ events: 'cogenta_analytics_events',
5
+ };
6
+ function textColumn(dialect, length) {
7
+ return unsafeRaw(dialect === 'sqlite' ? 'text' : `varchar(${length})`);
8
+ }
9
+ /**
10
+ * Creates the events table (and the daily-salt table from `session-hash.ts`)
11
+ * if they are not already there. Same idempotent, dialect-agnostic pattern as
12
+ * `@cogenta/auth`'s `ensureAuthTables` — no formal up/down migration, because
13
+ * nothing here is ever destructively altered after creation.
14
+ */
15
+ export async function ensureAnalyticsTables(db) {
16
+ await ensureDailySaltTable(db);
17
+ const d = db.dialect;
18
+ const events = identifier(TABLES.events, d);
19
+ const t512 = textColumn(d, 512);
20
+ const t64 = textColumn(d, 64);
21
+ const t32 = textColumn(d, 32);
22
+ await db.query(sql `
23
+ create table if not exists ${events} (
24
+ id ${t64} not null primary key,
25
+ -- ISO-8601 text on every dialect, like every other timestamp column in
26
+ -- this project (see the migrator's own table) — one representation, no
27
+ -- risk of the three dialects disagreeing about time zones.
28
+ at ${t64} not null,
29
+ path ${t512} not null,
30
+ -- Domain only, never a full URL. See referrer.ts for why.
31
+ referrer_domain ${t512},
32
+ device ${t32} not null,
33
+ -- No IP address, no cookie, no persistent id: a daily-salted hash. See
34
+ -- session-hash.ts — this is the privacy contract this table exists under.
35
+ session_hash ${t64} not null
36
+ )`);
37
+ await createIndexIfMissing(db, 'cogenta_analytics_events_at', events, sql `(at)`);
38
+ await createIndexIfMissing(db, 'cogenta_analytics_events_path', events, sql `(path, at)`);
39
+ await createIndexIfMissing(db, 'cogenta_analytics_events_session', events, sql `(session_hash, at)`);
40
+ }
41
+ async function createIndexIfMissing(db, name, table, columns) {
42
+ await db
43
+ .query(sql `create index ${identifier(name, db.dialect)} on ${table} ${columns}`)
44
+ .catch(() => undefined); // already there — no portable "if not exists" for indexes
45
+ }
46
+ //# sourceMappingURL=tables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tables.js","sourceRoot":"","sources":["../src/tables.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EAEV,GAAG,EACH,SAAS,GACV,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAExD,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,MAAM,EAAE,0BAA0B;CAC1B,CAAA;AAEV,SAAS,UAAU,CAAC,OAAwB,EAAE,MAAc;IAC1D,OAAO,SAAS,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,MAAM,GAAG,CAAC,CAAA;AACxE,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,EAAkB;IAC5D,MAAM,oBAAoB,CAAC,EAAE,CAAC,CAAA;IAE9B,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAA;IACpB,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;IAC3C,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IAC/B,MAAM,GAAG,GAAG,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IAC7B,MAAM,GAAG,GAAG,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IAE7B,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,CAAA;iCACa,MAAM;WAC5B,GAAG;;;;WAIH,GAAG;aACD,IAAI;;wBAEO,IAAI;eACb,GAAG;;;qBAGG,GAAG;MAClB,CAAC,CAAA;IAEL,MAAM,oBAAoB,CAAC,EAAE,EAAE,6BAA6B,EAAE,MAAM,EAAE,GAAG,CAAA,MAAM,CAAC,CAAA;IAChF,MAAM,oBAAoB,CAAC,EAAE,EAAE,+BAA+B,EAAE,MAAM,EAAE,GAAG,CAAA,YAAY,CAAC,CAAA;IACxF,MAAM,oBAAoB,CACxB,EAAE,EACF,kCAAkC,EAClC,MAAM,EACN,GAAG,CAAA,oBAAoB,CACxB,CAAA;AACH,CAAC;AAED,KAAK,UAAU,oBAAoB,CACjC,EAAkB,EAClB,IAAY,EACZ,KAAkB,EAClB,OAAoB;IAEpB,MAAM,EAAE;SACL,KAAK,CAAC,GAAG,CAAA,gBAAgB,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,KAAK,IAAI,OAAO,EAAE,CAAC;SAC/E,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA,CAAC,0DAA0D;AACtF,CAAC"}
@@ -0,0 +1,66 @@
1
+ import type { DeviceCategory } from './device.js';
2
+ export interface AnalyticsEvent {
3
+ readonly id: string;
4
+ readonly at: string;
5
+ readonly path: string;
6
+ readonly referrerDomain: string | undefined;
7
+ readonly device: DeviceCategory;
8
+ readonly sessionHash: string;
9
+ }
10
+ /**
11
+ * What the beacon route hands the store. `ip` and `userAgent` are consumed to
12
+ * derive `sessionHash`/`device` and are never themselves persisted — see
13
+ * `session-hash.ts` and `device.ts`.
14
+ */
15
+ export interface RecordEventInput {
16
+ readonly path: string;
17
+ readonly referrer?: string | null | undefined;
18
+ readonly userAgent?: string | null | undefined;
19
+ readonly ip: string;
20
+ /** The site's own hostname, so a same-site referrer is not recorded as one. */
21
+ readonly siteHost?: string | null | undefined;
22
+ }
23
+ export interface RecordEventResult {
24
+ /** `false` when the event was dropped — invalid path, or rate-limited. Never throws for a public beacon. */
25
+ readonly recorded: boolean;
26
+ }
27
+ export interface SummaryOptions {
28
+ readonly since: Date;
29
+ readonly until?: Date;
30
+ /** How many rows in each top-N breakdown. Defaults to 10. */
31
+ readonly limit?: number;
32
+ }
33
+ export interface CountedPath {
34
+ readonly path: string;
35
+ readonly views: number;
36
+ }
37
+ export interface CountedReferrer {
38
+ readonly domain: string;
39
+ readonly views: number;
40
+ }
41
+ export interface CountedDevice {
42
+ readonly device: DeviceCategory;
43
+ readonly views: number;
44
+ }
45
+ export interface DailyViews {
46
+ readonly day: string;
47
+ readonly views: number;
48
+ }
49
+ export interface AnalyticsSummary {
50
+ readonly since: string;
51
+ readonly until: string;
52
+ readonly totalViews: number;
53
+ /**
54
+ * Distinct session hashes in the window. Because the hash is salted fresh
55
+ * every day (`session-hash.ts`), the same real visitor on two different
56
+ * days counts as two unique visitors here — an intentional, documented
57
+ * over-count that is the price of never storing anything that could link
58
+ * one day's traffic to the next.
59
+ */
60
+ readonly uniqueVisitors: number;
61
+ readonly topPages: readonly CountedPath[];
62
+ readonly topReferrers: readonly CountedReferrer[];
63
+ readonly deviceBreakdown: readonly CountedDevice[];
64
+ readonly dailyViews: readonly DailyViews[];
65
+ }
66
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,a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AC5B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAA;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B;;;;;;OAMG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,CAAA;IACzC,QAAQ,CAAC,YAAY,EAAE,SAAS,eAAe,EAAE,CAAA;IACjD,QAAQ,CAAC,eAAe,EAAE,SAAS,aAAa,EAAE,CAAA;IAClD,QAAQ,CAAC,UAAU,EAAE,SAAS,UAAU,EAAE,CAAA;CAC3C"}
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,42 @@
1
+ {
2
+ "name": "@cogenta/analytics",
3
+ "version": "0.2.0",
4
+ "description": "Self-hosted, cookie-free, privacy-respecting page-view analytics.",
5
+ "license": "MPL-2.0",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "engines": {
18
+ "node": ">=22.11.0"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public",
22
+ "provenance": true
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/cogenta-cms/cogenta.git",
27
+ "directory": "packages/analytics"
28
+ },
29
+ "dependencies": {
30
+ "@cogenta/core": "0.4.0"
31
+ },
32
+ "devDependencies": {
33
+ "typescript": "^7.0.2",
34
+ "vitest": "^4.1.10"
35
+ },
36
+ "scripts": {
37
+ "build": "tsc -p tsconfig.json",
38
+ "typecheck": "tsc -p tsconfig.typecheck.json",
39
+ "test": "vitest run --passWithNoTests",
40
+ "test:integration": "vitest run --config vitest.integration.config.ts --passWithNoTests"
41
+ }
42
+ }