@webiny/api-record-locking 0.0.0-unstable.a4637c5ce6 → 0.0.0-unstable.a4f3e4ea8b
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/README.md +10 -9
- package/domain/LockRecord.d.ts +45 -0
- package/domain/LockRecord.js +73 -0
- package/domain/LockRecord.js.map +1 -0
- package/domain/RecordLockingModel.d.ts +9 -0
- package/domain/RecordLockingModel.js +32 -0
- package/domain/RecordLockingModel.js.map +1 -0
- package/domain/abstractions.d.ts +18 -0
- package/domain/abstractions.js +6 -0
- package/domain/abstractions.js.map +1 -0
- package/domain/calculateExpiresOn.d.ts +1 -0
- package/domain/calculateExpiresOn.js +8 -0
- package/domain/calculateExpiresOn.js.map +1 -0
- package/domain/errors.d.ts +71 -0
- package/domain/errors.js +85 -0
- package/domain/errors.js.map +1 -0
- package/domain/index.d.ts +4 -0
- package/domain/index.js +4 -0
- package/domain/types.d.ts +44 -0
- package/domain/types.js +9 -0
- package/domain/types.js.map +1 -0
- package/features/GetLockRecord/GetLockRecordRepository.d.ts +16 -0
- package/features/GetLockRecord/GetLockRecordRepository.js +40 -0
- package/features/GetLockRecord/GetLockRecordRepository.js.map +1 -0
- package/features/GetLockRecord/GetLockRecordUseCase.d.ts +12 -0
- package/features/GetLockRecord/GetLockRecordUseCase.js +18 -0
- package/features/GetLockRecord/GetLockRecordUseCase.js.map +1 -0
- package/features/GetLockRecord/abstractions.d.ts +41 -0
- package/features/GetLockRecord/abstractions.js +6 -0
- package/features/GetLockRecord/abstractions.js.map +1 -0
- package/features/GetLockRecord/feature.d.ts +4 -0
- package/features/GetLockRecord/feature.js +13 -0
- package/features/GetLockRecord/feature.js.map +1 -0
- package/features/GetLockRecord/index.d.ts +2 -0
- package/features/GetLockRecord/index.js +2 -0
- package/features/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.d.ts +15 -0
- package/features/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js +30 -0
- package/features/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js.map +1 -0
- package/features/GetLockedEntryLockRecord/abstractions.d.ts +26 -0
- package/features/GetLockedEntryLockRecord/abstractions.js +5 -0
- package/features/GetLockedEntryLockRecord/abstractions.js.map +1 -0
- package/features/GetLockedEntryLockRecord/feature.d.ts +4 -0
- package/features/GetLockedEntryLockRecord/feature.js +11 -0
- package/features/GetLockedEntryLockRecord/feature.js.map +1 -0
- package/features/GetLockedEntryLockRecord/index.d.ts +2 -0
- package/features/GetLockedEntryLockRecord/index.js +2 -0
- package/features/IsEntryLocked/IsEntryLockedUseCase.d.ts +14 -0
- package/features/IsEntryLocked/IsEntryLockedUseCase.js +33 -0
- package/features/IsEntryLocked/IsEntryLockedUseCase.js.map +1 -0
- package/features/IsEntryLocked/abstractions.d.ts +24 -0
- package/features/IsEntryLocked/abstractions.js +5 -0
- package/features/IsEntryLocked/abstractions.js.map +1 -0
- package/features/IsEntryLocked/feature.d.ts +4 -0
- package/features/IsEntryLocked/feature.js +11 -0
- package/features/IsEntryLocked/feature.js.map +1 -0
- package/features/IsEntryLocked/index.d.ts +1 -0
- package/features/IsEntryLocked/index.js +1 -0
- package/features/KickOutCurrentUser/KickOutCurrentUserUseCase.d.ts +15 -0
- package/features/KickOutCurrentUser/KickOutCurrentUserUseCase.js +36 -0
- package/features/KickOutCurrentUser/KickOutCurrentUserUseCase.js.map +1 -0
- package/features/KickOutCurrentUser/abstractions.d.ts +17 -0
- package/features/KickOutCurrentUser/abstractions.js +5 -0
- package/features/KickOutCurrentUser/abstractions.js.map +1 -0
- package/features/KickOutCurrentUser/feature.d.ts +4 -0
- package/features/KickOutCurrentUser/feature.js +11 -0
- package/features/KickOutCurrentUser/feature.js.map +1 -0
- package/features/KickOutCurrentUser/index.d.ts +1 -0
- package/features/KickOutCurrentUser/index.js +1 -0
- package/features/ListAllLockRecords/ListAllLockRecordsRepository.d.ts +18 -0
- package/features/ListAllLockRecords/ListAllLockRecordsRepository.js +49 -0
- package/features/ListAllLockRecords/ListAllLockRecordsRepository.js.map +1 -0
- package/features/ListAllLockRecords/ListAllLockRecordsUseCase.d.ts +11 -0
- package/features/ListAllLockRecords/ListAllLockRecordsUseCase.js +18 -0
- package/features/ListAllLockRecords/ListAllLockRecordsUseCase.js.map +1 -0
- package/features/ListAllLockRecords/abstractions.d.ts +40 -0
- package/features/ListAllLockRecords/abstractions.js +6 -0
- package/features/ListAllLockRecords/abstractions.js.map +1 -0
- package/features/ListAllLockRecords/feature.d.ts +4 -0
- package/features/ListAllLockRecords/feature.js +13 -0
- package/features/ListAllLockRecords/feature.js.map +1 -0
- package/features/ListAllLockRecords/index.d.ts +2 -0
- package/features/ListAllLockRecords/index.js +2 -0
- package/features/ListLockRecords/ListLockRecordsRepository.d.ts +17 -0
- package/features/ListLockRecords/ListLockRecordsRepository.js +49 -0
- package/features/ListLockRecords/ListLockRecordsRepository.js.map +1 -0
- package/features/ListLockRecords/ListLockRecordsUseCase.d.ts +15 -0
- package/features/ListLockRecords/ListLockRecordsUseCase.js +33 -0
- package/features/ListLockRecords/ListLockRecordsUseCase.js.map +1 -0
- package/features/ListLockRecords/abstractions.d.ts +45 -0
- package/features/ListLockRecords/abstractions.js +6 -0
- package/features/ListLockRecords/abstractions.js.map +1 -0
- package/features/ListLockRecords/feature.d.ts +4 -0
- package/features/ListLockRecords/feature.js +13 -0
- package/features/ListLockRecords/feature.js.map +1 -0
- package/features/ListLockRecords/index.d.ts +1 -0
- package/features/ListLockRecords/index.js +1 -0
- package/features/LockEntry/LockEntryEventsDecorator.d.ts +14 -0
- package/features/LockEntry/LockEntryEventsDecorator.js +40 -0
- package/features/LockEntry/LockEntryEventsDecorator.js.map +1 -0
- package/features/LockEntry/LockEntryRepository.d.ts +16 -0
- package/features/LockEntry/LockEntryRepository.js +45 -0
- package/features/LockEntry/LockEntryRepository.js.map +1 -0
- package/features/LockEntry/LockEntryUseCase.d.ts +14 -0
- package/features/LockEntry/LockEntryUseCase.js +31 -0
- package/features/LockEntry/LockEntryUseCase.js.map +1 -0
- package/features/LockEntry/abstractions.d.ts +41 -0
- package/features/LockEntry/abstractions.js +6 -0
- package/features/LockEntry/abstractions.js.map +1 -0
- package/features/LockEntry/events.d.ts +45 -0
- package/features/LockEntry/events.js +32 -0
- package/features/LockEntry/events.js.map +1 -0
- package/features/LockEntry/feature.d.ts +4 -0
- package/features/LockEntry/feature.js +15 -0
- package/features/LockEntry/feature.js.map +1 -0
- package/features/LockEntry/index.d.ts +1 -0
- package/features/LockEntry/index.js +1 -0
- package/features/RecordLockingFeature.d.ts +15 -0
- package/features/RecordLockingFeature.js +34 -0
- package/features/RecordLockingFeature.js.map +1 -0
- package/features/UnlockEntry/UnlockEntryEventsDecorator.d.ts +14 -0
- package/features/UnlockEntry/UnlockEntryEventsDecorator.js +41 -0
- package/features/UnlockEntry/UnlockEntryEventsDecorator.js.map +1 -0
- package/features/UnlockEntry/UnlockEntryRepository.d.ts +14 -0
- package/features/UnlockEntry/UnlockEntryRepository.js +42 -0
- package/features/UnlockEntry/UnlockEntryRepository.js.map +1 -0
- package/features/UnlockEntry/UnlockEntryUseCase.d.ts +18 -0
- package/features/UnlockEntry/UnlockEntryUseCase.js +65 -0
- package/features/UnlockEntry/UnlockEntryUseCase.js.map +1 -0
- package/features/UnlockEntry/abstractions.d.ts +44 -0
- package/features/UnlockEntry/abstractions.js +6 -0
- package/features/UnlockEntry/abstractions.js.map +1 -0
- package/features/UnlockEntry/events.d.ts +46 -0
- package/features/UnlockEntry/events.js +32 -0
- package/features/UnlockEntry/events.js.map +1 -0
- package/features/UnlockEntry/feature.d.ts +4 -0
- package/features/UnlockEntry/feature.js +15 -0
- package/features/UnlockEntry/feature.js.map +1 -0
- package/features/UnlockEntry/hasFullAccessPermission.d.ts +2 -0
- package/features/UnlockEntry/hasFullAccessPermission.js +9 -0
- package/features/UnlockEntry/hasFullAccessPermission.js.map +1 -0
- package/features/UnlockEntry/index.d.ts +1 -0
- package/features/UnlockEntry/index.js +1 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestEventsDecorator.d.ts +14 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestEventsDecorator.js +40 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestEventsDecorator.js.map +1 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestRepository.d.ts +17 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestRepository.js +44 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestRepository.js.map +1 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestUseCase.d.ts +16 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestUseCase.js +75 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestUseCase.js.map +1 -0
- package/features/UnlockEntryRequest/abstractions.d.ts +42 -0
- package/features/UnlockEntryRequest/abstractions.js +6 -0
- package/features/UnlockEntryRequest/abstractions.js.map +1 -0
- package/features/UnlockEntryRequest/events.d.ts +45 -0
- package/features/UnlockEntryRequest/events.js +32 -0
- package/features/UnlockEntryRequest/events.js.map +1 -0
- package/features/UnlockEntryRequest/feature.d.ts +4 -0
- package/features/UnlockEntryRequest/feature.js +15 -0
- package/features/UnlockEntryRequest/feature.js.map +1 -0
- package/features/UnlockEntryRequest/index.d.ts +3 -0
- package/features/UnlockEntryRequest/index.js +3 -0
- package/features/UpdateEntryLock/UpdateEntryLockRepository.d.ts +20 -0
- package/features/UpdateEntryLock/UpdateEntryLockRepository.js +60 -0
- package/features/UpdateEntryLock/UpdateEntryLockRepository.js.map +1 -0
- package/features/UpdateEntryLock/UpdateEntryLockUseCase.d.ts +18 -0
- package/features/UpdateEntryLock/UpdateEntryLockUseCase.js +51 -0
- package/features/UpdateEntryLock/UpdateEntryLockUseCase.js.map +1 -0
- package/features/UpdateEntryLock/abstractions.d.ts +42 -0
- package/features/UpdateEntryLock/abstractions.js +6 -0
- package/features/UpdateEntryLock/abstractions.js.map +1 -0
- package/features/UpdateEntryLock/feature.d.ts +4 -0
- package/features/UpdateEntryLock/feature.js +13 -0
- package/features/UpdateEntryLock/feature.js.map +1 -0
- package/features/UpdateEntryLock/index.d.ts +1 -0
- package/features/UpdateEntryLock/index.js +1 -0
- package/graphql/checkPermissions.d.ts +5 -0
- package/graphql/checkPermissions.js +10 -0
- package/graphql/checkPermissions.js.map +1 -0
- package/{utils → graphql}/resolve.d.ts +2 -2
- package/graphql/resolve.js +20 -0
- package/graphql/resolve.js.map +1 -0
- package/graphql/schema.d.ts +7 -3
- package/graphql/schema.js +162 -145
- package/graphql/schema.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +55 -34
- package/index.js.map +1 -1
- package/package.json +29 -28
- package/types.d.ts +3 -132
- package/types.js +6 -27
- package/types.js.map +1 -1
- package/utils/convertWhereCondition.d.ts +1 -1
- package/utils/convertWhereCondition.js +21 -36
- package/utils/convertWhereCondition.js.map +1 -1
- package/utils/getTimeout.js +8 -22
- package/utils/getTimeout.js.map +1 -1
- package/utils/lockRecordDatabaseId.js +7 -20
- package/utils/lockRecordDatabaseId.js.map +1 -1
- package/abstractions/IGetLockRecordUseCase.d.ts +0 -8
- package/abstractions/IGetLockRecordUseCase.js +0 -7
- package/abstractions/IGetLockRecordUseCase.js.map +0 -1
- package/abstractions/IGetLockedEntryLockRecordUseCase.d.ts +0 -8
- package/abstractions/IGetLockedEntryLockRecordUseCase.js +0 -7
- package/abstractions/IGetLockedEntryLockRecordUseCase.js.map +0 -1
- package/abstractions/IIsEntryLocked.d.ts +0 -8
- package/abstractions/IIsEntryLocked.js +0 -7
- package/abstractions/IIsEntryLocked.js.map +0 -1
- package/abstractions/IKickOutCurrentUserUseCase.d.ts +0 -5
- package/abstractions/IKickOutCurrentUserUseCase.js +0 -7
- package/abstractions/IKickOutCurrentUserUseCase.js.map +0 -1
- package/abstractions/IListAllLockRecordsUseCase.d.ts +0 -9
- package/abstractions/IListAllLockRecordsUseCase.js +0 -7
- package/abstractions/IListAllLockRecordsUseCase.js.map +0 -1
- package/abstractions/IListLockRecordsUseCase.d.ts +0 -10
- package/abstractions/IListLockRecordsUseCase.js +0 -7
- package/abstractions/IListLockRecordsUseCase.js.map +0 -1
- package/abstractions/ILockEntryUseCase.d.ts +0 -11
- package/abstractions/ILockEntryUseCase.js +0 -7
- package/abstractions/ILockEntryUseCase.js.map +0 -1
- package/abstractions/IUnlockEntryRequestUseCase.d.ts +0 -11
- package/abstractions/IUnlockEntryRequestUseCase.js +0 -7
- package/abstractions/IUnlockEntryRequestUseCase.js.map +0 -1
- package/abstractions/IUnlockEntryUseCase.d.ts +0 -12
- package/abstractions/IUnlockEntryUseCase.js +0 -7
- package/abstractions/IUnlockEntryUseCase.js.map +0 -1
- package/abstractions/IUpdateEntryLockUseCase.d.ts +0 -11
- package/abstractions/IUpdateEntryLockUseCase.js +0 -7
- package/abstractions/IUpdateEntryLockUseCase.js.map +0 -1
- package/crud/crud.d.ts +0 -7
- package/crud/crud.js +0 -204
- package/crud/crud.js.map +0 -1
- package/crud/model.d.ts +0 -2
- package/crud/model.js +0 -127
- package/crud/model.js.map +0 -1
- package/useCases/GetLockRecord/GetLockRecordUseCase.d.ts +0 -16
- package/useCases/GetLockRecord/GetLockRecordUseCase.js +0 -39
- package/useCases/GetLockRecord/GetLockRecordUseCase.js.map +0 -1
- package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.d.ts +0 -16
- package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js +0 -29
- package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js.map +0 -1
- package/useCases/IsEntryLocked/IsEntryLockedUseCase.d.ts +0 -13
- package/useCases/IsEntryLocked/IsEntryLockedUseCase.js +0 -31
- package/useCases/IsEntryLocked/IsEntryLockedUseCase.js.map +0 -1
- package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.d.ts +0 -12
- package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.js +0 -46
- package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.js.map +0 -1
- package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.d.ts +0 -13
- package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.js +0 -34
- package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.js.map +0 -1
- package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.d.ts +0 -14
- package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.js +0 -27
- package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.js.map +0 -1
- package/useCases/LockEntryUseCase/LockEntryUseCase.d.ts +0 -21
- package/useCases/LockEntryUseCase/LockEntryUseCase.js +0 -64
- package/useCases/LockEntryUseCase/LockEntryUseCase.js.map +0 -1
- package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.d.ts +0 -23
- package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.js +0 -90
- package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.js.map +0 -1
- package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.d.ts +0 -21
- package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.js +0 -82
- package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.js.map +0 -1
- package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.d.ts +0 -26
- package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.js +0 -93
- package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.js.map +0 -1
- package/useCases/index.d.ts +0 -31
- package/useCases/index.js +0 -96
- package/useCases/index.js.map +0 -1
- package/useCases/types.d.ts +0 -5
- package/useCases/types.js +0 -7
- package/useCases/types.js.map +0 -1
- package/utils/calculateExpiresOn.d.ts +0 -2
- package/utils/calculateExpiresOn.js +0 -16
- package/utils/calculateExpiresOn.js.map +0 -1
- package/utils/checkPermissions.d.ts +0 -7
- package/utils/checkPermissions.js +0 -21
- package/utils/checkPermissions.js.map +0 -1
- package/utils/convertEntryToLockRecord.d.ts +0 -28
- package/utils/convertEntryToLockRecord.js +0 -91
- package/utils/convertEntryToLockRecord.js.map +0 -1
- package/utils/resolve.js +0 -30
- package/utils/resolve.js.map +0 -1
- package/utils/validateSameIdentity.d.ts +0 -6
- package/utils/validateSameIdentity.js +0 -24
- package/utils/validateSameIdentity.js.map +0 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { UnlockEntryRequestUseCase } from "./abstractions.js";
|
|
2
|
+
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
|
+
import { EntryAfterUnlockRequestEvent, EntryBeforeUnlockRequestEvent, EntryUnlockRequestErrorEvent } from "./events.js";
|
|
4
|
+
class UnlockEntryRequestEventsDecoratorImpl {
|
|
5
|
+
constructor(eventPublisher, decoratee){
|
|
6
|
+
this.eventPublisher = eventPublisher;
|
|
7
|
+
this.decoratee = decoratee;
|
|
8
|
+
}
|
|
9
|
+
async execute(input) {
|
|
10
|
+
await this.eventPublisher.publish(new EntryBeforeUnlockRequestEvent({
|
|
11
|
+
id: input.id,
|
|
12
|
+
type: input.type
|
|
13
|
+
}));
|
|
14
|
+
const result = await this.decoratee.execute(input);
|
|
15
|
+
if (result.isFail()) {
|
|
16
|
+
const error = result.error;
|
|
17
|
+
await this.eventPublisher.publish(new EntryUnlockRequestErrorEvent({
|
|
18
|
+
id: input.id,
|
|
19
|
+
type: input.type,
|
|
20
|
+
error
|
|
21
|
+
}));
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
await this.eventPublisher.publish(new EntryAfterUnlockRequestEvent({
|
|
25
|
+
id: input.id,
|
|
26
|
+
type: input.type,
|
|
27
|
+
record: result.value
|
|
28
|
+
}));
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const UnlockEntryRequestEventsDecorator = UnlockEntryRequestUseCase.createDecorator({
|
|
33
|
+
decorator: UnlockEntryRequestEventsDecoratorImpl,
|
|
34
|
+
dependencies: [
|
|
35
|
+
EventPublisher
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
export { UnlockEntryRequestEventsDecorator };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=UnlockEntryRequestEventsDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/UnlockEntryRequest/UnlockEntryRequestEventsDecorator.js","sources":["../../../src/features/UnlockEntryRequest/UnlockEntryRequestEventsDecorator.ts"],"sourcesContent":["import {\n type UnlockEntryRequestInput,\n UnlockEntryRequestUseCase as UseCaseAbstraction,\n UnlockEntryRequestUseCase\n} from \"./abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { ILockRecord } from \"~/domain/index.js\";\nimport { Result } from \"@webiny/feature/api/index.js\";\nimport {\n EntryAfterUnlockRequestEvent,\n EntryBeforeUnlockRequestEvent,\n EntryUnlockRequestErrorEvent\n} from \"./events.js\";\n\nclass UnlockEntryRequestEventsDecoratorImpl implements UnlockEntryRequestUseCase.Interface {\n constructor(\n private readonly eventPublisher: EventPublisher.Interface,\n private readonly decoratee: UnlockEntryRequestUseCase.Interface\n ) {}\n\n async execute(\n input: UnlockEntryRequestInput\n ): Promise<Result<ILockRecord, UseCaseAbstraction.Error>> {\n // Publish before event\n await this.eventPublisher.publish(\n new EntryBeforeUnlockRequestEvent({\n id: input.id,\n type: input.type\n })\n );\n\n const result = await this.decoratee.execute(input);\n\n if (result.isFail()) {\n const error = result.error;\n\n await this.eventPublisher.publish(\n new EntryUnlockRequestErrorEvent({\n id: input.id,\n type: input.type,\n error\n })\n );\n\n return result;\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new EntryAfterUnlockRequestEvent({\n id: input.id,\n type: input.type,\n record: result.value\n })\n );\n\n return result;\n }\n}\n\nexport const UnlockEntryRequestEventsDecorator = UnlockEntryRequestUseCase.createDecorator({\n decorator: UnlockEntryRequestEventsDecoratorImpl,\n dependencies: [EventPublisher]\n});\n"],"names":["UnlockEntryRequestEventsDecoratorImpl","eventPublisher","decoratee","input","EntryBeforeUnlockRequestEvent","result","error","EntryUnlockRequestErrorEvent","EntryAfterUnlockRequestEvent","UnlockEntryRequestEventsDecorator","UnlockEntryRequestUseCase","EventPublisher"],"mappings":";;;AAcA,MAAMA;IACF,YACqBC,cAAwC,EACxCC,SAA8C,CACjE;aAFmBD,cAAc,GAAdA;aACAC,SAAS,GAATA;IAClB;IAEH,MAAM,QACFC,KAA8B,EACwB;QAEtD,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,8BAA8B;YAC9B,IAAID,MAAM,EAAE;YACZ,MAAMA,MAAM,IAAI;QACpB;QAGJ,MAAME,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACF;QAE5C,IAAIE,OAAO,MAAM,IAAI;YACjB,MAAMC,QAAQD,OAAO,KAAK;YAE1B,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIE,6BAA6B;gBAC7B,IAAIJ,MAAM,EAAE;gBACZ,MAAMA,MAAM,IAAI;gBAChBG;YACJ;YAGJ,OAAOD;QACX;QAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIG,6BAA6B;YAC7B,IAAIL,MAAM,EAAE;YACZ,MAAMA,MAAM,IAAI;YAChB,QAAQE,OAAO,KAAK;QACxB;QAGJ,OAAOA;IACX;AACJ;AAEO,MAAMI,oCAAoCC,0BAA0B,eAAe,CAAC;IACvF,WAAWV;IACX,cAAc;QAACW;KAAe;AAClC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { UnlockEntryRequestRepository as RepositoryAbstraction } from "./abstractions.js";
|
|
3
|
+
import { UpdateEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UpdateEntry";
|
|
4
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
|
+
import type { ILockRecord } from "../../domain/LockRecord.js";
|
|
6
|
+
import type { CmsModel } from "@webiny/api-headless-cms/types";
|
|
7
|
+
declare class UnlockEntryRequestRepositoryImpl implements RepositoryAbstraction.Interface {
|
|
8
|
+
private updateEntry;
|
|
9
|
+
private identityContext;
|
|
10
|
+
private model;
|
|
11
|
+
constructor(updateEntry: UpdateEntryUseCase.Interface, identityContext: IdentityContext.Interface, model: CmsModel);
|
|
12
|
+
update(record: ILockRecord): Promise<Result<ILockRecord, RepositoryAbstraction.Error>>;
|
|
13
|
+
}
|
|
14
|
+
export declare const UnlockEntryRequestRepository: typeof UnlockEntryRequestRepositoryImpl & {
|
|
15
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IUnlockEntryRequestRepository>;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { UnlockEntryRequestRepository } from "./abstractions.js";
|
|
3
|
+
import { UpdateEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UpdateEntry";
|
|
4
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
|
+
import { RecordLockingModel } from "../../domain/abstractions.js";
|
|
6
|
+
import { UnlockEntryRequestError } from "../../domain/errors.js";
|
|
7
|
+
import { createLockRecordDatabaseId } from "../../utils/lockRecordDatabaseId.js";
|
|
8
|
+
import { createIdentifier } from "@webiny/utils";
|
|
9
|
+
class UnlockEntryRequestRepositoryImpl {
|
|
10
|
+
constructor(updateEntry, identityContext, model){
|
|
11
|
+
this.updateEntry = updateEntry;
|
|
12
|
+
this.identityContext = identityContext;
|
|
13
|
+
this.model = model;
|
|
14
|
+
}
|
|
15
|
+
async update(record) {
|
|
16
|
+
try {
|
|
17
|
+
const entryId = createLockRecordDatabaseId(record.id);
|
|
18
|
+
const id = createIdentifier({
|
|
19
|
+
id: entryId,
|
|
20
|
+
version: 1
|
|
21
|
+
});
|
|
22
|
+
const recordValues = record.toObject();
|
|
23
|
+
const result = await this.identityContext.withoutAuthorization(async ()=>await this.updateEntry.execute(this.model, id, {
|
|
24
|
+
...recordValues,
|
|
25
|
+
values: recordValues
|
|
26
|
+
}));
|
|
27
|
+
if (result.isFail()) return Result.fail(new UnlockEntryRequestError(result.error));
|
|
28
|
+
return Result.ok(record);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
return Result.fail(new UnlockEntryRequestError(error));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const UnlockEntryRequestRepository_UnlockEntryRequestRepository = UnlockEntryRequestRepository.createImplementation({
|
|
35
|
+
implementation: UnlockEntryRequestRepositoryImpl,
|
|
36
|
+
dependencies: [
|
|
37
|
+
UpdateEntryUseCase,
|
|
38
|
+
IdentityContext,
|
|
39
|
+
RecordLockingModel
|
|
40
|
+
]
|
|
41
|
+
});
|
|
42
|
+
export { UnlockEntryRequestRepository_UnlockEntryRequestRepository as UnlockEntryRequestRepository };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=UnlockEntryRequestRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/UnlockEntryRequest/UnlockEntryRequestRepository.js","sources":["../../../src/features/UnlockEntryRequest/UnlockEntryRequestRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { UnlockEntryRequestRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { UpdateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { RecordLockingModel } from \"~/domain/abstractions.js\";\nimport type { ILockRecord } from \"~/domain/LockRecord.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { UnlockEntryRequestError } from \"~/domain/errors.js\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId.js\";\nimport { createIdentifier } from \"@webiny/utils\";\n\nclass UnlockEntryRequestRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private updateEntry: UpdateEntryUseCase.Interface,\n private identityContext: IdentityContext.Interface,\n private model: CmsModel\n ) {}\n\n async update(record: ILockRecord): Promise<Result<ILockRecord, RepositoryAbstraction.Error>> {\n try {\n const entryId = createLockRecordDatabaseId(record.id);\n const id = createIdentifier({\n id: entryId,\n version: 1\n });\n\n const recordValues = record.toObject();\n const result = await this.identityContext.withoutAuthorization(async () => {\n return await this.updateEntry.execute(this.model, id, {\n ...recordValues,\n values: recordValues\n });\n });\n\n if (result.isFail()) {\n return Result.fail(new UnlockEntryRequestError(result.error));\n }\n\n return Result.ok(record);\n } catch (error) {\n return Result.fail(new UnlockEntryRequestError(error as Error));\n }\n }\n}\n\nexport const UnlockEntryRequestRepository = RepositoryAbstraction.createImplementation({\n implementation: UnlockEntryRequestRepositoryImpl,\n dependencies: [UpdateEntryUseCase, IdentityContext, RecordLockingModel]\n});\n"],"names":["UnlockEntryRequestRepositoryImpl","updateEntry","identityContext","model","record","entryId","createLockRecordDatabaseId","id","createIdentifier","recordValues","result","Result","UnlockEntryRequestError","error","UnlockEntryRequestRepository","RepositoryAbstraction","UpdateEntryUseCase","IdentityContext","RecordLockingModel"],"mappings":";;;;;;;;AAWA,MAAMA;IACF,YACYC,WAAyC,EACzCC,eAA0C,EAC1CC,KAAe,CACzB;aAHUF,WAAW,GAAXA;aACAC,eAAe,GAAfA;aACAC,KAAK,GAALA;IACT;IAEH,MAAM,OAAOC,MAAmB,EAA6D;QACzF,IAAI;YACA,MAAMC,UAAUC,2BAA2BF,OAAO,EAAE;YACpD,MAAMG,KAAKC,iBAAiB;gBACxB,IAAIH;gBACJ,SAAS;YACb;YAEA,MAAMI,eAAeL,OAAO,QAAQ;YACpC,MAAMM,SAAS,MAAM,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,UACpD,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAEH,IAAI;oBAClD,GAAGE,YAAY;oBACf,QAAQA;gBACZ;YAGJ,IAAIC,OAAO,MAAM,IACb,OAAOC,OAAO,IAAI,CAAC,IAAIC,wBAAwBF,OAAO,KAAK;YAG/D,OAAOC,OAAO,EAAE,CAACP;QACrB,EAAE,OAAOS,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIC,wBAAwBC;QACnD;IACJ;AACJ;AAEO,MAAMC,4DAA+BC,6BAAAA,oBAA0C,CAAC;IACnF,gBAAgBf;IAChB,cAAc;QAACgB;QAAoBC;QAAiBC;KAAmB;AAC3E"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { UnlockEntryRequestUseCase as UseCaseAbstraction, UnlockEntryRequestRepository, UnlockEntryRequestInput } from "./abstractions.js";
|
|
3
|
+
import { GetLockRecordUseCase } from "../GetLockRecord/abstractions.js";
|
|
4
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
|
+
import type { ILockRecord } from "../../domain/LockRecord.js";
|
|
6
|
+
declare class UnlockEntryRequestUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
7
|
+
private getLockRecord;
|
|
8
|
+
private repository;
|
|
9
|
+
private identityContext;
|
|
10
|
+
constructor(getLockRecord: GetLockRecordUseCase.Interface, repository: UnlockEntryRequestRepository.Interface, identityContext: IdentityContext.Interface);
|
|
11
|
+
execute(input: UnlockEntryRequestInput): Promise<Result<ILockRecord, UseCaseAbstraction.Error>>;
|
|
12
|
+
}
|
|
13
|
+
export declare const UnlockEntryRequestUseCase: typeof UnlockEntryRequestUseCaseImpl & {
|
|
14
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IUnlockEntryRequestUseCase>;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { UnlockEntryRequestRepository, UnlockEntryRequestUseCase } from "./abstractions.js";
|
|
3
|
+
import { GetLockRecordUseCase } from "../GetLockRecord/abstractions.js";
|
|
4
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
|
+
import { EntryNotLockedError, LockRecordNotFoundError, LockRecordPersistenceError, UnlockRequestAlreadySentError } from "../../domain/errors.js";
|
|
6
|
+
import { RecordLockingLockRecordActionType } from "../../domain/types.js";
|
|
7
|
+
class UnlockEntryRequestUseCaseImpl {
|
|
8
|
+
constructor(getLockRecord, repository, identityContext){
|
|
9
|
+
this.getLockRecord = getLockRecord;
|
|
10
|
+
this.repository = repository;
|
|
11
|
+
this.identityContext = identityContext;
|
|
12
|
+
}
|
|
13
|
+
async execute(input) {
|
|
14
|
+
const recordResult = await this.getLockRecord.execute(input);
|
|
15
|
+
if (recordResult.isFail()) {
|
|
16
|
+
if (recordResult.error instanceof LockRecordNotFoundError) {
|
|
17
|
+
const error = new EntryNotLockedError({
|
|
18
|
+
id: input.id,
|
|
19
|
+
type: input.type
|
|
20
|
+
});
|
|
21
|
+
return Result.fail(error);
|
|
22
|
+
}
|
|
23
|
+
return Result.fail(new LockRecordPersistenceError(recordResult.error));
|
|
24
|
+
}
|
|
25
|
+
const record = recordResult.value;
|
|
26
|
+
if (record.isExpired()) {
|
|
27
|
+
const error = new EntryNotLockedError({
|
|
28
|
+
id: input.id,
|
|
29
|
+
type: input.type
|
|
30
|
+
});
|
|
31
|
+
return Result.fail(error);
|
|
32
|
+
}
|
|
33
|
+
const unlockRequested = record.getUnlockRequested();
|
|
34
|
+
if (unlockRequested) {
|
|
35
|
+
const currentIdentity = this.identityContext.getIdentity();
|
|
36
|
+
if (unlockRequested.createdBy.id !== currentIdentity.id) {
|
|
37
|
+
const error = new UnlockRequestAlreadySentError({
|
|
38
|
+
id: input.id,
|
|
39
|
+
type: input.type,
|
|
40
|
+
identityId: unlockRequested.createdBy.id
|
|
41
|
+
});
|
|
42
|
+
return Result.fail(error);
|
|
43
|
+
}
|
|
44
|
+
const approved = record.getUnlockApproved();
|
|
45
|
+
const denied = record.getUnlockDenied();
|
|
46
|
+
if (approved || denied) return Result.ok(record);
|
|
47
|
+
const error = new UnlockRequestAlreadySentError({
|
|
48
|
+
id: input.id,
|
|
49
|
+
type: input.type,
|
|
50
|
+
identityId: unlockRequested.createdBy.id
|
|
51
|
+
});
|
|
52
|
+
return Result.fail(error);
|
|
53
|
+
}
|
|
54
|
+
const identity = this.identityContext.getIdentity();
|
|
55
|
+
record.addAction({
|
|
56
|
+
type: RecordLockingLockRecordActionType.requested,
|
|
57
|
+
createdOn: new Date(),
|
|
58
|
+
createdBy: identity
|
|
59
|
+
});
|
|
60
|
+
const updateResult = await this.repository.update(record);
|
|
61
|
+
if (updateResult.isFail()) return Result.fail(updateResult.error);
|
|
62
|
+
return Result.ok(record);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const UnlockEntryRequestUseCase_UnlockEntryRequestUseCase = UnlockEntryRequestUseCase.createImplementation({
|
|
66
|
+
implementation: UnlockEntryRequestUseCaseImpl,
|
|
67
|
+
dependencies: [
|
|
68
|
+
GetLockRecordUseCase,
|
|
69
|
+
UnlockEntryRequestRepository,
|
|
70
|
+
IdentityContext
|
|
71
|
+
]
|
|
72
|
+
});
|
|
73
|
+
export { UnlockEntryRequestUseCase_UnlockEntryRequestUseCase as UnlockEntryRequestUseCase };
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=UnlockEntryRequestUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/UnlockEntryRequest/UnlockEntryRequestUseCase.js","sources":["../../../src/features/UnlockEntryRequest/UnlockEntryRequestUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n UnlockEntryRequestUseCase as UseCaseAbstraction,\n UnlockEntryRequestRepository,\n UnlockEntryRequestInput\n} from \"./abstractions.js\";\nimport { GetLockRecordUseCase } from \"../GetLockRecord/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type { ILockRecord } from \"~/domain/LockRecord.js\";\nimport {\n EntryNotLockedError,\n UnlockRequestAlreadySentError,\n LockRecordNotFoundError,\n LockRecordPersistenceError\n} from \"~/domain/errors.js\";\nimport { RecordLockingLockRecordActionType } from \"~/domain/types.js\";\n\nclass UnlockEntryRequestUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private getLockRecord: GetLockRecordUseCase.Interface,\n private repository: UnlockEntryRequestRepository.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async execute(\n input: UnlockEntryRequestInput\n ): Promise<Result<ILockRecord, UseCaseAbstraction.Error>> {\n // Get the lock record\n const recordResult = await this.getLockRecord.execute(input);\n\n // If not found, it means entry is not locked\n if (recordResult.isFail()) {\n if (recordResult.error instanceof LockRecordNotFoundError) {\n const error = new EntryNotLockedError({ id: input.id, type: input.type });\n return Result.fail(error);\n }\n // Other errors\n return Result.fail(new LockRecordPersistenceError(recordResult.error));\n }\n\n const record = recordResult.value;\n\n // If expired, entry is not locked\n if (record.isExpired()) {\n const error = new EntryNotLockedError({ id: input.id, type: input.type });\n return Result.fail(error);\n }\n\n // Check if unlock request already exists\n const unlockRequested = record.getUnlockRequested();\n if (unlockRequested) {\n const currentIdentity = this.identityContext.getIdentity();\n\n // If a different user already requested unlock, deny\n if (unlockRequested.createdBy.id !== currentIdentity.id) {\n const error = new UnlockRequestAlreadySentError({\n id: input.id,\n type: input.type,\n identityId: unlockRequested.createdBy.id\n });\n return Result.fail(error);\n }\n\n // If same user but already approved or denied, return the record\n const approved = record.getUnlockApproved();\n const denied = record.getUnlockDenied();\n if (approved || denied) {\n return Result.ok(record);\n }\n\n // If same user and pending, treat as duplicate\n const error = new UnlockRequestAlreadySentError({\n id: input.id,\n type: input.type,\n identityId: unlockRequested.createdBy.id\n });\n return Result.fail(error);\n }\n\n // Add unlock request action\n const identity = this.identityContext.getIdentity();\n record.addAction({\n type: RecordLockingLockRecordActionType.requested,\n createdOn: new Date(),\n createdBy: identity\n });\n\n // Update the record\n const updateResult = await this.repository.update(record);\n\n if (updateResult.isFail()) {\n return Result.fail(updateResult.error);\n }\n\n return Result.ok(record);\n }\n}\n\nexport const UnlockEntryRequestUseCase = UseCaseAbstraction.createImplementation({\n implementation: UnlockEntryRequestUseCaseImpl,\n dependencies: [GetLockRecordUseCase, UnlockEntryRequestRepository, IdentityContext]\n});\n"],"names":["UnlockEntryRequestUseCaseImpl","getLockRecord","repository","identityContext","input","recordResult","LockRecordNotFoundError","error","EntryNotLockedError","Result","LockRecordPersistenceError","record","unlockRequested","currentIdentity","UnlockRequestAlreadySentError","approved","denied","identity","RecordLockingLockRecordActionType","Date","updateResult","UnlockEntryRequestUseCase","UseCaseAbstraction","GetLockRecordUseCase","UnlockEntryRequestRepository","IdentityContext"],"mappings":";;;;;;AAiBA,MAAMA;IACF,YACYC,aAA6C,EAC7CC,UAAkD,EAClDC,eAA0C,CACpD;aAHUF,aAAa,GAAbA;aACAC,UAAU,GAAVA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,KAA8B,EACwB;QAEtD,MAAMC,eAAe,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAACD;QAGtD,IAAIC,aAAa,MAAM,IAAI;YACvB,IAAIA,aAAa,KAAK,YAAYC,yBAAyB;gBACvD,MAAMC,QAAQ,IAAIC,oBAAoB;oBAAE,IAAIJ,MAAM,EAAE;oBAAE,MAAMA,MAAM,IAAI;gBAAC;gBACvE,OAAOK,OAAO,IAAI,CAACF;YACvB;YAEA,OAAOE,OAAO,IAAI,CAAC,IAAIC,2BAA2BL,aAAa,KAAK;QACxE;QAEA,MAAMM,SAASN,aAAa,KAAK;QAGjC,IAAIM,OAAO,SAAS,IAAI;YACpB,MAAMJ,QAAQ,IAAIC,oBAAoB;gBAAE,IAAIJ,MAAM,EAAE;gBAAE,MAAMA,MAAM,IAAI;YAAC;YACvE,OAAOK,OAAO,IAAI,CAACF;QACvB;QAGA,MAAMK,kBAAkBD,OAAO,kBAAkB;QACjD,IAAIC,iBAAiB;YACjB,MAAMC,kBAAkB,IAAI,CAAC,eAAe,CAAC,WAAW;YAGxD,IAAID,gBAAgB,SAAS,CAAC,EAAE,KAAKC,gBAAgB,EAAE,EAAE;gBACrD,MAAMN,QAAQ,IAAIO,8BAA8B;oBAC5C,IAAIV,MAAM,EAAE;oBACZ,MAAMA,MAAM,IAAI;oBAChB,YAAYQ,gBAAgB,SAAS,CAAC,EAAE;gBAC5C;gBACA,OAAOH,OAAO,IAAI,CAACF;YACvB;YAGA,MAAMQ,WAAWJ,OAAO,iBAAiB;YACzC,MAAMK,SAASL,OAAO,eAAe;YACrC,IAAII,YAAYC,QACZ,OAAOP,OAAO,EAAE,CAACE;YAIrB,MAAMJ,QAAQ,IAAIO,8BAA8B;gBAC5C,IAAIV,MAAM,EAAE;gBACZ,MAAMA,MAAM,IAAI;gBAChB,YAAYQ,gBAAgB,SAAS,CAAC,EAAE;YAC5C;YACA,OAAOH,OAAO,IAAI,CAACF;QACvB;QAGA,MAAMU,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QACjDN,OAAO,SAAS,CAAC;YACb,MAAMO,kCAAkC,SAAS;YACjD,WAAW,IAAIC;YACf,WAAWF;QACf;QAGA,MAAMG,eAAe,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACT;QAElD,IAAIS,aAAa,MAAM,IACnB,OAAOX,OAAO,IAAI,CAACW,aAAa,KAAK;QAGzC,OAAOX,OAAO,EAAE,CAACE;IACrB;AACJ;AAEO,MAAMU,sDAA4BC,0BAAAA,oBAAuC,CAAC;IAC7E,gBAAgBtB;IAChB,cAAc;QAACuB;QAAsBC;QAA8BC;KAAgB;AACvF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { ILockRecord } from "../../domain/LockRecord.js";
|
|
3
|
+
import type { LockRecordEntryType } from "../../domain/types.js";
|
|
4
|
+
import type { EntryNotLockedError, UnlockRequestAlreadySentError, UnlockEntryRequestError, LockRecordPersistenceError } from "../../domain/errors.js";
|
|
5
|
+
export interface UnlockEntryRequestInput {
|
|
6
|
+
id: string;
|
|
7
|
+
type: LockRecordEntryType;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* UnlockEntryRequest Use Case - Adds unlock request to lock record
|
|
11
|
+
*/
|
|
12
|
+
export interface IUnlockEntryRequestUseCase {
|
|
13
|
+
execute(input: UnlockEntryRequestInput): Promise<Result<ILockRecord, UseCaseError>>;
|
|
14
|
+
}
|
|
15
|
+
export interface IUnlockEntryRequestUseCaseErrors {
|
|
16
|
+
notLocked: EntryNotLockedError;
|
|
17
|
+
alreadySent: UnlockRequestAlreadySentError;
|
|
18
|
+
persistence: LockRecordPersistenceError;
|
|
19
|
+
requestError: UnlockEntryRequestError;
|
|
20
|
+
}
|
|
21
|
+
type UseCaseError = IUnlockEntryRequestUseCaseErrors[keyof IUnlockEntryRequestUseCaseErrors];
|
|
22
|
+
export declare const UnlockEntryRequestUseCase: import("@webiny/di").Abstraction<IUnlockEntryRequestUseCase>;
|
|
23
|
+
export declare namespace UnlockEntryRequestUseCase {
|
|
24
|
+
type Interface = IUnlockEntryRequestUseCase;
|
|
25
|
+
type Error = UseCaseError;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* UnlockEntryRequestRepository - Updates lock record with unlock request
|
|
29
|
+
*/
|
|
30
|
+
export interface IUnlockEntryRequestRepository {
|
|
31
|
+
update(record: ILockRecord): Promise<Result<ILockRecord, RepositoryError>>;
|
|
32
|
+
}
|
|
33
|
+
export interface IUnlockEntryRequestRepositoryErrors {
|
|
34
|
+
persistence: UnlockEntryRequestError;
|
|
35
|
+
}
|
|
36
|
+
type RepositoryError = IUnlockEntryRequestRepositoryErrors[keyof IUnlockEntryRequestRepositoryErrors];
|
|
37
|
+
export declare const UnlockEntryRequestRepository: import("@webiny/di").Abstraction<IUnlockEntryRequestRepository>;
|
|
38
|
+
export declare namespace UnlockEntryRequestRepository {
|
|
39
|
+
type Interface = IUnlockEntryRequestRepository;
|
|
40
|
+
type Error = RepositoryError;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
const UnlockEntryRequestUseCase = createAbstraction("UnlockEntryRequestUseCase");
|
|
3
|
+
const UnlockEntryRequestRepository = createAbstraction("UnlockEntryRequestRepository");
|
|
4
|
+
export { UnlockEntryRequestRepository, UnlockEntryRequestUseCase };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/UnlockEntryRequest/abstractions.js","sources":["../../../src/features/UnlockEntryRequest/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { ILockRecord } from \"~/domain/LockRecord.js\";\nimport type { LockRecordEntryType } from \"~/domain/types.js\";\nimport type {\n EntryNotLockedError,\n UnlockRequestAlreadySentError,\n UnlockEntryRequestError,\n LockRecordPersistenceError\n} from \"~/domain/errors.js\";\n\n// Input type\nexport interface UnlockEntryRequestInput {\n id: string;\n type: LockRecordEntryType;\n}\n\n/**\n * UnlockEntryRequest Use Case - Adds unlock request to lock record\n */\nexport interface IUnlockEntryRequestUseCase {\n execute(input: UnlockEntryRequestInput): Promise<Result<ILockRecord, UseCaseError>>;\n}\n\nexport interface IUnlockEntryRequestUseCaseErrors {\n notLocked: EntryNotLockedError;\n alreadySent: UnlockRequestAlreadySentError;\n persistence: LockRecordPersistenceError;\n requestError: UnlockEntryRequestError;\n}\n\ntype UseCaseError = IUnlockEntryRequestUseCaseErrors[keyof IUnlockEntryRequestUseCaseErrors];\n\nexport const UnlockEntryRequestUseCase = createAbstraction<IUnlockEntryRequestUseCase>(\n \"UnlockEntryRequestUseCase\"\n);\n\nexport namespace UnlockEntryRequestUseCase {\n export type Interface = IUnlockEntryRequestUseCase;\n export type Error = UseCaseError;\n}\n\n/**\n * UnlockEntryRequestRepository - Updates lock record with unlock request\n */\nexport interface IUnlockEntryRequestRepository {\n update(record: ILockRecord): Promise<Result<ILockRecord, RepositoryError>>;\n}\n\nexport interface IUnlockEntryRequestRepositoryErrors {\n persistence: UnlockEntryRequestError;\n}\n\ntype RepositoryError =\n IUnlockEntryRequestRepositoryErrors[keyof IUnlockEntryRequestRepositoryErrors];\n\nexport const UnlockEntryRequestRepository = createAbstraction<IUnlockEntryRequestRepository>(\n \"UnlockEntryRequestRepository\"\n);\n\nexport namespace UnlockEntryRequestRepository {\n export type Interface = IUnlockEntryRequestRepository;\n export type Error = RepositoryError;\n}\n"],"names":["UnlockEntryRequestUseCase","createAbstraction","UnlockEntryRequestRepository"],"mappings":";AAiCO,MAAMA,4BAA4BC,kBACrC;AAsBG,MAAMC,+BAA+BD,kBACxC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
|
+
import type { IEventHandler } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
|
+
import type { ILockRecord } from "../../domain/LockRecord.js";
|
|
4
|
+
import type { LockRecordEntryType } from "../../domain/types.js";
|
|
5
|
+
export interface EntryBeforeUnlockRequestPayload {
|
|
6
|
+
id: string;
|
|
7
|
+
type: LockRecordEntryType;
|
|
8
|
+
}
|
|
9
|
+
export declare class EntryBeforeUnlockRequestEvent extends DomainEvent<EntryBeforeUnlockRequestPayload> {
|
|
10
|
+
eventType: "RecordLocking/Entry/BeforeUnlockRequest";
|
|
11
|
+
getHandlerAbstraction(): import("@webiny/di").Abstraction<IEventHandler<EntryBeforeUnlockRequestEvent>>;
|
|
12
|
+
}
|
|
13
|
+
export declare const EntryBeforeUnlockRequestEventHandler: import("@webiny/di").Abstraction<IEventHandler<EntryBeforeUnlockRequestEvent>>;
|
|
14
|
+
export declare namespace EntryBeforeUnlockRequestEventHandler {
|
|
15
|
+
type Interface = IEventHandler<EntryBeforeUnlockRequestEvent>;
|
|
16
|
+
type Event = EntryBeforeUnlockRequestEvent;
|
|
17
|
+
}
|
|
18
|
+
export interface EntryAfterUnlockRequestPayload {
|
|
19
|
+
id: string;
|
|
20
|
+
type: LockRecordEntryType;
|
|
21
|
+
record: ILockRecord;
|
|
22
|
+
}
|
|
23
|
+
export declare class EntryAfterUnlockRequestEvent extends DomainEvent<EntryAfterUnlockRequestPayload> {
|
|
24
|
+
eventType: "RecordLocking/Entry/AfterUnlockRequest";
|
|
25
|
+
getHandlerAbstraction(): import("@webiny/di").Abstraction<IEventHandler<EntryAfterUnlockRequestEvent>>;
|
|
26
|
+
}
|
|
27
|
+
export declare const EntryAfterUnlockRequestEventHandler: import("@webiny/di").Abstraction<IEventHandler<EntryAfterUnlockRequestEvent>>;
|
|
28
|
+
export declare namespace EntryAfterUnlockRequestEventHandler {
|
|
29
|
+
type Interface = IEventHandler<EntryAfterUnlockRequestEvent>;
|
|
30
|
+
type Event = EntryAfterUnlockRequestEvent;
|
|
31
|
+
}
|
|
32
|
+
export interface EntryUnlockRequestErrorPayload {
|
|
33
|
+
id: string;
|
|
34
|
+
type: LockRecordEntryType;
|
|
35
|
+
error: Error;
|
|
36
|
+
}
|
|
37
|
+
export declare class EntryUnlockRequestErrorEvent extends DomainEvent<EntryUnlockRequestErrorPayload> {
|
|
38
|
+
eventType: "RecordLocking/Entry/UnlockRequestError";
|
|
39
|
+
getHandlerAbstraction(): import("@webiny/di").Abstraction<IEventHandler<EntryUnlockRequestErrorEvent>>;
|
|
40
|
+
}
|
|
41
|
+
export declare const EntryUnlockRequestErrorEventHandler: import("@webiny/di").Abstraction<IEventHandler<EntryUnlockRequestErrorEvent>>;
|
|
42
|
+
export declare namespace EntryUnlockRequestErrorEventHandler {
|
|
43
|
+
type Interface = IEventHandler<EntryUnlockRequestErrorEvent>;
|
|
44
|
+
type Event = EntryUnlockRequestErrorEvent;
|
|
45
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
|
+
class EntryBeforeUnlockRequestEvent extends DomainEvent {
|
|
4
|
+
getHandlerAbstraction() {
|
|
5
|
+
return EntryBeforeUnlockRequestEventHandler;
|
|
6
|
+
}
|
|
7
|
+
constructor(...args){
|
|
8
|
+
super(...args), this.eventType = "RecordLocking/Entry/BeforeUnlockRequest";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const EntryBeforeUnlockRequestEventHandler = createAbstraction("EntryBeforeUnlockRequestEventHandler");
|
|
12
|
+
class EntryAfterUnlockRequestEvent extends DomainEvent {
|
|
13
|
+
getHandlerAbstraction() {
|
|
14
|
+
return EntryAfterUnlockRequestEventHandler;
|
|
15
|
+
}
|
|
16
|
+
constructor(...args){
|
|
17
|
+
super(...args), this.eventType = "RecordLocking/Entry/AfterUnlockRequest";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const EntryAfterUnlockRequestEventHandler = createAbstraction("EntryAfterUnlockRequestEventHandler");
|
|
21
|
+
class EntryUnlockRequestErrorEvent extends DomainEvent {
|
|
22
|
+
getHandlerAbstraction() {
|
|
23
|
+
return EntryUnlockRequestErrorEventHandler;
|
|
24
|
+
}
|
|
25
|
+
constructor(...args){
|
|
26
|
+
super(...args), this.eventType = "RecordLocking/Entry/UnlockRequestError";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const EntryUnlockRequestErrorEventHandler = createAbstraction("EntryUnlockRequestErrorEventHandler");
|
|
30
|
+
export { EntryAfterUnlockRequestEvent, EntryAfterUnlockRequestEventHandler, EntryBeforeUnlockRequestEvent, EntryBeforeUnlockRequestEventHandler, EntryUnlockRequestErrorEvent, EntryUnlockRequestErrorEventHandler };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/UnlockEntryRequest/events.js","sources":["../../../src/features/UnlockEntryRequest/events.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { DomainEvent } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { IEventHandler } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { ILockRecord } from \"~/domain/LockRecord.js\";\nimport type { LockRecordEntryType } from \"~/domain/types.js\";\n\n// ============================================================================\n// EntryBeforeUnlockRequest Event\n// ============================================================================\n\nexport interface EntryBeforeUnlockRequestPayload {\n id: string;\n type: LockRecordEntryType;\n}\n\nexport class EntryBeforeUnlockRequestEvent extends DomainEvent<EntryBeforeUnlockRequestPayload> {\n eventType = \"RecordLocking/Entry/BeforeUnlockRequest\" as const;\n\n getHandlerAbstraction() {\n return EntryBeforeUnlockRequestEventHandler;\n }\n}\n\nexport const EntryBeforeUnlockRequestEventHandler = createAbstraction<\n IEventHandler<EntryBeforeUnlockRequestEvent>\n>(\"EntryBeforeUnlockRequestEventHandler\");\n\nexport namespace EntryBeforeUnlockRequestEventHandler {\n export type Interface = IEventHandler<EntryBeforeUnlockRequestEvent>;\n export type Event = EntryBeforeUnlockRequestEvent;\n}\n\n// ============================================================================\n// EntryAfterUnlockRequest Event\n// ============================================================================\n\nexport interface EntryAfterUnlockRequestPayload {\n id: string;\n type: LockRecordEntryType;\n record: ILockRecord;\n}\n\nexport class EntryAfterUnlockRequestEvent extends DomainEvent<EntryAfterUnlockRequestPayload> {\n eventType = \"RecordLocking/Entry/AfterUnlockRequest\" as const;\n\n getHandlerAbstraction() {\n return EntryAfterUnlockRequestEventHandler;\n }\n}\n\nexport const EntryAfterUnlockRequestEventHandler = createAbstraction<\n IEventHandler<EntryAfterUnlockRequestEvent>\n>(\"EntryAfterUnlockRequestEventHandler\");\n\nexport namespace EntryAfterUnlockRequestEventHandler {\n export type Interface = IEventHandler<EntryAfterUnlockRequestEvent>;\n export type Event = EntryAfterUnlockRequestEvent;\n}\n\n// ============================================================================\n// EntryUnlockRequestError Event\n// ============================================================================\n\nexport interface EntryUnlockRequestErrorPayload {\n id: string;\n type: LockRecordEntryType;\n error: Error;\n}\n\nexport class EntryUnlockRequestErrorEvent extends DomainEvent<EntryUnlockRequestErrorPayload> {\n eventType = \"RecordLocking/Entry/UnlockRequestError\" as const;\n\n getHandlerAbstraction() {\n return EntryUnlockRequestErrorEventHandler;\n }\n}\n\nexport const EntryUnlockRequestErrorEventHandler = createAbstraction<\n IEventHandler<EntryUnlockRequestErrorEvent>\n>(\"EntryUnlockRequestErrorEventHandler\");\n\nexport namespace EntryUnlockRequestErrorEventHandler {\n export type Interface = IEventHandler<EntryUnlockRequestErrorEvent>;\n export type Event = EntryUnlockRequestErrorEvent;\n}\n"],"names":["EntryBeforeUnlockRequestEvent","DomainEvent","EntryBeforeUnlockRequestEventHandler","createAbstraction","EntryAfterUnlockRequestEvent","EntryAfterUnlockRequestEventHandler","EntryUnlockRequestErrorEvent","EntryUnlockRequestErrorEventHandler"],"mappings":";;AAeO,MAAMA,sCAAsCC;IAG/C,wBAAwB;QACpB,OAAOC;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMA,uCAAuCC,kBAElD;AAiBK,MAAMC,qCAAqCH;IAG9C,wBAAwB;QACpB,OAAOI;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMA,sCAAsCF,kBAEjD;AAiBK,MAAMG,qCAAqCL;IAG9C,wBAAwB;QACpB,OAAOM;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMA,sCAAsCJ,kBAEjD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { UnlockEntryRequestUseCase } from "./UnlockEntryRequestUseCase.js";
|
|
3
|
+
import { UnlockEntryRequestRepository } from "./UnlockEntryRequestRepository.js";
|
|
4
|
+
import { UnlockEntryRequestEventsDecorator } from "./UnlockEntryRequestEventsDecorator.js";
|
|
5
|
+
const UnlockEntryRequestFeature = createFeature({
|
|
6
|
+
name: "UnlockEntryRequest",
|
|
7
|
+
register (container) {
|
|
8
|
+
container.register(UnlockEntryRequestUseCase);
|
|
9
|
+
container.register(UnlockEntryRequestRepository).inSingletonScope();
|
|
10
|
+
container.registerDecorator(UnlockEntryRequestEventsDecorator);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
export { UnlockEntryRequestFeature };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/UnlockEntryRequest/feature.js","sources":["../../../src/features/UnlockEntryRequest/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { UnlockEntryRequestUseCase } from \"./UnlockEntryRequestUseCase.js\";\nimport { UnlockEntryRequestRepository } from \"./UnlockEntryRequestRepository.js\";\nimport { UnlockEntryRequestEventsDecorator } from \"./UnlockEntryRequestEventsDecorator.js\";\n\nexport const UnlockEntryRequestFeature = createFeature({\n name: \"UnlockEntryRequest\",\n register(container) {\n container.register(UnlockEntryRequestUseCase);\n container.register(UnlockEntryRequestRepository).inSingletonScope();\n container.registerDecorator(UnlockEntryRequestEventsDecorator);\n }\n});\n"],"names":["UnlockEntryRequestFeature","createFeature","container","UnlockEntryRequestUseCase","UnlockEntryRequestRepository","UnlockEntryRequestEventsDecorator"],"mappings":";;;;AAKO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE,8BAA8B,gBAAgB;QACjEF,UAAU,iBAAiB,CAACG;IAChC;AACJ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
2
|
+
import { UpdateEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UpdateEntry";
|
|
3
|
+
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById";
|
|
4
|
+
import { Result } from "@webiny/feature/api";
|
|
5
|
+
import { UpdateEntryLockRepository as RepositoryAbstraction } from "./abstractions.js";
|
|
6
|
+
import { RecordLockingConfig, RecordLockingModel } from "../../domain/abstractions.js";
|
|
7
|
+
import type { ILockRecord } from "../../domain/LockRecord.js";
|
|
8
|
+
declare class UpdateEntryLockRepositoryImpl implements RepositoryAbstraction.Interface {
|
|
9
|
+
private model;
|
|
10
|
+
private config;
|
|
11
|
+
private identityContext;
|
|
12
|
+
private updateEntry;
|
|
13
|
+
private getEntryById;
|
|
14
|
+
constructor(model: RecordLockingModel.Interface, config: RecordLockingConfig.Interface, identityContext: IdentityContext.Interface, updateEntry: UpdateEntryUseCase.Interface, getEntryById: GetEntryByIdUseCase.Interface);
|
|
15
|
+
update(lockRecordId: string, updateOwner: boolean): Promise<Result<ILockRecord, RepositoryAbstraction.Error>>;
|
|
16
|
+
}
|
|
17
|
+
export declare const UpdateEntryLockRepository: typeof UpdateEntryLockRepositoryImpl & {
|
|
18
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IUpdateEntryLockRepository>;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
2
|
+
import { UpdateEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UpdateEntry";
|
|
3
|
+
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById";
|
|
4
|
+
import { Result } from "@webiny/feature/api";
|
|
5
|
+
import { createIdentifier } from "@webiny/utils";
|
|
6
|
+
import { UpdateEntryLockRepository } from "./abstractions.js";
|
|
7
|
+
import { RecordLockingConfig, RecordLockingModel } from "../../domain/abstractions.js";
|
|
8
|
+
import { LockRecord } from "../../domain/LockRecord.js";
|
|
9
|
+
import { LockRecordPersistenceError } from "../../domain/errors.js";
|
|
10
|
+
import { createLockRecordDatabaseId } from "../../utils/lockRecordDatabaseId.js";
|
|
11
|
+
class UpdateEntryLockRepositoryImpl {
|
|
12
|
+
constructor(model, config, identityContext, updateEntry, getEntryById){
|
|
13
|
+
this.model = model;
|
|
14
|
+
this.config = config;
|
|
15
|
+
this.identityContext = identityContext;
|
|
16
|
+
this.updateEntry = updateEntry;
|
|
17
|
+
this.getEntryById = getEntryById;
|
|
18
|
+
}
|
|
19
|
+
async update(lockRecordId, updateOwner) {
|
|
20
|
+
try {
|
|
21
|
+
const entryId = createLockRecordDatabaseId(lockRecordId);
|
|
22
|
+
const id = createIdentifier({
|
|
23
|
+
id: entryId,
|
|
24
|
+
version: 1
|
|
25
|
+
});
|
|
26
|
+
const identity = this.identityContext.getIdentity();
|
|
27
|
+
const now = new Date().toISOString();
|
|
28
|
+
const updateData = {
|
|
29
|
+
savedOn: now
|
|
30
|
+
};
|
|
31
|
+
if (updateOwner) {
|
|
32
|
+
updateData.createdOn = now;
|
|
33
|
+
updateData.createdBy = identity;
|
|
34
|
+
updateData.savedBy = identity;
|
|
35
|
+
}
|
|
36
|
+
const result = await this.updateEntry.execute(this.model, id, updateData);
|
|
37
|
+
if (result.isFail()) return Result.fail(new LockRecordPersistenceError(result.error));
|
|
38
|
+
const getResult = await this.getEntryById.execute(this.model, id);
|
|
39
|
+
if (getResult.isFail()) return Result.fail(new LockRecordPersistenceError(getResult.error));
|
|
40
|
+
const entry = getResult.value;
|
|
41
|
+
const lockRecord = new LockRecord(entry, this.config.timeout);
|
|
42
|
+
return Result.ok(lockRecord);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
return Result.fail(new LockRecordPersistenceError(error));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const UpdateEntryLockRepository_UpdateEntryLockRepository = UpdateEntryLockRepository.createImplementation({
|
|
49
|
+
implementation: UpdateEntryLockRepositoryImpl,
|
|
50
|
+
dependencies: [
|
|
51
|
+
RecordLockingModel,
|
|
52
|
+
RecordLockingConfig,
|
|
53
|
+
IdentityContext,
|
|
54
|
+
UpdateEntryUseCase,
|
|
55
|
+
GetEntryByIdUseCase
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
export { UpdateEntryLockRepository_UpdateEntryLockRepository as UpdateEntryLockRepository };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=UpdateEntryLockRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/UpdateEntryLock/UpdateEntryLockRepository.js","sources":["../../../src/features/UpdateEntryLock/UpdateEntryLockRepository.ts"],"sourcesContent":["import { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { UpdateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById\";\nimport { Result } from \"@webiny/feature/api\";\nimport { createIdentifier } from \"@webiny/utils\";\nimport { UpdateEntryLockRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { RecordLockingConfig, RecordLockingModel } from \"~/domain/abstractions.js\";\nimport type { ILockRecord } from \"~/domain/LockRecord.js\";\nimport { LockRecord } from \"~/domain/LockRecord.js\";\nimport type { LockRecordValues } from \"~/domain/types.js\";\nimport { LockRecordPersistenceError } from \"~/domain/errors.js\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId.js\";\n\nclass UpdateEntryLockRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private model: RecordLockingModel.Interface,\n private config: RecordLockingConfig.Interface,\n private identityContext: IdentityContext.Interface,\n private updateEntry: UpdateEntryUseCase.Interface,\n private getEntryById: GetEntryByIdUseCase.Interface\n ) {}\n\n async update(\n lockRecordId: string,\n updateOwner: boolean\n ): Promise<Result<ILockRecord, RepositoryAbstraction.Error>> {\n try {\n const entryId = createLockRecordDatabaseId(lockRecordId);\n const id = createIdentifier({\n id: entryId,\n version: 1\n });\n\n const identity = this.identityContext.getIdentity();\n const now = new Date().toISOString();\n\n // Build update data\n const updateData: any = {\n savedOn: now\n };\n\n // If updating owner (expired lock), also update created fields\n if (updateOwner) {\n updateData.createdOn = now;\n updateData.createdBy = identity;\n updateData.savedBy = identity;\n }\n\n const result = await this.updateEntry.execute(this.model, id, updateData);\n\n if (result.isFail()) {\n return Result.fail(new LockRecordPersistenceError(result.error));\n }\n\n // Fetch the updated entry to return full lock record\n const getResult = await this.getEntryById.execute<LockRecordValues>(this.model, id);\n\n if (getResult.isFail()) {\n return Result.fail(new LockRecordPersistenceError(getResult.error));\n }\n\n const entry = getResult.value;\n const lockRecord = new LockRecord(entry, this.config.timeout);\n\n return Result.ok(lockRecord);\n } catch (error) {\n return Result.fail(new LockRecordPersistenceError(error as Error));\n }\n }\n}\n\nexport const UpdateEntryLockRepository = RepositoryAbstraction.createImplementation({\n implementation: UpdateEntryLockRepositoryImpl,\n dependencies: [\n RecordLockingModel,\n RecordLockingConfig,\n IdentityContext,\n UpdateEntryUseCase,\n GetEntryByIdUseCase\n ]\n});\n"],"names":["UpdateEntryLockRepositoryImpl","model","config","identityContext","updateEntry","getEntryById","lockRecordId","updateOwner","entryId","createLockRecordDatabaseId","id","createIdentifier","identity","now","Date","updateData","result","Result","LockRecordPersistenceError","getResult","entry","lockRecord","LockRecord","error","UpdateEntryLockRepository","RepositoryAbstraction","RecordLockingModel","RecordLockingConfig","IdentityContext","UpdateEntryUseCase","GetEntryByIdUseCase"],"mappings":";;;;;;;;;;AAaA,MAAMA;IACF,YACYC,KAAmC,EACnCC,MAAqC,EACrCC,eAA0C,EAC1CC,WAAyC,EACzCC,YAA2C,CACrD;aALUJ,KAAK,GAALA;aACAC,MAAM,GAANA;aACAC,eAAe,GAAfA;aACAC,WAAW,GAAXA;aACAC,YAAY,GAAZA;IACT;IAEH,MAAM,OACFC,YAAoB,EACpBC,WAAoB,EACqC;QACzD,IAAI;YACA,MAAMC,UAAUC,2BAA2BH;YAC3C,MAAMI,KAAKC,iBAAiB;gBACxB,IAAIH;gBACJ,SAAS;YACb;YAEA,MAAMI,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;YACjD,MAAMC,MAAM,IAAIC,OAAO,WAAW;YAGlC,MAAMC,aAAkB;gBACpB,SAASF;YACb;YAGA,IAAIN,aAAa;gBACbQ,WAAW,SAAS,GAAGF;gBACvBE,WAAW,SAAS,GAAGH;gBACvBG,WAAW,OAAO,GAAGH;YACzB;YAEA,MAAMI,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAEN,IAAIK;YAE9D,IAAIC,OAAO,MAAM,IACb,OAAOC,OAAO,IAAI,CAAC,IAAIC,2BAA2BF,OAAO,KAAK;YAIlE,MAAMG,YAAY,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAmB,IAAI,CAAC,KAAK,EAAET;YAEhF,IAAIS,UAAU,MAAM,IAChB,OAAOF,OAAO,IAAI,CAAC,IAAIC,2BAA2BC,UAAU,KAAK;YAGrE,MAAMC,QAAQD,UAAU,KAAK;YAC7B,MAAME,aAAa,IAAIC,WAAWF,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO;YAE5D,OAAOH,OAAO,EAAE,CAACI;QACrB,EAAE,OAAOE,OAAO;YACZ,OAAON,OAAO,IAAI,CAAC,IAAIC,2BAA2BK;QACtD;IACJ;AACJ;AAEO,MAAMC,sDAA4BC,0BAAAA,oBAA0C,CAAC;IAChF,gBAAgBzB;IAChB,cAAc;QACV0B;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { UpdateEntryLockUseCase as UseCaseAbstraction, UpdateEntryLockRepository, UpdateEntryLockInput } from "./abstractions.js";
|
|
3
|
+
import { GetLockRecordUseCase } from "../GetLockRecord/abstractions.js";
|
|
4
|
+
import { LockEntryUseCase } from "../LockEntry/abstractions.js";
|
|
5
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
6
|
+
import type { ILockRecord } from "../../domain/LockRecord.js";
|
|
7
|
+
declare class UpdateEntryLockUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
8
|
+
private getLockRecord;
|
|
9
|
+
private lockEntry;
|
|
10
|
+
private repository;
|
|
11
|
+
private identityContext;
|
|
12
|
+
constructor(getLockRecord: GetLockRecordUseCase.Interface, lockEntry: LockEntryUseCase.Interface, repository: UpdateEntryLockRepository.Interface, identityContext: IdentityContext.Interface);
|
|
13
|
+
execute(input: UpdateEntryLockInput): Promise<Result<ILockRecord, UseCaseAbstraction.Error>>;
|
|
14
|
+
}
|
|
15
|
+
export declare const UpdateEntryLockUseCase: typeof UpdateEntryLockUseCaseImpl & {
|
|
16
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IUpdateEntryLockUseCase>;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { UpdateEntryLockRepository, UpdateEntryLockUseCase } from "./abstractions.js";
|
|
3
|
+
import { GetLockRecordUseCase } from "../GetLockRecord/abstractions.js";
|
|
4
|
+
import { LockEntryUseCase } from "../LockEntry/abstractions.js";
|
|
5
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
6
|
+
import { IdentityMismatchError, LockRecordNotFoundError, UpdateEntryLockError } from "../../domain/errors.js";
|
|
7
|
+
class UpdateEntryLockUseCaseImpl {
|
|
8
|
+
constructor(getLockRecord, lockEntry, repository, identityContext){
|
|
9
|
+
this.getLockRecord = getLockRecord;
|
|
10
|
+
this.lockEntry = lockEntry;
|
|
11
|
+
this.repository = repository;
|
|
12
|
+
this.identityContext = identityContext;
|
|
13
|
+
}
|
|
14
|
+
async execute(input) {
|
|
15
|
+
const recordResult = await this.getLockRecord.execute(input);
|
|
16
|
+
if (recordResult.isFail()) {
|
|
17
|
+
if (recordResult.error instanceof LockRecordNotFoundError) {
|
|
18
|
+
const lockResult = await this.lockEntry.execute(input);
|
|
19
|
+
if (lockResult.isFail()) return Result.fail(new UpdateEntryLockError(lockResult.error));
|
|
20
|
+
return Result.ok(lockResult.value);
|
|
21
|
+
}
|
|
22
|
+
return Result.fail(recordResult.error);
|
|
23
|
+
}
|
|
24
|
+
const record = recordResult.value;
|
|
25
|
+
if (record.isExpired()) {
|
|
26
|
+
const updateResult = await this.repository.update(record.id, true);
|
|
27
|
+
if (updateResult.isFail()) return Result.fail(new UpdateEntryLockError(updateResult.error));
|
|
28
|
+
return Result.ok(updateResult.value);
|
|
29
|
+
}
|
|
30
|
+
const identity = this.identityContext.getIdentity();
|
|
31
|
+
if (record.lockedBy.id !== identity.id) return Result.fail(new IdentityMismatchError({
|
|
32
|
+
currentId: identity.id,
|
|
33
|
+
targetId: record.lockedBy.id
|
|
34
|
+
}));
|
|
35
|
+
const updateResult = await this.repository.update(record.id, false);
|
|
36
|
+
if (updateResult.isFail()) return Result.fail(new UpdateEntryLockError(updateResult.error));
|
|
37
|
+
return Result.ok(updateResult.value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const UpdateEntryLockUseCase_UpdateEntryLockUseCase = UpdateEntryLockUseCase.createImplementation({
|
|
41
|
+
implementation: UpdateEntryLockUseCaseImpl,
|
|
42
|
+
dependencies: [
|
|
43
|
+
GetLockRecordUseCase,
|
|
44
|
+
LockEntryUseCase,
|
|
45
|
+
UpdateEntryLockRepository,
|
|
46
|
+
IdentityContext
|
|
47
|
+
]
|
|
48
|
+
});
|
|
49
|
+
export { UpdateEntryLockUseCase_UpdateEntryLockUseCase as UpdateEntryLockUseCase };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=UpdateEntryLockUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/UpdateEntryLock/UpdateEntryLockUseCase.js","sources":["../../../src/features/UpdateEntryLock/UpdateEntryLockUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n UpdateEntryLockUseCase as UseCaseAbstraction,\n UpdateEntryLockRepository,\n UpdateEntryLockInput\n} from \"./abstractions.js\";\nimport { GetLockRecordUseCase } from \"../GetLockRecord/abstractions.js\";\nimport { LockEntryUseCase } from \"../LockEntry/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type { ILockRecord } from \"~/domain/LockRecord.js\";\nimport {\n LockRecordNotFoundError,\n IdentityMismatchError,\n UpdateEntryLockError\n} from \"~/domain/errors.js\";\n\nclass UpdateEntryLockUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private getLockRecord: GetLockRecordUseCase.Interface,\n private lockEntry: LockEntryUseCase.Interface,\n private repository: UpdateEntryLockRepository.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async execute(\n input: UpdateEntryLockInput\n ): Promise<Result<ILockRecord, UseCaseAbstraction.Error>> {\n // Try to get existing lock record\n const recordResult = await this.getLockRecord.execute(input);\n\n // If doesn't exist, create a new lock\n if (recordResult.isFail()) {\n if (recordResult.error instanceof LockRecordNotFoundError) {\n const lockResult = await this.lockEntry.execute(input);\n if (lockResult.isFail()) {\n return Result.fail(new UpdateEntryLockError(lockResult.error));\n }\n return Result.ok(lockResult.value);\n }\n return Result.fail(recordResult.error);\n }\n\n const record = recordResult.value;\n\n // If expired, update with current user as new owner\n if (record.isExpired()) {\n const updateResult = await this.repository.update(record.id, true);\n if (updateResult.isFail()) {\n return Result.fail(new UpdateEntryLockError(updateResult.error));\n }\n return Result.ok(updateResult.value);\n }\n\n // If not expired, validate same owner\n const identity = this.identityContext.getIdentity();\n if (record.lockedBy.id !== identity.id) {\n return Result.fail(\n new IdentityMismatchError({\n currentId: identity.id,\n targetId: record.lockedBy.id\n })\n );\n }\n\n // Update timestamp only\n const updateResult = await this.repository.update(record.id, false);\n if (updateResult.isFail()) {\n return Result.fail(new UpdateEntryLockError(updateResult.error));\n }\n\n return Result.ok(updateResult.value);\n }\n}\n\nexport const UpdateEntryLockUseCase = UseCaseAbstraction.createImplementation({\n implementation: UpdateEntryLockUseCaseImpl,\n dependencies: [\n GetLockRecordUseCase,\n LockEntryUseCase,\n UpdateEntryLockRepository,\n IdentityContext\n ]\n});\n"],"names":["UpdateEntryLockUseCaseImpl","getLockRecord","lockEntry","repository","identityContext","input","recordResult","LockRecordNotFoundError","lockResult","Result","UpdateEntryLockError","record","updateResult","identity","IdentityMismatchError","UpdateEntryLockUseCase","UseCaseAbstraction","GetLockRecordUseCase","LockEntryUseCase","UpdateEntryLockRepository","IdentityContext"],"mappings":";;;;;;AAgBA,MAAMA;IACF,YACYC,aAA6C,EAC7CC,SAAqC,EACrCC,UAA+C,EAC/CC,eAA0C,CACpD;aAJUH,aAAa,GAAbA;aACAC,SAAS,GAATA;aACAC,UAAU,GAAVA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,KAA2B,EAC2B;QAEtD,MAAMC,eAAe,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAACD;QAGtD,IAAIC,aAAa,MAAM,IAAI;YACvB,IAAIA,aAAa,KAAK,YAAYC,yBAAyB;gBACvD,MAAMC,aAAa,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACH;gBAChD,IAAIG,WAAW,MAAM,IACjB,OAAOC,OAAO,IAAI,CAAC,IAAIC,qBAAqBF,WAAW,KAAK;gBAEhE,OAAOC,OAAO,EAAE,CAACD,WAAW,KAAK;YACrC;YACA,OAAOC,OAAO,IAAI,CAACH,aAAa,KAAK;QACzC;QAEA,MAAMK,SAASL,aAAa,KAAK;QAGjC,IAAIK,OAAO,SAAS,IAAI;YACpB,MAAMC,eAAe,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACD,OAAO,EAAE,EAAE;YAC7D,IAAIC,aAAa,MAAM,IACnB,OAAOH,OAAO,IAAI,CAAC,IAAIC,qBAAqBE,aAAa,KAAK;YAElE,OAAOH,OAAO,EAAE,CAACG,aAAa,KAAK;QACvC;QAGA,MAAMC,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QACjD,IAAIF,OAAO,QAAQ,CAAC,EAAE,KAAKE,SAAS,EAAE,EAClC,OAAOJ,OAAO,IAAI,CACd,IAAIK,sBAAsB;YACtB,WAAWD,SAAS,EAAE;YACtB,UAAUF,OAAO,QAAQ,CAAC,EAAE;QAChC;QAKR,MAAMC,eAAe,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACD,OAAO,EAAE,EAAE;QAC7D,IAAIC,aAAa,MAAM,IACnB,OAAOH,OAAO,IAAI,CAAC,IAAIC,qBAAqBE,aAAa,KAAK;QAGlE,OAAOH,OAAO,EAAE,CAACG,aAAa,KAAK;IACvC;AACJ;AAEO,MAAMG,gDAAyBC,uBAAAA,oBAAuC,CAAC;IAC1E,gBAAgBhB;IAChB,cAAc;QACViB;QACAC;QACAC;QACAC;KACH;AACL"}
|