@proteinjs/user-server 1.18.0 → 1.20.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/CHANGELOG.md +22 -0
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/generated/index.js +3 -1
- package/dist/generated/index.js.map +1 -1
- package/dist/src/authorization/UserActivityStamp.d.ts +17 -15
- package/dist/src/authorization/UserActivityStamp.d.ts.map +1 -1
- package/dist/src/authorization/UserActivityStamp.js +21 -19
- package/dist/src/authorization/UserActivityStamp.js.map +1 -1
- package/dist/src/authorization/userCache.d.ts +9 -0
- package/dist/src/authorization/userCache.d.ts.map +1 -1
- package/dist/src/authorization/userCache.js +9 -9
- package/dist/src/authorization/userCache.js.map +1 -1
- package/dist/src/routes/DevBootstrapRoles.d.ts +21 -0
- package/dist/src/routes/DevBootstrapRoles.d.ts.map +1 -0
- package/dist/src/routes/DevBootstrapRoles.js +64 -0
- package/dist/src/routes/DevBootstrapRoles.js.map +1 -0
- package/dist/src/routes/devLogin.d.ts +11 -0
- package/dist/src/routes/devLogin.d.ts.map +1 -1
- package/dist/src/routes/devLogin.js +23 -3
- package/dist/src/routes/devLogin.js.map +1 -1
- package/dist/src/services/Roles.d.ts +29 -1
- package/dist/src/services/Roles.d.ts.map +1 -1
- package/dist/src/services/Roles.js +88 -14
- package/dist/src/services/Roles.js.map +1 -1
- package/dist/src/services/UserPresence.d.ts +16 -0
- package/dist/src/services/UserPresence.d.ts.map +1 -0
- package/dist/src/services/UserPresence.js +75 -0
- package/dist/src/services/UserPresence.js.map +1 -0
- package/dist/test/DevLogin.test.js +5 -2
- package/dist/test/DevLogin.test.js.map +1 -1
- package/dist/test/DevLoginBootstrapAdmin.test.js +2 -0
- package/dist/test/DevLoginBootstrapAdmin.test.js.map +1 -1
- package/dist/test/DevLoginBootstrapRoles.test.d.ts +2 -0
- package/dist/test/DevLoginBootstrapRoles.test.d.ts.map +1 -0
- package/dist/test/DevLoginBootstrapRoles.test.js +491 -0
- package/dist/test/DevLoginBootstrapRoles.test.js.map +1 -0
- package/dist/test/UserActivityStamp.integration.test.js +57 -90
- package/dist/test/UserActivityStamp.integration.test.js.map +1 -1
- package/dist/test/UserCacheDoesNotStampPresence.integration.test.d.ts +2 -0
- package/dist/test/UserCacheDoesNotStampPresence.integration.test.d.ts.map +1 -0
- package/dist/test/UserCacheDoesNotStampPresence.integration.test.js +117 -0
- package/dist/test/UserCacheDoesNotStampPresence.integration.test.js.map +1 -0
- package/generated/index.ts +3 -1
- package/package.json +3 -3
- package/src/authorization/UserActivityStamp.ts +22 -20
- package/src/authorization/userCache.ts +9 -9
- package/src/routes/DevBootstrapRoles.ts +50 -0
- package/src/routes/devLogin.ts +18 -0
- package/src/services/Roles.ts +61 -1
- package/src/services/UserPresence.ts +26 -0
- package/test/DevLogin.test.ts +5 -2
- package/test/DevLoginBootstrapAdmin.test.ts +2 -0
- package/test/DevLoginBootstrapRoles.test.ts +248 -0
- package/test/UserActivityStamp.integration.test.ts +38 -50
- package/test/UserCacheDoesNotStampPresence.integration.test.ts +44 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getDbAsSystem } from '@proteinjs/db';
|
|
2
|
+
import { tables, type UserActivity } from '@proteinjs/user';
|
|
3
|
+
import { userCache } from '../src/authorization/userCache';
|
|
4
|
+
import { UserServerTestEnvironment } from './UserServerTestEnvironment';
|
|
5
|
+
|
|
6
|
+
const testEnv = new UserServerTestEnvironment();
|
|
7
|
+
|
|
8
|
+
const activityRows = async (scope: string): Promise<UserActivity[]> =>
|
|
9
|
+
await getDbAsSystem().query(tables.UserActivity, { scope });
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* TRANSPORT IS NOT PRESENCE (UserActivityTable's contract; founder finding 2026-09-12 — every
|
|
13
|
+
* user on the admin usage page "last active today"). The per-request session-cache build
|
|
14
|
+
* (`userCache.create`) runs for EVERY request that rides a session cookie: an open tab's polls,
|
|
15
|
+
* a socket's room re-joins on every reconnect, the reload a deploy pushes onto every idle tab.
|
|
16
|
+
* None of that is a person. The build must therefore never write the presence stamp — the
|
|
17
|
+
* only door is the page's human-input report (UserPresence.recordPresence).
|
|
18
|
+
*
|
|
19
|
+
* Pre-fix, `userCache.create` stamped on every build: this test reads one row where the
|
|
20
|
+
* contract says none.
|
|
21
|
+
*/
|
|
22
|
+
describe('userCache.create — the session build does not stamp presence', () => {
|
|
23
|
+
beforeAll(async () => {
|
|
24
|
+
await testEnv.beforeAll();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterAll(async () => {
|
|
28
|
+
await testEnv.afterAll();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('resolving a human session (any request over a session cookie) writes NO user_activity row', async () => {
|
|
32
|
+
const user = await testEnv.createUser({ name: 'Idle Tab', email: 'idle-tab@test.local' });
|
|
33
|
+
|
|
34
|
+
// Three request-shaped builds: a poll, a reconnect re-join, a deploy reload — all the same seam.
|
|
35
|
+
for (const sessionId of ['poll', 'socket-rejoin', 'deploy-reload']) {
|
|
36
|
+
const resolved = await userCache.create(sessionId, user.email);
|
|
37
|
+
expect(resolved.id).toBe(user.id);
|
|
38
|
+
}
|
|
39
|
+
// The pre-fix stamp was fire-and-forget off the build — give it every chance to land.
|
|
40
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
41
|
+
|
|
42
|
+
expect(await activityRows(user.id)).toHaveLength(0);
|
|
43
|
+
});
|
|
44
|
+
});
|