mirror of
https://github.com/standardnotes/server
synced 2026-09-12 15:45:26 -04:00
feat(domain-core): add legacy session model
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { LegacySession } from './LegacySession'
|
||||
|
||||
describe('LegacySession', () => {
|
||||
it('should create a value object', () => {
|
||||
const valueOrError = LegacySession.create('foobar')
|
||||
|
||||
expect(valueOrError.isFailed()).toBeFalsy()
|
||||
expect(valueOrError.getValue().accessToken).toEqual('foobar')
|
||||
})
|
||||
|
||||
it('should not create an invalid value object', () => {
|
||||
const valueOrError = LegacySession.create('')
|
||||
|
||||
expect(valueOrError.isFailed()).toBeTruthy()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,22 @@
|
||||
import { ValueObject } from '../Core/ValueObject'
|
||||
import { Result } from '../Core/Result'
|
||||
import { LegacySessionProps } from './LegacySessionProps'
|
||||
import { Validator } from '../Core/Validator'
|
||||
|
||||
export class LegacySession extends ValueObject<LegacySessionProps> {
|
||||
get accessToken(): string {
|
||||
return this.props.token
|
||||
}
|
||||
|
||||
private constructor(props: LegacySessionProps) {
|
||||
super(props)
|
||||
}
|
||||
|
||||
static create(token: string): Result<LegacySession> {
|
||||
if (Validator.isNotEmpty(token).isFailed()) {
|
||||
return Result.fail<LegacySession>('Could not create legacy session. Token value is empty')
|
||||
}
|
||||
|
||||
return Result.ok<LegacySession>(new LegacySession({ token }))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface LegacySessionProps {
|
||||
token: string
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
export * from './Auth/LegacySession'
|
||||
export * from './Auth/LegacySessionProps'
|
||||
export * from './Auth/Session'
|
||||
export * from './Auth/SessionProps'
|
||||
export * from './Auth/SessionToken'
|
||||
|
||||
Reference in New Issue
Block a user