Compare commits

..

6 Commits

25 changed files with 196 additions and 129 deletions

View File

@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [2.19.3](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.19.2...@standardnotes/analytics@2.19.3) (2023-01-16)
**Note:** Version bump only for package @standardnotes/analytics
## [2.19.2](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.19.1...@standardnotes/analytics@2.19.2) (2023-01-13)
**Note:** Version bump only for package @standardnotes/analytics

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/analytics",
"version": "2.19.2",
"version": "2.19.3",
"engines": {
"node": ">=18.0.0 <19.0.0"
},

View File

@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.81.10](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.81.9...@standardnotes/auth-server@1.81.10) (2023-01-16)
**Note:** Version bump only for package @standardnotes/auth-server
## [1.81.9](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.81.8...@standardnotes/auth-server@1.81.9) (2023-01-13)
**Note:** Version bump only for package @standardnotes/auth-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/auth-server",
"version": "1.81.9",
"version": "1.81.10",
"engines": {
"node": ">=18.0.0 <19.0.0"
},

View File

@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.11.1](https://github.com/standardnotes/server/compare/@standardnotes/domain-core@1.11.0...@standardnotes/domain-core@1.11.1) (2023-01-16)
### Bug Fixes
* **revisions:** add required role to revisions list response ([e7beee2](https://github.com/standardnotes/server/commit/e7beee278871d2939b058d842404fd6980d7f48a))
# [1.11.0](https://github.com/standardnotes/server/compare/@standardnotes/domain-core@1.10.0...@standardnotes/domain-core@1.11.0) (2022-12-15)
### Features

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/domain-core",
"version": "1.11.0",
"version": "1.11.1",
"engines": {
"node": ">=18.0.0 <19.0.0"
},

View File

@@ -0,0 +1,5 @@
import { Result } from '../Core/Result'
export interface SyncUseCaseInterface<T> {
execute(...args: any[]): Result<T>
}

View File

@@ -35,4 +35,5 @@ export * from './Mapping/MapperInterface'
export * from './Subscription/SubscriptionPlanName'
export * from './Subscription/SubscriptionPlanNameProps'
export * from './UseCase/SyncUseCaseInterface'
export * from './UseCase/UseCaseInterface'

View File

@@ -3,6 +3,24 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.10.8](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.10.7...@standardnotes/revisions-server@1.10.8) (2023-01-16)
### Bug Fixes
* **revisions:** add required role to revisions list response ([e7beee2](https://github.com/standardnotes/server/commit/e7beee278871d2939b058d842404fd6980d7f48a))
## [1.10.7](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.10.6...@standardnotes/revisions-server@1.10.7) (2023-01-16)
### Bug Fixes
* **revisions:** remove redundant specs ([11b8b07](https://github.com/standardnotes/server/commit/11b8b078b4c72f393fd4e555501242ffe22cc06f))
## [1.10.6](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.10.5...@standardnotes/revisions-server@1.10.6) (2023-01-16)
### Bug Fixes
* **revisions:** mapping to snake case ([b97dafe](https://github.com/standardnotes/server/commit/b97dafe6f35ad0f9e42a228f354c4bceb1a2874d))
## [1.10.5](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.10.4...@standardnotes/revisions-server@1.10.5) (2023-01-16)
### Bug Fixes

View File

@@ -7,5 +7,5 @@ module.exports = {
transform: {
...tsjPreset.transform,
},
coveragePathIgnorePatterns: ['/Bootstrap/', 'HealthCheckController', '/Infra/', '/Mapping/'],
coveragePathIgnorePatterns: ['/Bootstrap/', '/Controller/', 'HealthCheckController', '/Infra/', '/Mapping/'],
}

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/revisions-server",
"version": "1.10.5",
"version": "1.10.8",
"engines": {
"node": ">=18.0.0 <19.0.0"
},

View File

@@ -44,6 +44,8 @@ import { CopyRevisions } from '../Domain/UseCase/CopyRevisions/CopyRevisions'
import { RevisionsOwnershipUpdateRequestedEventHandler } from '../Domain/Handler/RevisionsOwnershipUpdateRequestedEventHandler'
import { RevisionHttpMapper } from '../Mapping/RevisionHttpMapper'
import { RevisionMetadataHttpMapper } from '../Mapping/RevisionMetadataHttpMapper'
import { GetRequiredRoleToViewRevision } from '../Domain/UseCase/GetRequiredRoleToViewRevision/GetRequiredRoleToViewRevision'
import { Timer, TimerInterface } from '@standardnotes/time'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const newrelicFormatter = require('@newrelic/winston-enricher')
@@ -104,6 +106,12 @@ export class ContainerConfigLoader {
}
container.bind<AWS.S3 | undefined>(TYPES.S3).toConstantValue(s3Client)
container.bind<TimerInterface>(TYPES.Timer).toConstantValue(new Timer())
container
.bind<GetRequiredRoleToViewRevision>(TYPES.GetRequiredRoleToViewRevision)
.toConstantValue(new GetRequiredRoleToViewRevision(container.get(TYPES.Timer)))
// Map
container
.bind<MapperInterface<RevisionMetadata, TypeORMRevision>>(TYPES.RevisionMetadataPersistenceMapper)
@@ -120,14 +128,14 @@ export class ContainerConfigLoader {
Revision,
{
uuid: string
itemUuid: string
item_uuid: string
content: string | null
contentType: string
itemsKeyId: string | null
encItemKey: string | null
authHash: string | null
createAt: string
updateAt: string
content_type: string
items_key_id: string | null
enc_item_key: string | null
auth_hash: string | null
created_at: string
updated_at: string
}
>
>(TYPES.RevisionHttpMapper)
@@ -138,13 +146,13 @@ export class ContainerConfigLoader {
RevisionMetadata,
{
uuid: string
contentType: string
createdAt: string
updatedAt: string
content_type: string
created_at: string
updated_at: string
}
>
>(TYPES.RevisionMetadataHttpMapper)
.toConstantValue(new RevisionMetadataHttpMapper())
.toConstantValue(new RevisionMetadataHttpMapper(container.get(TYPES.GetRequiredRoleToViewRevision)))
// ORM
container

View File

@@ -30,6 +30,7 @@ const TYPES = {
GetRevision: Symbol.for('GetRevision'),
DeleteRevision: Symbol.for('DeleteRevision'),
CopyRevisions: Symbol.for('CopyRevisions'),
GetRequiredRoleToViewRevision: Symbol.for('GetRequiredRoleToViewRevision'),
// Controller
RevisionsController: Symbol.for('RevisionsController'),
// Handlers

View File

@@ -1,70 +0,0 @@
import { Result } from '@standardnotes/domain-core'
import { Logger } from 'winston'
import { DeleteRevision } from '../Domain/UseCase/DeleteRevision/DeleteRevision'
import { GetRevision } from '../Domain/UseCase/GetRevision/GetRevision'
import { GetRevisionsMetada } from '../Domain/UseCase/GetRevisionsMetada/GetRevisionsMetada'
import { RevisionsController } from './RevisionsController'
describe('RevisionsController', () => {
let getRevisionsMetadata: GetRevisionsMetada
let getRevision: GetRevision
let deleteRevision: DeleteRevision
let logger: Logger
const createController = () => new RevisionsController(getRevisionsMetadata, getRevision, deleteRevision, logger)
beforeEach(() => {
getRevisionsMetadata = {} as jest.Mocked<GetRevisionsMetada>
getRevisionsMetadata.execute = jest.fn().mockReturnValue(Result.ok())
getRevision = {} as jest.Mocked<GetRevision>
getRevision.execute = jest.fn().mockReturnValue(Result.ok())
deleteRevision = {} as jest.Mocked<DeleteRevision>
deleteRevision.execute = jest.fn().mockReturnValue(Result.ok())
logger = {} as jest.Mocked<Logger>
logger.warn = jest.fn()
})
it('should get revisions list', async () => {
const response = await createController().getRevisions({ itemUuid: '1-2-3', userUuid: '1-2-3' })
expect(response.status).toEqual(200)
})
it('should indicate failure to get revisions list', async () => {
getRevisionsMetadata.execute = jest.fn().mockReturnValue(Result.fail('Oops'))
const response = await createController().getRevisions({ itemUuid: '1-2-3', userUuid: '1-2-3' })
expect(response.status).toEqual(400)
})
it('should get revision', async () => {
const response = await createController().getRevision({ revisionUuid: '1-2-3', userUuid: '1-2-3' })
expect(response.status).toEqual(200)
})
it('should indicate failure to get revision', async () => {
getRevision.execute = jest.fn().mockReturnValue(Result.fail('Oops'))
const response = await createController().getRevision({ revisionUuid: '1-2-3', userUuid: '1-2-3' })
expect(response.status).toEqual(400)
})
it('should delete revision', async () => {
const response = await createController().deleteRevision({ revisionUuid: '1-2-3', userUuid: '1-2-3' })
expect(response.status).toEqual(200)
})
it('should indicate failure to delete revision', async () => {
deleteRevision.execute = jest.fn().mockReturnValue(Result.fail('Oops'))
const response = await createController().deleteRevision({ revisionUuid: '1-2-3', userUuid: '1-2-3' })
expect(response.status).toEqual(400)
})
})

View File

@@ -0,0 +1,43 @@
import { TimerInterface } from '@standardnotes/time'
import { GetRequiredRoleToViewRevision } from './GetRequiredRoleToViewRevision'
describe('GetRequiredRoleToViewRevision', () => {
let timer: TimerInterface
const createUseCase = () => new GetRequiredRoleToViewRevision(timer)
beforeEach(() => {
timer = {} as jest.Mocked<TimerInterface>
})
it('should return CoreUser if revision was created less than 30 days ago', () => {
timer.dateWasNDaysAgo = jest.fn().mockReturnValue(29)
const useCase = createUseCase()
const result = useCase.execute({ createdAt: new Date() })
expect(result.getValue()).toEqual('CORE_USER')
})
it('should return PlusUser if revision was created more than 30 days ago and less than 365 days ago', () => {
timer.dateWasNDaysAgo = jest.fn().mockReturnValue(31)
const useCase = createUseCase()
const result = useCase.execute({ createdAt: new Date() })
expect(result.getValue()).toEqual('PLUS_USER')
})
it('should return ProUser if revision was created more than 365 days ago', () => {
timer.dateWasNDaysAgo = jest.fn().mockReturnValue(366)
const useCase = createUseCase()
const result = useCase.execute({ createdAt: new Date() })
expect(result.getValue()).toEqual('PRO_USER')
})
})

View File

@@ -0,0 +1,22 @@
import { Result, RoleName, SyncUseCaseInterface } from '@standardnotes/domain-core'
import { TimerInterface } from '@standardnotes/time'
import { GetRequiredRoleToViewRevisionDTO } from './GetRequiredRoleToViewRevisionDTO'
export class GetRequiredRoleToViewRevision implements SyncUseCaseInterface<string> {
constructor(private timer: TimerInterface) {}
execute(dto: GetRequiredRoleToViewRevisionDTO): Result<string> {
const revisionCreatedNDaysAgo = this.timer.dateWasNDaysAgo(dto.createdAt)
if (revisionCreatedNDaysAgo > 30 && revisionCreatedNDaysAgo < 365) {
return Result.ok(RoleName.NAMES.PlusUser)
}
if (revisionCreatedNDaysAgo > 365) {
return Result.ok(RoleName.NAMES.ProUser)
}
return Result.ok(RoleName.NAMES.CoreUser)
}
}

View File

@@ -0,0 +1,3 @@
export interface GetRequiredRoleToViewRevisionDTO {
createdAt: Date
}

View File

@@ -8,53 +8,52 @@ export class RevisionHttpMapper
Revision,
{
uuid: string
itemUuid: string
item_uuid: string
content: string | null
contentType: string
itemsKeyId: string | null
encItemKey: string | null
authHash: string | null
createAt: string
updateAt: string
content_type: string
items_key_id: string | null
enc_item_key: string | null
auth_hash: string | null
created_at: string
updated_at: string
}
>
{
toDomain(_projection: {
uuid: string
itemUuid: string
userUuid: string | null
item_uuid: string
content: string | null
contentType: string
itemsKeyId: string | null
encItemKey: string | null
authHash: string | null
createAt: string
updateAt: string
content_type: string
items_key_id: string | null
enc_item_key: string | null
auth_hash: string | null
created_at: string
updated_at: string
}): Revision {
throw new Error('Method not implemented.')
}
toProjection(domain: Revision): {
uuid: string
itemUuid: string
item_uuid: string
content: string | null
contentType: string
itemsKeyId: string | null
encItemKey: string | null
authHash: string | null
createAt: string
updateAt: string
content_type: string
items_key_id: string | null
enc_item_key: string | null
auth_hash: string | null
created_at: string
updated_at: string
} {
return {
uuid: domain.id.toString(),
itemUuid: domain.props.itemUuid.value,
item_uuid: domain.props.itemUuid.value,
content: domain.props.content,
contentType: domain.props.contentType.value as string,
itemsKeyId: domain.props.itemsKeyId,
encItemKey: domain.props.encItemKey,
authHash: domain.props.authHash,
createAt: domain.props.dates.createdAt.toISOString(),
updateAt: domain.props.dates.updatedAt.toISOString(),
content_type: domain.props.contentType.value as string,
items_key_id: domain.props.itemsKeyId,
enc_item_key: domain.props.encItemKey,
auth_hash: domain.props.authHash,
created_at: domain.props.dates.createdAt.toISOString(),
updated_at: domain.props.dates.updatedAt.toISOString(),
}
}
}

View File

@@ -1,4 +1,4 @@
import { MapperInterface } from '@standardnotes/domain-core'
import { MapperInterface, SyncUseCaseInterface } from '@standardnotes/domain-core'
import { RevisionMetadata } from '../Domain/Revision/RevisionMetadata'
@@ -8,27 +8,38 @@ export class RevisionMetadataHttpMapper
RevisionMetadata,
{
uuid: string
contentType: string
createdAt: string
updatedAt: string
content_type: string
created_at: string
updated_at: string
required_role: string
}
>
{
toDomain(_projection: { uuid: string; contentType: string; createdAt: string; updatedAt: string }): RevisionMetadata {
constructor(private getRequiredRoleToViewRevision: SyncUseCaseInterface<string>) {}
toDomain(_projection: {
uuid: string
content_type: string
created_at: string
updated_at: string
required_role: string
}): RevisionMetadata {
throw new Error('Method not implemented.')
}
toProjection(domain: RevisionMetadata): {
uuid: string
contentType: string
createdAt: string
updatedAt: string
content_type: string
created_at: string
updated_at: string
required_role: string
} {
return {
uuid: domain.id.toString(),
contentType: domain.props.contentType.value as string,
createdAt: domain.props.dates.createdAt.toISOString(),
updatedAt: domain.props.dates.updatedAt.toISOString(),
content_type: domain.props.contentType.value as string,
created_at: domain.props.dates.createdAt.toISOString(),
updated_at: domain.props.dates.updatedAt.toISOString(),
required_role: this.getRequiredRoleToViewRevision.execute({ createdAt: domain.props.dates.createdAt }).getValue(),
}
}
}

View File

@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.16.7](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.16.6...@standardnotes/scheduler-server@1.16.7) (2023-01-16)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.16.6](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.16.5...@standardnotes/scheduler-server@1.16.6) (2023-01-13)
**Note:** Version bump only for package @standardnotes/scheduler-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/scheduler-server",
"version": "1.16.6",
"version": "1.16.7",
"engines": {
"node": ">=18.0.0 <19.0.0"
},

View File

@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.28.7](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.28.6...@standardnotes/syncing-server@1.28.7) (2023-01-16)
**Note:** Version bump only for package @standardnotes/syncing-server
## [1.28.6](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.28.5...@standardnotes/syncing-server@1.28.6) (2023-01-13)
**Note:** Version bump only for package @standardnotes/syncing-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/syncing-server",
"version": "1.28.6",
"version": "1.28.7",
"engines": {
"node": ">=18.0.0 <19.0.0"
},

View File

@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.19.6](https://github.com/standardnotes/server/compare/@standardnotes/workspace-server@1.19.5...@standardnotes/workspace-server@1.19.6) (2023-01-16)
**Note:** Version bump only for package @standardnotes/workspace-server
## [1.19.5](https://github.com/standardnotes/server/compare/@standardnotes/workspace-server@1.19.4...@standardnotes/workspace-server@1.19.5) (2023-01-13)
**Note:** Version bump only for package @standardnotes/workspace-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/workspace-server",
"version": "1.19.5",
"version": "1.19.6",
"engines": {
"node": ">=18.0.0 <19.0.0"
},