@harshankur/viewcounter 3.1.0 → 3.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 (50) hide show
  1. package/.env.example +37 -11
  2. package/README.md +330 -138
  3. package/admin/css/admin.css +891 -198
  4. package/admin/index.html +13 -7
  5. package/admin/js/api.js +52 -6
  6. package/admin/js/appTabs.js +100 -0
  7. package/admin/js/charts.js +529 -189
  8. package/admin/js/constants.js +98 -9
  9. package/admin/js/dataTable.js +478 -0
  10. package/admin/js/format.js +58 -7
  11. package/admin/js/icons.js +168 -0
  12. package/admin/js/listbox.js +2 -1
  13. package/admin/js/logs.js +211 -60
  14. package/admin/js/main.js +201 -37
  15. package/admin/js/overview.js +905 -0
  16. package/admin/js/passwordPrompt.js +75 -0
  17. package/admin/js/table.js +12 -52
  18. package/admin/js/viewDialogs.js +30 -14
  19. package/admin/js/views.js +273 -207
  20. package/admin/locales/en.json +352 -63
  21. package/config/index.js +40 -5
  22. package/constants.js +126 -8
  23. package/db/AdminRepository.js +85 -159
  24. package/db/DatabaseManager.js +57 -7
  25. package/db/LogRepository.js +172 -35
  26. package/db/adminSchema.js +93 -4
  27. package/db/adminSessionStore.js +104 -0
  28. package/db/analysis.js +484 -0
  29. package/db/rejectionCounter.js +117 -0
  30. package/index.js +49 -26
  31. package/middleware/adminAuth.js +83 -43
  32. package/middleware/adminValidation.js +69 -3
  33. package/middleware/auth.js +2 -2
  34. package/middleware/security.js +26 -2
  35. package/middleware/validation.js +50 -2
  36. package/package.json +5 -2
  37. package/routes/admin.js +130 -22
  38. package/routes/analytics.js +236 -18
  39. package/tracker/tracker.js +240 -0
  40. package/utils/appIdUtils.js +1 -1
  41. package/utils/durationUtils.js +33 -0
  42. package/utils/errorUtils.js +4 -1
  43. package/utils/geoCity.js +87 -0
  44. package/utils/ipUtils.js +1 -1
  45. package/utils/privacyUtils.js +2 -2
  46. package/utils/referrerParser.js +23 -5
  47. package/utils/secretStore.js +1 -1
  48. package/utils/userAgentParser.js +52 -3
  49. package/utils/visitorContext.js +70 -0
  50. package/admin/js/insights.js +0 -192
package/.env.example CHANGED
@@ -1,7 +1,7 @@
1
1
  # ViewCounter configuration
2
2
  #
3
3
  # Copy to `.env` and fill in. Every value here can also come from dbInfo.json /
4
- # allowed.json, which take precedence — see config/index.js for the resolution
4
+ # allowed.json, which take precedence. See config/index.js for the resolution
5
5
  # order (config file > environment variable > built-in default).
6
6
  #
7
7
  # Anything marked Required is checked at startup in production: the server
@@ -37,7 +37,7 @@ CORS_ORIGINS=https://example.com,https://www.example.com
37
37
  # Credentials for the analytics READ endpoints (/stats, /views, /trends, ...),
38
38
  # comma-separated, sent by clients as the `x-api-key` header. Keys shorter than
39
39
  # 32 characters are ignored. List several so one consumer's key can be revoked
40
- # without rotating everyone else's. With none set, the read API returns 503 —
40
+ # without rotating everyone else's. With none set, the read API returns 503:
41
41
  # it fails closed rather than serving your analytics to anyone who asks.
42
42
  # Generate one with:
43
43
  # node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
@@ -59,6 +59,17 @@ ADMIN_API_KEYS=
59
59
  # Generate one with: openssl rand -base64 24
60
60
  #ADMIN_PASSWORD=
61
61
 
62
+ # How long an admin UI session lasts: it ends after this long without use, or
63
+ # this long after signing in, whichever comes first. Sessions are kept in the
64
+ # database (only a hash of the token), so they survive restarts, and using the
65
+ # UI, even just reading it, keeps one alive. A number with m, h, or d, such as
66
+ # 30m, 12h, or 7d. A malformed value, or an idle time longer than the maximum,
67
+ # stops the server from starting. Erasing views permanently asks for the
68
+ # password again unless it was entered in the last 15 minutes, however long
69
+ # the session. Defaults: 7d idle, 30d maximum.
70
+ #ADMIN_SESSION_IDLE_TIMEOUT=7d
71
+ #ADMIN_SESSION_MAX_AGE=30d
72
+
62
73
  # Number of reverse proxies in front of this service, or a comma-separated list
63
74
  # of trusted proxy CIDRs. Leave unset if nothing proxies it.
64
75
  #
@@ -72,8 +83,8 @@ ADMIN_API_KEYS=
72
83
  # Where the visitor-hash secret is persisted. Generated with a CSPRNG on first
73
84
  # run at mode 0600. This secret is the only reason a stored visitor hash cannot
74
85
  # be brute-forced back to the IP that produced it, so back it up with the same
75
- # care as the database password — and note that replacing it makes existing
76
- # hashes unlinkable from new ones (which is deliberate, not a bug).
86
+ # care as the database password. Replacing it makes existing hashes
87
+ # unlinkable from new ones (which is deliberate, not a bug).
77
88
  #VISITOR_SECRET_PATH=/var/lib/viewcounter/.visitor-secret
78
89
 
79
90
  # Supply the secret directly instead of persisting a file. Useful for
@@ -95,8 +106,8 @@ DB_PORT=3306
95
106
  PORT=3030
96
107
 
97
108
  # Defaults to `production`. Set to `development` for local work. This does not
98
- # change what is returned to callers — errors never include internal detail in
99
- # any environment — but it does relax the startup checks above.
109
+ # change what is returned to callers (errors never include internal detail in
110
+ # any environment), but it does relax the startup checks above.
100
111
  #NODE_ENV=production
101
112
 
102
113
  # Operational log verbosity: debug | info | warn | error | silent.
@@ -104,7 +115,9 @@ PORT=3030
104
115
  LOG_LEVEL=info
105
116
 
106
117
  # Rate limiting, applied per client IP across all endpoints. This is the
107
- # single-abuser backstop.
118
+ # single-abuser backstop. Engagement reports (/engage, two a minute from each
119
+ # page being read) have a separate budget of the same size, here and per app,
120
+ # so they never use up the one page views depend on.
108
121
  RATE_LIMIT_WINDOW_MS=60000
109
122
  RATE_LIMIT_MAX=100
110
123
 
@@ -125,11 +138,24 @@ UNIQUE_VISITOR_WINDOW_HOURS=24
125
138
  # 0 keeps trash until someone empties it by hand. Default: 30.
126
139
  TRASH_RETENTION_DAYS=30
127
140
 
128
- # Days an entry stays in the view register log (one row per accepted view)
129
- # before it is removed. The log holds no personal data; this only bounds its
130
- # size, and never touches the views themselves. The admin operation log is
131
- # never pruned. 0 keeps the view log forever. Default: 90.
141
+ # Days an entry stays in the tracking log (one row per accepted view, plus
142
+ # per-minute counts of bots and refused requests) before it is removed. The
143
+ # log holds no personal data; this only bounds its size, and never touches the
144
+ # views themselves. The admin operation log is never pruned. 0 keeps the
145
+ # tracking log forever. Default: 90. (The name predates the tracking log.)
132
146
  VIEW_LOG_RETENTION_DAYS=90
133
147
 
148
+ # A city database, for the region and city of each view. Countries work
149
+ # without one (a GeoLite2 country database ships in the package). Point this
150
+ # at a MaxMind-format .mmdb file:
151
+ # - DB-IP IP to City Lite, free under CC BY 4.0, updated monthly:
152
+ # https://db-ip.com/db/download/ip-to-city-lite (the admin UI credits it
153
+ # as its licence asks)
154
+ # - or MaxMind GeoLite2 City, which needs a free MaxMind account
155
+ # The file is read again when it changes, so a monthly download that replaces
156
+ # it needs no restart. Unset: region and city stay empty. A path that cannot
157
+ # be opened stops the server from starting.
158
+ #GEOIP_CITY_DB=/var/lib/viewcounter/dbip-city-lite.mmdb
159
+
134
160
  # Device size buckets accepted on /registerView, comma-separated.
135
161
  #ALLOWED_DEVICE_SIZES=small,medium,large