@things-factory/auth-base 10.1.142 → 10.1.145
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/dist-server/index.js +2 -9
- package/dist-server/index.js.map +1 -1
- package/dist-server/service/access-request/index.d.ts +1 -1
- package/dist-server/service/app-binding/index.d.ts +1 -1
- package/dist-server/service/appliance/index.d.ts +1 -1
- package/dist-server/service/application/index.d.ts +1 -1
- package/dist-server/service/domain-link/index.d.ts +1 -1
- package/dist-server/service/domain-owner/index.d.ts +1 -1
- package/dist-server/service/granted-role/index.d.ts +1 -1
- package/dist-server/service/index.d.ts +1 -1
- package/dist-server/service/invitation/index.d.ts +1 -1
- package/dist-server/service/partner/index.d.ts +1 -1
- package/dist-server/service/privilege/index.d.ts +1 -1
- package/dist-server/service/privilege/privilege-sync.d.ts +10 -0
- package/dist-server/service/privilege/privilege-sync.js +28 -0
- package/dist-server/service/privilege/privilege-sync.js.map +1 -0
- package/dist-server/service/role/index.d.ts +1 -1
- package/dist-server/service/role-template/index.d.ts +1 -1
- package/dist-server/service/user/index.d.ts +1 -1
- package/dist-server/service/verification-token/index.d.ts +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/tests/privilege-sync-db.test.ts +58 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/auth-base",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.145",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "dist-client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"passport-jwt": "^4.0.0",
|
|
49
49
|
"passport-local": "^1.0.0"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "1c33612ba31f51b9af59f9bc68751971097350a5"
|
|
52
52
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The privilege sync is boot-time writing, and boot-time writing takes its turn (shell `inBootTurn`).
|
|
3
|
+
*
|
|
4
|
+
* On sqlite every transaction shares one connection. Another module's boot transaction (work-shift's
|
|
5
|
+
* baseline) that began while the sync's insert was open failed with "cannot start a transaction within a
|
|
6
|
+
* transaction", and its rollback took the insert with it — so the same privilege was missing again on
|
|
7
|
+
* the next boot, and the collision repeated every boot (`contact/query`, operato-plant, 2026-10-10).
|
|
8
|
+
*/
|
|
9
|
+
import { inBootTurn } from '@things-factory/shell'
|
|
10
|
+
|
|
11
|
+
import { closeAuthDatabase, Domain, getRepository, openAuthDatabase, resetAuthDatabase } from './db'
|
|
12
|
+
import { loadCompiled } from './compiled'
|
|
13
|
+
|
|
14
|
+
const { synchronizePrivileges } = loadCompiled('service/privilege/privilege-sync')
|
|
15
|
+
const { Privilege } = loadCompiled('service/privilege/privilege')
|
|
16
|
+
|
|
17
|
+
const pause = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
|
|
18
|
+
|
|
19
|
+
beforeAll(async () => {
|
|
20
|
+
await openAuthDatabase()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
await resetAuthDatabase()
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
afterAll(async () => {
|
|
28
|
+
await closeAuthDatabase()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('adds what is missing and leaves what is there', async () => {
|
|
32
|
+
await getRepository(Privilege).save({ category: 'contact', name: 'mutation' })
|
|
33
|
+
|
|
34
|
+
expect(await synchronizePrivileges([['contact', 'mutation'], ['contact', 'query']])).toEqual(['contact/query'])
|
|
35
|
+
expect(await getRepository(Privilege).countBy({ category: 'contact' })).toBe(2)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('another boot job that fails does not take the sync with it', async () => {
|
|
39
|
+
const dataSource = await openAuthDatabase()
|
|
40
|
+
|
|
41
|
+
/*
|
|
42
|
+
* A boot job of another module, in its turn: it holds a transaction for a while and then fails. On
|
|
43
|
+
* sqlite TypeORM shares one query runner, so a save that starts meanwhile rides inside that
|
|
44
|
+
* transaction — and goes when it rolls back.
|
|
45
|
+
*/
|
|
46
|
+
const other = inBootTurn(() =>
|
|
47
|
+
dataSource.transaction(async tx => {
|
|
48
|
+
await tx.getRepository(Domain).save({ name: 'boot-job', subdomain: 'boot-job' })
|
|
49
|
+
await pause(30)
|
|
50
|
+
throw new Error('the other boot job failed')
|
|
51
|
+
})
|
|
52
|
+
).catch(() => undefined)
|
|
53
|
+
const sync = synchronizePrivileges([['contact', 'query']])
|
|
54
|
+
|
|
55
|
+
await Promise.all([other, sync])
|
|
56
|
+
expect(await getRepository(Domain).countBy({ subdomain: 'boot-job' })).toBe(0)
|
|
57
|
+
expect(await getRepository(Privilege).countBy({ category: 'contact', name: 'query' })).toBe(1)
|
|
58
|
+
})
|