Skip to content

Commit 57f8bb2

Browse files
committed
refactor(service): users/auth: rename some session repository methods for consistency
1 parent 1f82c17 commit 57f8bb2

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

service/src/ingress/ingress.adapters.db.mongoose.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ export class UserIngressBindingsMongooseRepository implements UserIngressBinding
157157

158158
constructor(readonly model: UserIngressBindingsModel) {}
159159

160-
async readBindingsForUser(userId: UserId): Promise<UserIngressBindings> {
160+
async readBindingsForUser(userId: UserId): Promise<UserIngressBindings | null> {
161161
const doc = await this.model.findById(userId, null, { lean: true })
162-
return { userId, bindingsByIdp: new Map(Object.entries(doc?.bindings || {})) }
162+
return doc ? { userId, bindingsByIdp: new Map(Object.entries(doc?.bindings || {})) } : null
163163
}
164164

165165
async readAllBindingsForIdp(idpId: IdentityProviderId, paging?: PagingParameters | undefined): Promise<PageOf<UserIngressBindings>> {

service/src/ingress/ingress.entities.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ export type SessionExpanded = Omit<Session, 'user' | 'device'> & {
1919
}
2020

2121
export interface SessionRepository {
22-
findSessionByToken(token: string): Promise<Session | null>
22+
readSessionByToken(token: string): Promise<Session | null>
2323
createOrRefreshSession(userId: UserId, deviceId?: string): Promise<Session>
24-
removeSession(token: string): Promise<Session | null>
25-
removeSessionsForUser(userId: UserId): Promise<number>
26-
removeSessionsForDevice(deviceId: DeviceId): Promise<number>
24+
deleteSession(token: string): Promise<Session | null>
25+
deleteSessionsForUser(userId: UserId): Promise<number>
26+
deleteSessionsForDevice(deviceId: DeviceId): Promise<number>
2727
}
2828

2929
/**
@@ -82,6 +82,10 @@ export interface DeviceEnrollmentPolicy {
8282
* The identity provider user is the result of mapping a specific IDP account to a Mage user account.
8383
*/
8484
export type IdentityProviderUser = Pick<User, 'username' | 'displayName' | 'email' | 'phones'>
85+
& {
86+
idpAccountId?: string
87+
idpAccountAttrs?: Record<string, any>
88+
}
8589

8690
/**
8791
* A user ingress binding is the bridge between a Mage user and an identity provider account. When a user attempts
@@ -90,6 +94,8 @@ export type IdentityProviderUser = Pick<User, 'username' | 'displayName' | 'emai
9094
*/
9195
export interface UserIngressBinding {
9296
idpId: IdentityProviderId
97+
created: Date
98+
updated: Date
9399
// TODO: evaluate for utility of disabling a single ingress/idp path for a user as opposed to the entire account
94100
// verified: boolean
95101
// enabled: boolean
@@ -124,8 +130,15 @@ export interface IdentityProviderRepository {
124130
}
125131

126132
export interface UserIngressBindingsRepository {
127-
readBindingsForUser(userId: UserId): Promise<UserIngressBindings>
133+
/**
134+
* Return null if the user has no persisted bindings entry.
135+
*/
136+
readBindingsForUser(userId: UserId): Promise<UserIngressBindings | null>
128137
readAllBindingsForIdp(idpId: IdentityProviderId, paging?: PagingParameters): Promise<PageOf<UserIngressBindings>>
138+
/**
139+
* Save the given ingress binding to the bindings dictionary for the given user, creating or updating as necessary.
140+
* Return the modified ingress bindings.
141+
*/
129142
saveUserIngressBinding(userId: UserId, binding: UserIngressBinding): Promise<UserIngressBindings | Error>
130143
/**
131144
* Return the binding that was deleted, or null if the user did not have a binding to the given IDP.

0 commit comments

Comments
 (0)