@@ -17,7 +17,7 @@ import { AuthenticationRepository } from '../authentication.repository';
17
17
import { CanImpersonateEvent } from '../events/can-impersonate.event' ;
18
18
import { JwtService } from '../jwt.service' ;
19
19
import { NoSessionException } from './no-session.exception' ;
20
- import { type Session } from './session.dto' ;
20
+ import { Session } from './session.dto' ;
21
21
import { SessionHost } from './session.host' ;
22
22
23
23
/**
@@ -86,22 +86,21 @@ export class SessionManager {
86
86
}
87
87
: undefined ;
88
88
89
- const requesterSession : Session = {
89
+ const requesterSession = Session . from ( {
90
90
token,
91
91
issuedAt : DateTime . fromMillis ( iat ) ,
92
92
userId : result . userId ?? anon . id ,
93
93
anonymous : ! result . userId ,
94
94
roles : result . roles ,
95
- } ;
95
+ } ) ;
96
96
97
- const session : Session = impersonatee
98
- ? {
99
- ...requesterSession ,
97
+ const session = impersonatee
98
+ ? requesterSession . with ( {
100
99
userId : impersonatee ?. id ?? requesterSession . userId ,
101
100
roles : impersonatee . roles ,
102
101
impersonator : requesterSession ,
103
102
impersonatee,
104
- }
103
+ } )
105
104
: requesterSession ;
106
105
107
106
if ( impersonatee ) {
@@ -133,14 +132,14 @@ export class SessionManager {
133
132
return id ;
134
133
} ) ;
135
134
const unresolvedId = 'unresolvedId' as ID ;
136
- const session : Session = {
135
+ const session = Session . from ( {
137
136
token : 'system' ,
138
137
issuedAt : DateTime . now ( ) ,
139
138
userId : unresolvedId ,
140
139
anonymous : false ,
141
140
roles : [ 'global:Administrator' ] ,
142
141
...input ,
143
- } ;
142
+ } ) ;
144
143
type LazySession = Session &
145
144
Promise < Session > & { withRoles : ( ...roles : Role [ ] ) => LazySession } ;
146
145
return new Proxy ( session , {
@@ -180,25 +179,25 @@ export class SessionManager {
180
179
}
181
180
182
181
asRole < R > ( role : Role , fn : ( ) => R ) : R {
183
- const session : Session = {
182
+ const session = Session . from ( {
184
183
token : 'system' ,
185
184
issuedAt : DateTime . now ( ) ,
186
185
userId : 'anonymous' as ID ,
187
186
anonymous : false ,
188
187
roles : [ `global:${ role } ` ] ,
189
- } ;
188
+ } ) ;
190
189
return this . sessionHost . withSession ( session , fn ) ;
191
190
}
192
191
193
192
async sessionForUser ( userId : ID ) : Promise < Session > {
194
193
const roles = await this . repo . rolesForUser ( userId ) ;
195
- const session : Session = {
194
+ const session = Session . from ( {
196
195
token : 'system' ,
197
196
issuedAt : DateTime . now ( ) ,
198
197
userId,
199
198
anonymous : false ,
200
199
roles,
201
- } ;
200
+ } ) ;
202
201
return session ;
203
202
}
204
203
}
0 commit comments