@webiny/api-record-locking 6.3.0-beta.4 → 6.4.0-beta.0
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/domain/LockRecord.js +63 -70
- package/domain/LockRecord.js.map +1 -1
- package/domain/RecordLockingModel.js +26 -23
- package/domain/RecordLockingModel.js.map +1 -1
- package/domain/abstractions.js +3 -7
- package/domain/abstractions.js.map +1 -1
- package/domain/calculateExpiresOn.js +5 -6
- package/domain/calculateExpiresOn.js.map +1 -1
- package/domain/errors.js +71 -81
- package/domain/errors.js.map +1 -1
- package/domain/index.js +0 -2
- package/domain/types.js +6 -9
- package/domain/types.js.map +1 -1
- package/features/GetLockRecord/GetLockRecordRepository.js +27 -24
- package/features/GetLockRecord/GetLockRecordRepository.js.map +1 -1
- package/features/GetLockRecord/GetLockRecordUseCase.js +13 -10
- package/features/GetLockRecord/GetLockRecordUseCase.js.map +1 -1
- package/features/GetLockRecord/abstractions.js +3 -14
- package/features/GetLockRecord/abstractions.js.map +1 -1
- package/features/GetLockRecord/feature.js +7 -6
- package/features/GetLockRecord/feature.js.map +1 -1
- package/features/GetLockRecord/index.js +0 -2
- package/features/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js +19 -28
- package/features/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js.map +1 -1
- package/features/GetLockedEntryLockRecord/abstractions.js +2 -10
- package/features/GetLockedEntryLockRecord/abstractions.js.map +1 -1
- package/features/GetLockedEntryLockRecord/feature.js +6 -5
- package/features/GetLockedEntryLockRecord/feature.js.map +1 -1
- package/features/GetLockedEntryLockRecord/index.js +0 -2
- package/features/IsEntryLocked/IsEntryLockedUseCase.js +22 -28
- package/features/IsEntryLocked/IsEntryLockedUseCase.js.map +1 -1
- package/features/IsEntryLocked/abstractions.js +2 -9
- package/features/IsEntryLocked/abstractions.js.map +1 -1
- package/features/IsEntryLocked/feature.js +6 -5
- package/features/IsEntryLocked/feature.js.map +1 -1
- package/features/IsEntryLocked/index.js +0 -2
- package/features/KickOutCurrentUser/KickOutCurrentUserUseCase.js +32 -32
- package/features/KickOutCurrentUser/KickOutCurrentUserUseCase.js.map +1 -1
- package/features/KickOutCurrentUser/abstractions.js +2 -6
- package/features/KickOutCurrentUser/abstractions.js.map +1 -1
- package/features/KickOutCurrentUser/feature.js +6 -5
- package/features/KickOutCurrentUser/feature.js.map +1 -1
- package/features/KickOutCurrentUser/index.js +0 -2
- package/features/ListAllLockRecords/ListAllLockRecordsRepository.js +31 -31
- package/features/ListAllLockRecords/ListAllLockRecordsRepository.js.map +1 -1
- package/features/ListAllLockRecords/ListAllLockRecordsUseCase.js +13 -10
- package/features/ListAllLockRecords/ListAllLockRecordsUseCase.js.map +1 -1
- package/features/ListAllLockRecords/abstractions.js +3 -14
- package/features/ListAllLockRecords/abstractions.js.map +1 -1
- package/features/ListAllLockRecords/feature.js +7 -6
- package/features/ListAllLockRecords/feature.js.map +1 -1
- package/features/ListAllLockRecords/index.js +0 -2
- package/features/ListLockRecords/ListLockRecordsRepository.js +31 -31
- package/features/ListLockRecords/ListLockRecordsRepository.js.map +1 -1
- package/features/ListLockRecords/ListLockRecordsUseCase.js +26 -23
- package/features/ListLockRecords/ListLockRecordsUseCase.js.map +1 -1
- package/features/ListLockRecords/abstractions.js +3 -14
- package/features/ListLockRecords/abstractions.js.map +1 -1
- package/features/ListLockRecords/feature.js +7 -6
- package/features/ListLockRecords/feature.js.map +1 -1
- package/features/ListLockRecords/index.js +0 -2
- package/features/LockEntry/LockEntryEventsDecorator.js +31 -31
- package/features/LockEntry/LockEntryEventsDecorator.js.map +1 -1
- package/features/LockEntry/LockEntryRepository.js +33 -30
- package/features/LockEntry/LockEntryRepository.js.map +1 -1
- package/features/LockEntry/LockEntryUseCase.js +21 -26
- package/features/LockEntry/LockEntryUseCase.js.map +1 -1
- package/features/LockEntry/abstractions.js +3 -14
- package/features/LockEntry/abstractions.js.map +1 -1
- package/features/LockEntry/events.js +25 -33
- package/features/LockEntry/events.js.map +1 -1
- package/features/LockEntry/feature.js +8 -7
- package/features/LockEntry/feature.js.map +1 -1
- package/features/LockEntry/index.js +0 -2
- package/features/RecordLockingFeature.js +19 -21
- package/features/RecordLockingFeature.js.map +1 -1
- package/features/UnlockEntry/UnlockEntryEventsDecorator.js +32 -32
- package/features/UnlockEntry/UnlockEntryEventsDecorator.js.map +1 -1
- package/features/UnlockEntry/UnlockEntryRepository.js +29 -27
- package/features/UnlockEntry/UnlockEntryRepository.js.map +1 -1
- package/features/UnlockEntry/UnlockEntryUseCase.js +53 -69
- package/features/UnlockEntry/UnlockEntryUseCase.js.map +1 -1
- package/features/UnlockEntry/abstractions.js +3 -14
- package/features/UnlockEntry/abstractions.js.map +1 -1
- package/features/UnlockEntry/events.js +25 -33
- package/features/UnlockEntry/events.js.map +1 -1
- package/features/UnlockEntry/feature.js +8 -7
- package/features/UnlockEntry/feature.js.map +1 -1
- package/features/UnlockEntry/hasFullAccessPermission.js +6 -7
- package/features/UnlockEntry/hasFullAccessPermission.js.map +1 -1
- package/features/UnlockEntry/index.js +0 -2
- package/features/UnlockEntryRequest/UnlockEntryRequestEventsDecorator.js +31 -31
- package/features/UnlockEntryRequest/UnlockEntryRequestEventsDecorator.js.map +1 -1
- package/features/UnlockEntryRequest/UnlockEntryRequestRepository.js +31 -30
- package/features/UnlockEntryRequest/UnlockEntryRequestRepository.js.map +1 -1
- package/features/UnlockEntryRequest/UnlockEntryRequestUseCase.js +62 -79
- package/features/UnlockEntryRequest/UnlockEntryRequestUseCase.js.map +1 -1
- package/features/UnlockEntryRequest/abstractions.js +3 -14
- package/features/UnlockEntryRequest/abstractions.js.map +1 -1
- package/features/UnlockEntryRequest/events.js +25 -33
- package/features/UnlockEntryRequest/events.js.map +1 -1
- package/features/UnlockEntryRequest/feature.js +8 -7
- package/features/UnlockEntryRequest/feature.js.map +1 -1
- package/features/UnlockEntryRequest/index.js +0 -2
- package/features/UpdateEntryLock/UpdateEntryLockRepository.js +45 -48
- package/features/UpdateEntryLock/UpdateEntryLockRepository.js.map +1 -1
- package/features/UpdateEntryLock/UpdateEntryLockUseCase.js +40 -51
- package/features/UpdateEntryLock/UpdateEntryLockUseCase.js.map +1 -1
- package/features/UpdateEntryLock/abstractions.js +3 -14
- package/features/UpdateEntryLock/abstractions.js.map +1 -1
- package/features/UpdateEntryLock/feature.js +7 -6
- package/features/UpdateEntryLock/feature.js.map +1 -1
- package/features/UpdateEntryLock/index.js +0 -2
- package/graphql/checkPermissions.js +5 -9
- package/graphql/checkPermissions.js.map +1 -1
- package/graphql/resolve.js +15 -17
- package/graphql/resolve.js.map +1 -1
- package/graphql/schema.js +147 -165
- package/graphql/schema.js.map +1 -1
- package/index.js +40 -49
- package/index.js.map +1 -1
- package/package.json +17 -17
- package/types.js +6 -9
- package/types.js.map +1 -1
- package/utils/convertWhereCondition.js +20 -32
- package/utils/convertWhereCondition.js.map +1 -1
- package/utils/getTimeout.js +8 -15
- package/utils/getTimeout.js.map +1 -1
- package/utils/lockRecordDatabaseId.js +6 -11
- package/utils/lockRecordDatabaseId.js.map +1 -1
- package/domain/index.js.map +0 -1
- package/features/GetLockRecord/index.js.map +0 -1
- package/features/GetLockedEntryLockRecord/index.js.map +0 -1
- package/features/IsEntryLocked/index.js.map +0 -1
- package/features/KickOutCurrentUser/index.js.map +0 -1
- package/features/ListAllLockRecords/index.js.map +0 -1
- package/features/ListLockRecords/index.js.map +0 -1
- package/features/LockEntry/index.js.map +0 -1
- package/features/UnlockEntry/index.js.map +0 -1
- package/features/UnlockEntryRequest/index.js.map +0 -1
- package/features/UpdateEntryLock/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/UnlockEntry/UnlockEntryRepository.js","sources":["../../../src/features/UnlockEntry/UnlockEntryRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry\";\nimport { createIdentifier } from \"@webiny/utils\";\nimport { UnlockEntryRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { RecordLockingModel } from \"~/domain/abstractions.js\";\nimport { LockRecordNotFoundError, UnlockEntryError } from \"~/domain/errors.js\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId.js\";\n\nclass UnlockEntryRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private model: RecordLockingModel.Interface,\n private deleteEntry: DeleteEntryUseCase.Interface\n ) {}\n\n async delete(lockRecordId: string): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n const entryId = createLockRecordDatabaseId(lockRecordId);\n const id = createIdentifier({\n id: entryId,\n version: 1\n });\n\n const result = await this.deleteEntry.execute(this.model, id, {\n permanently: true\n });\n\n if (result.isFail()) {\n if (result.error.code === \"Cms/Entry/NotFound\") {\n return Result.fail(new LockRecordNotFoundError());\n }\n return Result.fail(new UnlockEntryError(result.error));\n }\n\n return Result.ok();\n } catch (error) {\n return Result.fail(new UnlockEntryError(error as Error));\n }\n }\n}\n\nexport const UnlockEntryRepository = RepositoryAbstraction.createImplementation({\n implementation: UnlockEntryRepositoryImpl,\n dependencies: [RecordLockingModel, DeleteEntryUseCase]\n});\n"],"names":["UnlockEntryRepositoryImpl","model","deleteEntry","lockRecordId","entryId","createLockRecordDatabaseId","id","createIdentifier","result","Result","LockRecordNotFoundError","UnlockEntryError","error","UnlockEntryRepository","RepositoryAbstraction","RecordLockingModel","DeleteEntryUseCase"],"mappings":";;;;;;;AAQA,MAAMA;IACF,YACYC,KAAmC,EACnCC,WAAyC,CACnD;aAFUD,KAAK,GAALA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,OAAOC,YAAoB,EAAsD;QACnF,IAAI;YACA,MAAMC,UAAUC,2BAA2BF;YAC3C,MAAMG,KAAKC,iBAAiB;gBACxB,IAAIH;gBACJ,SAAS;YACb;YAEA,MAAMI,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAEF,IAAI;gBAC1D,aAAa;YACjB;YAEA,IAAIE,OAAO,MAAM,IAAI;gBACjB,IAAIA,AAAsB,yBAAtBA,OAAO,KAAK,CAAC,IAAI,EACjB,OAAOC,OAAO,IAAI,CAAC,IAAIC;gBAE3B,OAAOD,OAAO,IAAI,CAAC,IAAIE,iBAAiBH,OAAO,KAAK;YACxD;YAEA,OAAOC,OAAO,EAAE;QACpB,EAAE,OAAOG,OAAO;YACZ,OAAOH,OAAO,IAAI,CAAC,IAAIE,iBAAiBC;QAC5C;IACJ;AACJ;AAEO,MAAMC,8CAAwBC,sBAAAA,oBAA0C,CAAC;IAC5E,gBAAgBd;IAChB,cAAc;QAACe;QAAoBC;KAAmB;AAC1D"}
|
|
@@ -1,81 +1,65 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import {
|
|
2
|
+
import { UnlockEntryRepository, UnlockEntryUseCase } from "./abstractions.js";
|
|
3
3
|
import { GetLockRecordUseCase } from "../GetLockRecord/abstractions.js";
|
|
4
4
|
import { KickOutCurrentUserUseCase } from "../KickOutCurrentUser/abstractions.js";
|
|
5
5
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { IdentityMismatchError, LockRecordNotFoundError } from "../../domain/errors.js";
|
|
7
7
|
import { hasFullAccessPermission } from "./hasFullAccessPermission.js";
|
|
8
8
|
class UnlockEntryUseCaseImpl {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
async execute(input) {
|
|
16
|
-
// Get the lock record
|
|
17
|
-
const recordResult = await this.getLockRecord.execute(input);
|
|
18
|
-
|
|
19
|
-
// If not found or expired, attempt cleanup and return error
|
|
20
|
-
if (recordResult.isFail()) {
|
|
21
|
-
if (recordResult.error instanceof LockRecordNotFoundError) {
|
|
22
|
-
// Try to cleanup any stale data
|
|
23
|
-
await this.repository.delete(input.id);
|
|
24
|
-
}
|
|
25
|
-
return Result.fail(recordResult.error);
|
|
26
|
-
}
|
|
27
|
-
const record = recordResult.value;
|
|
28
|
-
|
|
29
|
-
// If expired, cleanup and return error
|
|
30
|
-
if (record.isExpired()) {
|
|
31
|
-
await this.repository.delete(record.id);
|
|
32
|
-
const error = new LockRecordNotFoundError();
|
|
33
|
-
return Result.fail(error);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Check if user is the owner
|
|
37
|
-
const identity = this.identityContext.getIdentity();
|
|
38
|
-
const isSameUser = record.lockedBy.id === identity.id;
|
|
39
|
-
let shouldKickOut = false;
|
|
40
|
-
|
|
41
|
-
// If not the owner, check if force unlock is allowed
|
|
42
|
-
if (!isSameUser) {
|
|
43
|
-
if (!input.force) {
|
|
44
|
-
const error = new IdentityMismatchError({
|
|
45
|
-
currentId: identity.id,
|
|
46
|
-
targetId: record.lockedBy.id
|
|
47
|
-
});
|
|
48
|
-
return Result.fail(error);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Check if user has permission to force unlock
|
|
52
|
-
const hasAccess = await hasFullAccessPermission(this.identityContext);
|
|
53
|
-
if (!hasAccess) {
|
|
54
|
-
const error = new IdentityMismatchError({
|
|
55
|
-
currentId: identity.id,
|
|
56
|
-
targetId: record.lockedBy.id
|
|
57
|
-
});
|
|
58
|
-
return Result.fail(error);
|
|
59
|
-
}
|
|
60
|
-
shouldKickOut = true;
|
|
9
|
+
constructor(getLockRecord, kickOutCurrentUser, repository, identityContext){
|
|
10
|
+
this.getLockRecord = getLockRecord;
|
|
11
|
+
this.kickOutCurrentUser = kickOutCurrentUser;
|
|
12
|
+
this.repository = repository;
|
|
13
|
+
this.identityContext = identityContext;
|
|
61
14
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
15
|
+
async execute(input) {
|
|
16
|
+
const recordResult = await this.getLockRecord.execute(input);
|
|
17
|
+
if (recordResult.isFail()) {
|
|
18
|
+
if (recordResult.error instanceof LockRecordNotFoundError) await this.repository.delete(input.id);
|
|
19
|
+
return Result.fail(recordResult.error);
|
|
20
|
+
}
|
|
21
|
+
const record = recordResult.value;
|
|
22
|
+
if (record.isExpired()) {
|
|
23
|
+
await this.repository.delete(record.id);
|
|
24
|
+
const error = new LockRecordNotFoundError();
|
|
25
|
+
return Result.fail(error);
|
|
26
|
+
}
|
|
27
|
+
const identity = this.identityContext.getIdentity();
|
|
28
|
+
const isSameUser = record.lockedBy.id === identity.id;
|
|
29
|
+
let shouldKickOut = false;
|
|
30
|
+
if (!isSameUser) {
|
|
31
|
+
if (!input.force) {
|
|
32
|
+
const error = new IdentityMismatchError({
|
|
33
|
+
currentId: identity.id,
|
|
34
|
+
targetId: record.lockedBy.id
|
|
35
|
+
});
|
|
36
|
+
return Result.fail(error);
|
|
37
|
+
}
|
|
38
|
+
const hasAccess = await hasFullAccessPermission(this.identityContext);
|
|
39
|
+
if (!hasAccess) {
|
|
40
|
+
const error = new IdentityMismatchError({
|
|
41
|
+
currentId: identity.id,
|
|
42
|
+
targetId: record.lockedBy.id
|
|
43
|
+
});
|
|
44
|
+
return Result.fail(error);
|
|
45
|
+
}
|
|
46
|
+
shouldKickOut = true;
|
|
47
|
+
}
|
|
48
|
+
const deleteResult = await this.repository.delete(record.id);
|
|
49
|
+
if (deleteResult.isFail()) return Result.fail(deleteResult.error);
|
|
50
|
+
if (shouldKickOut) await this.kickOutCurrentUser.execute(record);
|
|
51
|
+
return Result.ok(record);
|
|
72
52
|
}
|
|
73
|
-
return Result.ok(record);
|
|
74
|
-
}
|
|
75
53
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
54
|
+
const UnlockEntryUseCase_UnlockEntryUseCase = UnlockEntryUseCase.createImplementation({
|
|
55
|
+
implementation: UnlockEntryUseCaseImpl,
|
|
56
|
+
dependencies: [
|
|
57
|
+
GetLockRecordUseCase,
|
|
58
|
+
KickOutCurrentUserUseCase,
|
|
59
|
+
UnlockEntryRepository,
|
|
60
|
+
IdentityContext
|
|
61
|
+
]
|
|
79
62
|
});
|
|
63
|
+
export { UnlockEntryUseCase_UnlockEntryUseCase as UnlockEntryUseCase };
|
|
80
64
|
|
|
81
65
|
//# sourceMappingURL=UnlockEntryUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/UnlockEntry/UnlockEntryUseCase.js","sources":["../../../src/features/UnlockEntry/UnlockEntryUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n UnlockEntryUseCase as UseCaseAbstraction,\n UnlockEntryRepository,\n UnlockEntryInput\n} from \"./abstractions.js\";\nimport { GetLockRecordUseCase } from \"../GetLockRecord/abstractions.js\";\nimport { KickOutCurrentUserUseCase } from \"../KickOutCurrentUser/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type { ILockRecord } from \"~/domain/LockRecord.js\";\nimport { LockRecordNotFoundError, IdentityMismatchError } from \"~/domain/errors.js\";\nimport { hasFullAccessPermission } from \"./hasFullAccessPermission.js\";\n\nclass UnlockEntryUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private getLockRecord: GetLockRecordUseCase.Interface,\n private kickOutCurrentUser: KickOutCurrentUserUseCase.Interface,\n private repository: UnlockEntryRepository.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async execute(input: UnlockEntryInput): Promise<Result<ILockRecord, UseCaseAbstraction.Error>> {\n // Get the lock record\n const recordResult = await this.getLockRecord.execute(input);\n\n // If not found or expired, attempt cleanup and return error\n if (recordResult.isFail()) {\n if (recordResult.error instanceof LockRecordNotFoundError) {\n // Try to cleanup any stale data\n await this.repository.delete(input.id);\n }\n\n return Result.fail(recordResult.error);\n }\n\n const record = recordResult.value;\n\n // If expired, cleanup and return error\n if (record.isExpired()) {\n await this.repository.delete(record.id);\n const error = new LockRecordNotFoundError();\n return Result.fail(error);\n }\n\n // Check if user is the owner\n const identity = this.identityContext.getIdentity();\n const isSameUser = record.lockedBy.id === identity.id;\n\n let shouldKickOut = false;\n\n // If not the owner, check if force unlock is allowed\n if (!isSameUser) {\n if (!input.force) {\n const error = new IdentityMismatchError({\n currentId: identity.id,\n targetId: record.lockedBy.id\n });\n return Result.fail(error);\n }\n\n // Check if user has permission to force unlock\n const hasAccess = await hasFullAccessPermission(this.identityContext);\n if (!hasAccess) {\n const error = new IdentityMismatchError({\n currentId: identity.id,\n targetId: record.lockedBy.id\n });\n return Result.fail(error);\n }\n\n shouldKickOut = true;\n }\n\n // Delete the lock record\n const deleteResult = await this.repository.delete(record.id);\n\n if (deleteResult.isFail()) {\n return Result.fail(deleteResult.error);\n }\n\n // If forced by another user, kick out the original lock owner\n if (shouldKickOut) {\n await this.kickOutCurrentUser.execute(record);\n }\n\n return Result.ok(record);\n }\n}\n\nexport const UnlockEntryUseCase = UseCaseAbstraction.createImplementation({\n implementation: UnlockEntryUseCaseImpl,\n dependencies: [\n GetLockRecordUseCase,\n KickOutCurrentUserUseCase,\n UnlockEntryRepository,\n IdentityContext\n ]\n});\n"],"names":["UnlockEntryUseCaseImpl","getLockRecord","kickOutCurrentUser","repository","identityContext","input","recordResult","LockRecordNotFoundError","Result","record","error","identity","isSameUser","shouldKickOut","IdentityMismatchError","hasAccess","hasFullAccessPermission","deleteResult","UnlockEntryUseCase","UseCaseAbstraction","GetLockRecordUseCase","KickOutCurrentUserUseCase","UnlockEntryRepository","IdentityContext"],"mappings":";;;;;;;AAaA,MAAMA;IACF,YACYC,aAA6C,EAC7CC,kBAAuD,EACvDC,UAA2C,EAC3CC,eAA0C,CACpD;aAJUH,aAAa,GAAbA;aACAC,kBAAkB,GAAlBA;aACAC,UAAU,GAAVA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QAAQC,KAAuB,EAA0D;QAE3F,MAAMC,eAAe,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAACD;QAGtD,IAAIC,aAAa,MAAM,IAAI;YACvB,IAAIA,aAAa,KAAK,YAAYC,yBAE9B,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACF,MAAM,EAAE;YAGzC,OAAOG,OAAO,IAAI,CAACF,aAAa,KAAK;QACzC;QAEA,MAAMG,SAASH,aAAa,KAAK;QAGjC,IAAIG,OAAO,SAAS,IAAI;YACpB,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACA,OAAO,EAAE;YACtC,MAAMC,QAAQ,IAAIH;YAClB,OAAOC,OAAO,IAAI,CAACE;QACvB;QAGA,MAAMC,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QACjD,MAAMC,aAAaH,OAAO,QAAQ,CAAC,EAAE,KAAKE,SAAS,EAAE;QAErD,IAAIE,gBAAgB;QAGpB,IAAI,CAACD,YAAY;YACb,IAAI,CAACP,MAAM,KAAK,EAAE;gBACd,MAAMK,QAAQ,IAAII,sBAAsB;oBACpC,WAAWH,SAAS,EAAE;oBACtB,UAAUF,OAAO,QAAQ,CAAC,EAAE;gBAChC;gBACA,OAAOD,OAAO,IAAI,CAACE;YACvB;YAGA,MAAMK,YAAY,MAAMC,wBAAwB,IAAI,CAAC,eAAe;YACpE,IAAI,CAACD,WAAW;gBACZ,MAAML,QAAQ,IAAII,sBAAsB;oBACpC,WAAWH,SAAS,EAAE;oBACtB,UAAUF,OAAO,QAAQ,CAAC,EAAE;gBAChC;gBACA,OAAOD,OAAO,IAAI,CAACE;YACvB;YAEAG,gBAAgB;QACpB;QAGA,MAAMI,eAAe,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACR,OAAO,EAAE;QAE3D,IAAIQ,aAAa,MAAM,IACnB,OAAOT,OAAO,IAAI,CAACS,aAAa,KAAK;QAIzC,IAAIJ,eACA,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAACJ;QAG1C,OAAOD,OAAO,EAAE,CAACC;IACrB;AACJ;AAEO,MAAMS,wCAAqBC,mBAAAA,oBAAuC,CAAC;IACtE,gBAAgBnB;IAChB,cAAc;QACVoB;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* UnlockEntry Use Case - Unlocks an entry by deleting the lock record
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export const UnlockEntryUseCase = createAbstraction("UnlockEntryUseCase");
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* UnlockEntryRepository - Deletes lock record from storage
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export const UnlockEntryRepository = createAbstraction("UnlockEntryRepository");
|
|
2
|
+
const UnlockEntryUseCase = createAbstraction("UnlockEntryUseCase");
|
|
3
|
+
const UnlockEntryRepository = createAbstraction("UnlockEntryRepository");
|
|
4
|
+
export { UnlockEntryRepository, UnlockEntryUseCase };
|
|
16
5
|
|
|
17
6
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/UnlockEntry/abstractions.js","sources":["../../../src/features/UnlockEntry/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 {\n type LockRecordNotFoundError,\n LockRecordPersistenceError,\n type IdentityMismatchError,\n type UnlockEntryError\n} from \"~/domain/errors.js\";\n\n// Input types\nexport interface UnlockEntryInput {\n id: string;\n type: LockRecordEntryType;\n force?: boolean;\n}\n\n/**\n * UnlockEntry Use Case - Unlocks an entry by deleting the lock record\n */\nexport interface IUnlockEntryUseCase {\n execute(input: UnlockEntryInput): Promise<Result<ILockRecord, UseCaseError>>;\n}\n\nexport interface IUnlockEntryUseCaseErrors {\n notFound: LockRecordNotFoundError;\n notSameIdentity: IdentityMismatchError;\n unlockError: UnlockEntryError;\n persistence: LockRecordPersistenceError;\n}\n\ntype UseCaseError = IUnlockEntryUseCaseErrors[keyof IUnlockEntryUseCaseErrors];\n\nexport const UnlockEntryUseCase = createAbstraction<IUnlockEntryUseCase>(\"UnlockEntryUseCase\");\n\nexport namespace UnlockEntryUseCase {\n export type Interface = IUnlockEntryUseCase;\n export type Error = UseCaseError;\n}\n\n/**\n * UnlockEntryRepository - Deletes lock record from storage\n */\nexport interface IUnlockEntryRepository {\n delete(lockRecordId: string): Promise<Result<void, RepositoryError>>;\n}\n\nexport interface IUnlockEntryRepositoryErrors {\n notFound: LockRecordNotFoundError;\n unlockError: UnlockEntryError;\n}\n\ntype RepositoryError = IUnlockEntryRepositoryErrors[keyof IUnlockEntryRepositoryErrors];\n\nexport const UnlockEntryRepository =\n createAbstraction<IUnlockEntryRepository>(\"UnlockEntryRepository\");\n\nexport namespace UnlockEntryRepository {\n export type Interface = IUnlockEntryRepository;\n export type Error = RepositoryError;\n}\n"],"names":["UnlockEntryUseCase","createAbstraction","UnlockEntryRepository"],"mappings":";AAkCO,MAAMA,qBAAqBC,kBAAuC;AAqBlE,MAAMC,wBACTD,kBAA0C"}
|
|
@@ -1,40 +1,32 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
2
|
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
getHandlerAbstraction() {
|
|
11
|
-
return EntryBeforeUnlockEventHandler;
|
|
12
|
-
}
|
|
3
|
+
class EntryBeforeUnlockEvent extends DomainEvent {
|
|
4
|
+
getHandlerAbstraction() {
|
|
5
|
+
return EntryBeforeUnlockEventHandler;
|
|
6
|
+
}
|
|
7
|
+
constructor(...args){
|
|
8
|
+
super(...args), this.eventType = "RecordLocking/Entry/BeforeUnlock";
|
|
9
|
+
}
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
getHandlerAbstraction() {
|
|
23
|
-
return EntryAfterUnlockEventHandler;
|
|
24
|
-
}
|
|
11
|
+
const EntryBeforeUnlockEventHandler = createAbstraction("EntryBeforeUnlockEventHandler");
|
|
12
|
+
class EntryAfterUnlockEvent extends DomainEvent {
|
|
13
|
+
getHandlerAbstraction() {
|
|
14
|
+
return EntryAfterUnlockEventHandler;
|
|
15
|
+
}
|
|
16
|
+
constructor(...args){
|
|
17
|
+
super(...args), this.eventType = "RecordLocking/Entry/AfterUnlock";
|
|
18
|
+
}
|
|
25
19
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
getHandlerAbstraction() {
|
|
35
|
-
return EntryUnlockErrorEventHandler;
|
|
36
|
-
}
|
|
20
|
+
const EntryAfterUnlockEventHandler = createAbstraction("EntryAfterUnlockEventHandler");
|
|
21
|
+
class EntryUnlockErrorEvent extends DomainEvent {
|
|
22
|
+
getHandlerAbstraction() {
|
|
23
|
+
return EntryUnlockErrorEventHandler;
|
|
24
|
+
}
|
|
25
|
+
constructor(...args){
|
|
26
|
+
super(...args), this.eventType = "RecordLocking/Entry/UnlockError";
|
|
27
|
+
}
|
|
37
28
|
}
|
|
38
|
-
|
|
29
|
+
const EntryUnlockErrorEventHandler = createAbstraction("EntryUnlockErrorEventHandler");
|
|
30
|
+
export { EntryAfterUnlockEvent, EntryAfterUnlockEventHandler, EntryBeforeUnlockEvent, EntryBeforeUnlockEventHandler, EntryUnlockErrorEvent, EntryUnlockErrorEventHandler };
|
|
39
31
|
|
|
40
32
|
//# sourceMappingURL=events.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/UnlockEntry/events.js","sources":["../../../src/features/UnlockEntry/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// EntryBeforeUnlock Event\n// ============================================================================\n\nexport interface EntryBeforeUnlockPayload {\n id: string;\n type: LockRecordEntryType;\n force?: boolean;\n}\n\nexport class EntryBeforeUnlockEvent extends DomainEvent<EntryBeforeUnlockPayload> {\n eventType = \"RecordLocking/Entry/BeforeUnlock\" as const;\n\n getHandlerAbstraction() {\n return EntryBeforeUnlockEventHandler;\n }\n}\n\nexport const EntryBeforeUnlockEventHandler = createAbstraction<\n IEventHandler<EntryBeforeUnlockEvent>\n>(\"EntryBeforeUnlockEventHandler\");\n\nexport namespace EntryBeforeUnlockEventHandler {\n export type Interface = IEventHandler<EntryBeforeUnlockEvent>;\n export type Event = EntryBeforeUnlockEvent;\n}\n\n// ============================================================================\n// EntryAfterUnlock Event\n// ============================================================================\n\nexport interface EntryAfterUnlockPayload {\n id: string;\n type: LockRecordEntryType;\n record: ILockRecord;\n}\n\nexport class EntryAfterUnlockEvent extends DomainEvent<EntryAfterUnlockPayload> {\n eventType = \"RecordLocking/Entry/AfterUnlock\" as const;\n\n getHandlerAbstraction() {\n return EntryAfterUnlockEventHandler;\n }\n}\n\nexport const EntryAfterUnlockEventHandler = createAbstraction<IEventHandler<EntryAfterUnlockEvent>>(\n \"EntryAfterUnlockEventHandler\"\n);\n\nexport namespace EntryAfterUnlockEventHandler {\n export type Interface = IEventHandler<EntryAfterUnlockEvent>;\n export type Event = EntryAfterUnlockEvent;\n}\n\n// ============================================================================\n// EntryUnlockError Event\n// ============================================================================\n\nexport interface EntryUnlockErrorPayload {\n id: string;\n type: LockRecordEntryType;\n error: Error;\n}\n\nexport class EntryUnlockErrorEvent extends DomainEvent<EntryUnlockErrorPayload> {\n eventType = \"RecordLocking/Entry/UnlockError\" as const;\n\n getHandlerAbstraction() {\n return EntryUnlockErrorEventHandler;\n }\n}\n\nexport const EntryUnlockErrorEventHandler = createAbstraction<IEventHandler<EntryUnlockErrorEvent>>(\n \"EntryUnlockErrorEventHandler\"\n);\n\nexport namespace EntryUnlockErrorEventHandler {\n export type Interface = IEventHandler<EntryUnlockErrorEvent>;\n export type Event = EntryUnlockErrorEvent;\n}\n"],"names":["EntryBeforeUnlockEvent","DomainEvent","EntryBeforeUnlockEventHandler","createAbstraction","EntryAfterUnlockEvent","EntryAfterUnlockEventHandler","EntryUnlockErrorEvent","EntryUnlockErrorEventHandler"],"mappings":";;AAgBO,MAAMA,+BAA+BC;IAGxC,wBAAwB;QACpB,OAAOC;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMA,gCAAgCC,kBAE3C;AAiBK,MAAMC,8BAA8BH;IAGvC,wBAAwB;QACpB,OAAOI;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMA,+BAA+BF,kBACxC;AAkBG,MAAMG,8BAA8BL;IAGvC,wBAAwB;QACpB,OAAOM;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMA,+BAA+BJ,kBACxC"}
|
|
@@ -2,13 +2,14 @@ import { createFeature } from "@webiny/feature/api";
|
|
|
2
2
|
import { UnlockEntryUseCase } from "./UnlockEntryUseCase.js";
|
|
3
3
|
import { UnlockEntryRepository } from "./UnlockEntryRepository.js";
|
|
4
4
|
import { UnlockEntryEventsDecorator } from "./UnlockEntryEventsDecorator.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const UnlockEntryFeature = createFeature({
|
|
6
|
+
name: "UnlockEntry",
|
|
7
|
+
register (container) {
|
|
8
|
+
container.register(UnlockEntryUseCase);
|
|
9
|
+
container.register(UnlockEntryRepository).inSingletonScope();
|
|
10
|
+
container.registerDecorator(UnlockEntryEventsDecorator);
|
|
11
|
+
}
|
|
12
12
|
});
|
|
13
|
+
export { UnlockEntryFeature };
|
|
13
14
|
|
|
14
15
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/UnlockEntry/feature.js","sources":["../../../src/features/UnlockEntry/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { UnlockEntryUseCase } from \"./UnlockEntryUseCase.js\";\nimport { UnlockEntryRepository } from \"./UnlockEntryRepository.js\";\nimport { UnlockEntryEventsDecorator } from \"./UnlockEntryEventsDecorator.js\";\n\nexport const UnlockEntryFeature = createFeature({\n name: \"UnlockEntry\",\n register(container) {\n container.register(UnlockEntryUseCase);\n container.register(UnlockEntryRepository).inSingletonScope();\n container.registerDecorator(UnlockEntryEventsDecorator);\n }\n});\n"],"names":["UnlockEntryFeature","createFeature","container","UnlockEntryUseCase","UnlockEntryRepository","UnlockEntryEventsDecorator"],"mappings":";;;;AAKO,MAAMA,qBAAqBC,cAAc;IAC5C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE,uBAAuB,gBAAgB;QAC1DF,UAAU,iBAAiB,CAACG;IAChC;AACJ"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const permission = await identityContext.getPermission("recordLocking");
|
|
7
|
-
return permission?.canForceUnlock === true;
|
|
1
|
+
const hasFullAccessPermission = async (identityContext)=>{
|
|
2
|
+
const hasFullAccess = await identityContext.hasFullAccess();
|
|
3
|
+
if (hasFullAccess) return true;
|
|
4
|
+
const permission = await identityContext.getPermission("recordLocking");
|
|
5
|
+
return permission?.canForceUnlock === true;
|
|
8
6
|
};
|
|
7
|
+
export { hasFullAccessPermission };
|
|
9
8
|
|
|
10
9
|
//# sourceMappingURL=hasFullAccessPermission.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/UnlockEntry/hasFullAccessPermission.js","sources":["../../../src/features/UnlockEntry/hasFullAccessPermission.ts"],"sourcesContent":["import type { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type { SecurityPermission } from \"@webiny/api-core/types/security.js\";\n\ninterface RecordLockingSecurityPermission extends SecurityPermission {\n canForceUnlock?: boolean;\n}\n\nexport const hasFullAccessPermission = async (\n identityContext: IdentityContext.Interface\n): Promise<boolean> => {\n const hasFullAccess = await identityContext.hasFullAccess();\n if (hasFullAccess) {\n return true;\n }\n\n const permission =\n await identityContext.getPermission<RecordLockingSecurityPermission>(\"recordLocking\");\n return permission?.canForceUnlock === true;\n};\n"],"names":["hasFullAccessPermission","identityContext","hasFullAccess","permission"],"mappings":"AAOO,MAAMA,0BAA0B,OACnCC;IAEA,MAAMC,gBAAgB,MAAMD,gBAAgB,aAAa;IACzD,IAAIC,eACA,OAAO;IAGX,MAAMC,aACF,MAAMF,gBAAgB,aAAa,CAAkC;IACzE,OAAOE,YAAY,mBAAmB;AAC1C"}
|
|
@@ -2,39 +2,39 @@ import { UnlockEntryRequestUseCase } from "./abstractions.js";
|
|
|
2
2
|
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
3
|
import { EntryAfterUnlockRequestEvent, EntryBeforeUnlockRequestEvent, EntryUnlockRequestErrorEvent } from "./events.js";
|
|
4
4
|
class UnlockEntryRequestEventsDecoratorImpl {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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;
|
|
24
30
|
}
|
|
25
|
-
|
|
26
|
-
// Publish after event
|
|
27
|
-
await this.eventPublisher.publish(new EntryAfterUnlockRequestEvent({
|
|
28
|
-
id: input.id,
|
|
29
|
-
type: input.type,
|
|
30
|
-
record: result.value
|
|
31
|
-
}));
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
31
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
const UnlockEntryRequestEventsDecorator = UnlockEntryRequestUseCase.createDecorator({
|
|
33
|
+
decorator: UnlockEntryRequestEventsDecoratorImpl,
|
|
34
|
+
dependencies: [
|
|
35
|
+
EventPublisher
|
|
36
|
+
]
|
|
38
37
|
});
|
|
38
|
+
export { UnlockEntryRequestEventsDecorator };
|
|
39
39
|
|
|
40
40
|
//# sourceMappingURL=UnlockEntryRequestEventsDecorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import { UnlockEntryRequestRepository
|
|
2
|
+
import { UnlockEntryRequestRepository } from "./abstractions.js";
|
|
3
3
|
import { UpdateEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UpdateEntry";
|
|
4
4
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
5
|
import { RecordLockingModel } from "../../domain/abstractions.js";
|
|
@@ -7,37 +7,38 @@ import { UnlockEntryRequestError } from "../../domain/errors.js";
|
|
|
7
7
|
import { createLockRecordDatabaseId } from "../../utils/lockRecordDatabaseId.js";
|
|
8
8
|
import { createIdentifier } from "@webiny/utils";
|
|
9
9
|
class UnlockEntryRequestRepositoryImpl {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return Result.ok(record);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
return Result.fail(new UnlockEntryRequestError(error));
|
|
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
|
+
}
|
|
35
32
|
}
|
|
36
|
-
}
|
|
37
33
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
const UnlockEntryRequestRepository_UnlockEntryRequestRepository = UnlockEntryRequestRepository.createImplementation({
|
|
35
|
+
implementation: UnlockEntryRequestRepositoryImpl,
|
|
36
|
+
dependencies: [
|
|
37
|
+
UpdateEntryUseCase,
|
|
38
|
+
IdentityContext,
|
|
39
|
+
RecordLockingModel
|
|
40
|
+
]
|
|
41
41
|
});
|
|
42
|
+
export { UnlockEntryRequestRepository_UnlockEntryRequestRepository as UnlockEntryRequestRepository };
|
|
42
43
|
|
|
43
44
|
//# sourceMappingURL=UnlockEntryRequestRepository.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|