@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,62 +1,51 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import {
|
|
2
|
+
import { UpdateEntryLockRepository, UpdateEntryLockUseCase } from "./abstractions.js";
|
|
3
3
|
import { GetLockRecordUseCase } from "../GetLockRecord/abstractions.js";
|
|
4
4
|
import { LockEntryUseCase } from "../LockEntry/abstractions.js";
|
|
5
5
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { IdentityMismatchError, LockRecordNotFoundError, UpdateEntryLockError } from "../../domain/errors.js";
|
|
7
7
|
class UpdateEntryLockUseCaseImpl {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
async execute(input) {
|
|
15
|
-
// Try to get existing lock record
|
|
16
|
-
const recordResult = await this.getLockRecord.execute(input);
|
|
17
|
-
|
|
18
|
-
// If doesn't exist, create a new lock
|
|
19
|
-
if (recordResult.isFail()) {
|
|
20
|
-
if (recordResult.error instanceof LockRecordNotFoundError) {
|
|
21
|
-
const lockResult = await this.lockEntry.execute(input);
|
|
22
|
-
if (lockResult.isFail()) {
|
|
23
|
-
return Result.fail(new UpdateEntryLockError(lockResult.error));
|
|
24
|
-
}
|
|
25
|
-
return Result.ok(lockResult.value);
|
|
26
|
-
}
|
|
27
|
-
return Result.fail(recordResult.error);
|
|
8
|
+
constructor(getLockRecord, lockEntry, repository, identityContext){
|
|
9
|
+
this.getLockRecord = getLockRecord;
|
|
10
|
+
this.lockEntry = lockEntry;
|
|
11
|
+
this.repository = repository;
|
|
12
|
+
this.identityContext = identityContext;
|
|
28
13
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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);
|
|
53
38
|
}
|
|
54
|
-
return Result.ok(updateResult.value);
|
|
55
|
-
}
|
|
56
39
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
40
|
+
const UpdateEntryLockUseCase_UpdateEntryLockUseCase = UpdateEntryLockUseCase.createImplementation({
|
|
41
|
+
implementation: UpdateEntryLockUseCaseImpl,
|
|
42
|
+
dependencies: [
|
|
43
|
+
GetLockRecordUseCase,
|
|
44
|
+
LockEntryUseCase,
|
|
45
|
+
UpdateEntryLockRepository,
|
|
46
|
+
IdentityContext
|
|
47
|
+
]
|
|
60
48
|
});
|
|
49
|
+
export { UpdateEntryLockUseCase_UpdateEntryLockUseCase as UpdateEntryLockUseCase };
|
|
61
50
|
|
|
62
51
|
//# sourceMappingURL=UpdateEntryLockUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* UpdateEntryLock Use Case - Updates lock timestamp to keep it alive
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export const UpdateEntryLockUseCase = createAbstraction("UpdateEntryLockUseCase");
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* UpdateEntryLockRepository - Updates lock record in storage
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export const UpdateEntryLockRepository = createAbstraction("UpdateEntryLockRepository");
|
|
2
|
+
const UpdateEntryLockUseCase = createAbstraction("UpdateEntryLockUseCase");
|
|
3
|
+
const UpdateEntryLockRepository = createAbstraction("UpdateEntryLockRepository");
|
|
4
|
+
export { UpdateEntryLockRepository, UpdateEntryLockUseCase };
|
|
16
5
|
|
|
17
6
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/UpdateEntryLock/abstractions.js","sources":["../../../src/features/UpdateEntryLock/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 LockRecordNotFoundError,\n LockRecordPersistenceError,\n IdentityMismatchError,\n UpdateEntryLockError\n} from \"~/domain/errors.js\";\n\n// Input types\nexport interface UpdateEntryLockInput {\n id: string;\n type: LockRecordEntryType;\n}\n\n/**\n * UpdateEntryLock Use Case - Updates lock timestamp to keep it alive\n */\nexport interface IUpdateEntryLockUseCase {\n execute(input: UpdateEntryLockInput): Promise<Result<ILockRecord, UseCaseError>>;\n}\n\nexport interface IUpdateEntryLockUseCaseErrors {\n notFound: LockRecordNotFoundError;\n notSameIdentity: IdentityMismatchError;\n persistence: LockRecordPersistenceError;\n updateError: UpdateEntryLockError;\n}\n\ntype UseCaseError = IUpdateEntryLockUseCaseErrors[keyof IUpdateEntryLockUseCaseErrors];\n\nexport const UpdateEntryLockUseCase =\n createAbstraction<IUpdateEntryLockUseCase>(\"UpdateEntryLockUseCase\");\n\nexport namespace UpdateEntryLockUseCase {\n export type Interface = IUpdateEntryLockUseCase;\n export type Error = UseCaseError;\n}\n\n/**\n * UpdateEntryLockRepository - Updates lock record in storage\n */\nexport interface IUpdateEntryLockRepository {\n update(\n lockRecordId: string,\n updateOwner: boolean\n ): Promise<Result<ILockRecord, RepositoryError>>;\n}\n\nexport interface IUpdateEntryLockRepositoryErrors {\n persistence: LockRecordPersistenceError;\n}\n\ntype RepositoryError = IUpdateEntryLockRepositoryErrors[keyof IUpdateEntryLockRepositoryErrors];\n\nexport const UpdateEntryLockRepository = createAbstraction<IUpdateEntryLockRepository>(\n \"UpdateEntryLockRepository\"\n);\n\nexport namespace UpdateEntryLockRepository {\n export type Interface = IUpdateEntryLockRepository;\n export type Error = RepositoryError;\n}\n"],"names":["UpdateEntryLockUseCase","createAbstraction","UpdateEntryLockRepository"],"mappings":";AAiCO,MAAMA,yBACTC,kBAA2C;AAuBxC,MAAMC,4BAA4BD,kBACrC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { UpdateEntryLockUseCase } from "./UpdateEntryLockUseCase.js";
|
|
3
3
|
import { UpdateEntryLockRepository } from "./UpdateEntryLockRepository.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const UpdateEntryLockFeature = createFeature({
|
|
5
|
+
name: "UpdateEntryLock",
|
|
6
|
+
register (container) {
|
|
7
|
+
container.register(UpdateEntryLockUseCase);
|
|
8
|
+
container.register(UpdateEntryLockRepository).inSingletonScope();
|
|
9
|
+
}
|
|
10
10
|
});
|
|
11
|
+
export { UpdateEntryLockFeature };
|
|
11
12
|
|
|
12
13
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/UpdateEntryLock/feature.js","sources":["../../../src/features/UpdateEntryLock/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { UpdateEntryLockUseCase } from \"./UpdateEntryLockUseCase.js\";\nimport { UpdateEntryLockRepository } from \"./UpdateEntryLockRepository.js\";\n\nexport const UpdateEntryLockFeature = createFeature({\n name: \"UpdateEntryLock\",\n register(container) {\n container.register(UpdateEntryLockUseCase);\n container.register(UpdateEntryLockRepository).inSingletonScope();\n }\n});\n"],"names":["UpdateEntryLockFeature","createFeature","container","UpdateEntryLockUseCase","UpdateEntryLockRepository"],"mappings":";;;AAIO,MAAMA,yBAAyBC,cAAc;IAChD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE,2BAA2B,gBAAgB;IAClE;AACJ"}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
2
2
|
import { NotAuthorizedError } from "@webiny/api-core/features/security/shared";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const identityContext = context.container.resolve(IdentityContext);
|
|
8
|
-
const identity = identityContext.getIdentity();
|
|
9
|
-
if (identity.isAnonymous()) {
|
|
10
|
-
throw new NotAuthorizedError();
|
|
11
|
-
}
|
|
3
|
+
const checkPermissions = async (context)=>{
|
|
4
|
+
const identityContext = context.container.resolve(IdentityContext);
|
|
5
|
+
const identity = identityContext.getIdentity();
|
|
6
|
+
if (identity.isAnonymous()) throw new NotAuthorizedError();
|
|
12
7
|
};
|
|
8
|
+
export { checkPermissions };
|
|
13
9
|
|
|
14
10
|
//# sourceMappingURL=checkPermissions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"graphql/checkPermissions.js","sources":["../../src/graphql/checkPermissions.ts"],"sourcesContent":["import { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\n\n/**\n * Simple permission check. Only authenticated users can access the websockets API via GraphQL\n */\nexport const checkPermissions = async (context: ApiCoreContext): Promise<void> => {\n const identityContext = context.container.resolve(IdentityContext);\n const identity = identityContext.getIdentity();\n\n if (identity.isAnonymous()) {\n throw new NotAuthorizedError();\n }\n};\n"],"names":["checkPermissions","context","identityContext","IdentityContext","identity","NotAuthorizedError"],"mappings":";;AAOO,MAAMA,mBAAmB,OAAOC;IACnC,MAAMC,kBAAkBD,QAAQ,SAAS,CAAC,OAAO,CAACE;IAClD,MAAMC,WAAWF,gBAAgB,WAAW;IAE5C,IAAIE,SAAS,WAAW,IACpB,MAAM,IAAIC;AAElB"}
|
package/graphql/resolve.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { ErrorResponse, ListErrorResponse, ListResponse, Response } from "@webiny/handler-graphql";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
const resolve = async (cb)=>{
|
|
3
|
+
try {
|
|
4
|
+
const result = await cb();
|
|
5
|
+
return new Response(result);
|
|
6
|
+
} catch (ex) {
|
|
7
|
+
return new ErrorResponse(ex);
|
|
8
|
+
}
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} catch (ex) {
|
|
18
|
-
return new ListErrorResponse(ex);
|
|
19
|
-
}
|
|
10
|
+
const resolveList = async (cb)=>{
|
|
11
|
+
try {
|
|
12
|
+
const { items, meta } = await cb();
|
|
13
|
+
return new ListResponse(items, meta);
|
|
14
|
+
} catch (ex) {
|
|
15
|
+
return new ListErrorResponse(ex);
|
|
16
|
+
}
|
|
20
17
|
};
|
|
18
|
+
export { resolve, resolveList };
|
|
21
19
|
|
|
22
20
|
//# sourceMappingURL=resolve.js.map
|
package/graphql/resolve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"graphql/resolve.js","sources":["../../src/graphql/resolve.ts"],"sourcesContent":["import { ErrorResponse, ListErrorResponse, ListResponse, Response } from \"@webiny/handler-graphql\";\nimport type { IRecordLockingMeta } from \"~/types.js\";\n\nexport const resolve = async <T>(cb: () => Promise<T>): Promise<Response<T> | ErrorResponse> => {\n try {\n const result = await cb();\n return new Response<T>(result);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n};\n\nexport interface IListResponse<T> {\n items: T[];\n meta: IRecordLockingMeta;\n}\n\nexport const resolveList = async <T>(\n cb: () => Promise<IListResponse<T>>\n): Promise<Response<T[]> | ErrorResponse> => {\n try {\n const { items, meta } = await cb();\n return new ListResponse(items, meta);\n } catch (ex) {\n return new ListErrorResponse(ex);\n }\n};\n"],"names":["resolve","cb","result","Response","ex","ErrorResponse","resolveList","items","meta","ListResponse","ListErrorResponse"],"mappings":";AAGO,MAAMA,UAAU,OAAUC;IAC7B,IAAI;QACA,MAAMC,SAAS,MAAMD;QACrB,OAAO,IAAIE,SAAYD;IAC3B,EAAE,OAAOE,IAAI;QACT,OAAO,IAAIC,cAAcD;IAC7B;AACJ;AAOO,MAAME,cAAc,OACvBL;IAEA,IAAI;QACA,MAAM,EAAEM,KAAK,EAAEC,IAAI,EAAE,GAAG,MAAMP;QAC9B,OAAO,IAAIQ,aAAaF,OAAOC;IACnC,EAAE,OAAOJ,IAAI;QACT,OAAO,IAAIM,kBAAkBN;IACjC;AACJ"}
|
package/graphql/schema.js
CHANGED
|
@@ -13,35 +13,35 @@ import { LockEntryUseCase } from "../features/LockEntry/abstractions.js";
|
|
|
13
13
|
import { UpdateEntryLockUseCase } from "../features/UpdateEntryLock/abstractions.js";
|
|
14
14
|
import { UnlockEntryUseCase } from "../features/UnlockEntry/abstractions.js";
|
|
15
15
|
import { UnlockEntryRequestUseCase } from "../features/UnlockEntryRequest/abstractions.js";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
${recordLockingFields.map(f
|
|
16
|
+
const createGraphQLSchema = async (params)=>{
|
|
17
|
+
const model = params.model;
|
|
18
|
+
const models = params.models.filter((model)=>model.fields.length > 0);
|
|
19
|
+
const fieldRegistry = params.fieldRegistry;
|
|
20
|
+
const recordLockingFields = renderFields({
|
|
21
|
+
models,
|
|
22
|
+
model,
|
|
23
|
+
fields: model.fields,
|
|
24
|
+
type: "manage",
|
|
25
|
+
fieldRegistry
|
|
26
|
+
});
|
|
27
|
+
const listFilterFieldsRender = renderListFilterFields({
|
|
28
|
+
model,
|
|
29
|
+
fields: model.fields,
|
|
30
|
+
type: "manage",
|
|
31
|
+
fieldRegistry,
|
|
32
|
+
excludeFields: [
|
|
33
|
+
"entryId"
|
|
34
|
+
]
|
|
35
|
+
});
|
|
36
|
+
const sortEnumRender = renderSortEnum({
|
|
37
|
+
model,
|
|
38
|
+
fields: model.fields,
|
|
39
|
+
fieldRegistry,
|
|
40
|
+
sorters: []
|
|
41
|
+
});
|
|
42
|
+
const plugin = createGraphQLSchemaPlugin({
|
|
43
|
+
typeDefs: `
|
|
44
|
+
${recordLockingFields.map((f)=>f.typeDefs).join("\n")}
|
|
45
45
|
|
|
46
46
|
type RecordLockingError {
|
|
47
47
|
message: String
|
|
@@ -76,7 +76,7 @@ export const createGraphQLSchema = async params => {
|
|
|
76
76
|
lockedOn: DateTime!
|
|
77
77
|
updatedOn: DateTime!
|
|
78
78
|
expiresOn: DateTime!
|
|
79
|
-
${recordLockingFields.map(f
|
|
79
|
+
${recordLockingFields.map((f)=>f.fields).join("\n")}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
type RecordLockingIsEntryLockedResponse {
|
|
@@ -173,143 +173,125 @@ export const createGraphQLSchema = async params => {
|
|
|
173
173
|
recordLocking: RecordLockingMutation
|
|
174
174
|
}
|
|
175
175
|
`,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
176
|
+
resolvers: {
|
|
177
|
+
Query: {
|
|
178
|
+
recordLocking: async ()=>({})
|
|
179
|
+
},
|
|
180
|
+
Mutation: {
|
|
181
|
+
recordLocking: async ()=>({})
|
|
182
|
+
},
|
|
183
|
+
RecordLockingQuery: {
|
|
184
|
+
async isEntryLocked (_, args, context) {
|
|
185
|
+
return resolve(async ()=>{
|
|
186
|
+
await checkPermissions(context);
|
|
187
|
+
const useCase = context.container.resolve(IsEntryLockedUseCase);
|
|
188
|
+
const result = await useCase.execute({
|
|
189
|
+
id: args.id,
|
|
190
|
+
type: args.type
|
|
191
|
+
});
|
|
192
|
+
if (result.isFail()) throw result.error;
|
|
193
|
+
return result.value;
|
|
194
|
+
});
|
|
195
|
+
},
|
|
196
|
+
async getLockRecord (_, args, context) {
|
|
197
|
+
return resolve(async ()=>{
|
|
198
|
+
await checkPermissions(context);
|
|
199
|
+
const useCase = context.container.resolve(GetLockRecordUseCase);
|
|
200
|
+
const result = await useCase.execute({
|
|
201
|
+
id: args.id,
|
|
202
|
+
type: args.type
|
|
203
|
+
});
|
|
204
|
+
if (result.isFail()) throw result.error;
|
|
205
|
+
return result.value;
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
async getLockedEntryLockRecord (_, args, context) {
|
|
209
|
+
return resolve(async ()=>{
|
|
210
|
+
await checkPermissions(context);
|
|
211
|
+
const useCase = context.container.resolve(GetLockedEntryLockRecordUseCase);
|
|
212
|
+
const result = await useCase.execute({
|
|
213
|
+
id: args.id,
|
|
214
|
+
type: args.type
|
|
215
|
+
});
|
|
216
|
+
if (result.isFail()) return null;
|
|
217
|
+
return result.value;
|
|
218
|
+
});
|
|
219
|
+
},
|
|
220
|
+
async listLockRecords (_, args, context) {
|
|
221
|
+
return resolveList(async ()=>{
|
|
222
|
+
await checkPermissions(context);
|
|
223
|
+
const useCase = context.container.resolve(ListLockRecordsUseCase);
|
|
224
|
+
const result = await useCase.execute(args);
|
|
225
|
+
if (result.isFail()) throw result.error;
|
|
226
|
+
return result.value;
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
listAllLockRecords (_, args, context) {
|
|
230
|
+
return resolveList(async ()=>{
|
|
231
|
+
await checkPermissions(context);
|
|
232
|
+
const useCase = context.container.resolve(ListAllLockRecordsUseCase);
|
|
233
|
+
const result = await useCase.execute(args);
|
|
234
|
+
if (result.isFail()) throw result.error;
|
|
235
|
+
return result.value;
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
RecordLockingMutation: {
|
|
240
|
+
async lockEntry (_, args, context) {
|
|
241
|
+
return resolve(async ()=>{
|
|
242
|
+
await checkPermissions(context);
|
|
243
|
+
const useCase = context.container.resolve(LockEntryUseCase);
|
|
244
|
+
const result = await useCase.execute({
|
|
245
|
+
id: args.id,
|
|
246
|
+
type: args.type
|
|
247
|
+
});
|
|
248
|
+
if (result.isFail()) throw result.error;
|
|
249
|
+
return result.value;
|
|
250
|
+
});
|
|
251
|
+
},
|
|
252
|
+
async updateEntryLock (_, args, context) {
|
|
253
|
+
return resolve(async ()=>{
|
|
254
|
+
await checkPermissions(context);
|
|
255
|
+
const useCase = context.container.resolve(UpdateEntryLockUseCase);
|
|
256
|
+
const result = await useCase.execute({
|
|
257
|
+
id: args.id,
|
|
258
|
+
type: args.type
|
|
259
|
+
});
|
|
260
|
+
if (result.isFail()) throw result.error;
|
|
261
|
+
return result.value;
|
|
262
|
+
});
|
|
263
|
+
},
|
|
264
|
+
async unlockEntry (_, args, context) {
|
|
265
|
+
return resolve(async ()=>{
|
|
266
|
+
await checkPermissions(context);
|
|
267
|
+
const useCase = context.container.resolve(UnlockEntryUseCase);
|
|
268
|
+
const result = await useCase.execute({
|
|
269
|
+
id: args.id,
|
|
270
|
+
type: args.type,
|
|
271
|
+
force: args.force
|
|
272
|
+
});
|
|
273
|
+
if (result.isFail()) throw result.error;
|
|
274
|
+
return result.value;
|
|
275
|
+
});
|
|
276
|
+
},
|
|
277
|
+
async unlockEntryRequest (_, args, context) {
|
|
278
|
+
return resolve(async ()=>{
|
|
279
|
+
await checkPermissions(context);
|
|
280
|
+
const useCase = context.container.resolve(UnlockEntryRequestUseCase);
|
|
281
|
+
const result = await useCase.execute({
|
|
282
|
+
id: args.id,
|
|
283
|
+
type: args.type
|
|
284
|
+
});
|
|
285
|
+
if (result.isFail()) throw result.error;
|
|
286
|
+
return result.value;
|
|
287
|
+
});
|
|
288
|
+
}
|
|
194
289
|
}
|
|
195
|
-
return result.value;
|
|
196
|
-
});
|
|
197
|
-
},
|
|
198
|
-
async getLockRecord(_, args, context) {
|
|
199
|
-
return resolve(async () => {
|
|
200
|
-
await checkPermissions(context);
|
|
201
|
-
const useCase = context.container.resolve(GetLockRecordUseCase);
|
|
202
|
-
const result = await useCase.execute({
|
|
203
|
-
id: args.id,
|
|
204
|
-
type: args.type
|
|
205
|
-
});
|
|
206
|
-
if (result.isFail()) {
|
|
207
|
-
throw result.error;
|
|
208
|
-
}
|
|
209
|
-
return result.value;
|
|
210
|
-
});
|
|
211
|
-
},
|
|
212
|
-
async getLockedEntryLockRecord(_, args, context) {
|
|
213
|
-
return resolve(async () => {
|
|
214
|
-
await checkPermissions(context);
|
|
215
|
-
const useCase = context.container.resolve(GetLockedEntryLockRecordUseCase);
|
|
216
|
-
const result = await useCase.execute({
|
|
217
|
-
id: args.id,
|
|
218
|
-
type: args.type
|
|
219
|
-
});
|
|
220
|
-
// Returns null if not found/expired/locked by current user
|
|
221
|
-
if (result.isFail()) {
|
|
222
|
-
return null;
|
|
223
|
-
}
|
|
224
|
-
return result.value;
|
|
225
|
-
});
|
|
226
|
-
},
|
|
227
|
-
async listLockRecords(_, args, context) {
|
|
228
|
-
return resolveList(async () => {
|
|
229
|
-
await checkPermissions(context);
|
|
230
|
-
const useCase = context.container.resolve(ListLockRecordsUseCase);
|
|
231
|
-
const result = await useCase.execute(args);
|
|
232
|
-
if (result.isFail()) {
|
|
233
|
-
throw result.error;
|
|
234
|
-
}
|
|
235
|
-
return result.value;
|
|
236
|
-
});
|
|
237
|
-
},
|
|
238
|
-
listAllLockRecords(_, args, context) {
|
|
239
|
-
return resolveList(async () => {
|
|
240
|
-
await checkPermissions(context);
|
|
241
|
-
const useCase = context.container.resolve(ListAllLockRecordsUseCase);
|
|
242
|
-
const result = await useCase.execute(args);
|
|
243
|
-
if (result.isFail()) {
|
|
244
|
-
throw result.error;
|
|
245
|
-
}
|
|
246
|
-
return result.value;
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
RecordLockingMutation: {
|
|
251
|
-
async lockEntry(_, args, context) {
|
|
252
|
-
return resolve(async () => {
|
|
253
|
-
await checkPermissions(context);
|
|
254
|
-
const useCase = context.container.resolve(LockEntryUseCase);
|
|
255
|
-
const result = await useCase.execute({
|
|
256
|
-
id: args.id,
|
|
257
|
-
type: args.type
|
|
258
|
-
});
|
|
259
|
-
if (result.isFail()) {
|
|
260
|
-
throw result.error;
|
|
261
|
-
}
|
|
262
|
-
return result.value;
|
|
263
|
-
});
|
|
264
|
-
},
|
|
265
|
-
async updateEntryLock(_, args, context) {
|
|
266
|
-
return resolve(async () => {
|
|
267
|
-
await checkPermissions(context);
|
|
268
|
-
const useCase = context.container.resolve(UpdateEntryLockUseCase);
|
|
269
|
-
const result = await useCase.execute({
|
|
270
|
-
id: args.id,
|
|
271
|
-
type: args.type
|
|
272
|
-
});
|
|
273
|
-
if (result.isFail()) {
|
|
274
|
-
throw result.error;
|
|
275
|
-
}
|
|
276
|
-
return result.value;
|
|
277
|
-
});
|
|
278
|
-
},
|
|
279
|
-
async unlockEntry(_, args, context) {
|
|
280
|
-
return resolve(async () => {
|
|
281
|
-
await checkPermissions(context);
|
|
282
|
-
const useCase = context.container.resolve(UnlockEntryUseCase);
|
|
283
|
-
const result = await useCase.execute({
|
|
284
|
-
id: args.id,
|
|
285
|
-
type: args.type,
|
|
286
|
-
force: args.force
|
|
287
|
-
});
|
|
288
|
-
if (result.isFail()) {
|
|
289
|
-
throw result.error;
|
|
290
|
-
}
|
|
291
|
-
return result.value;
|
|
292
|
-
});
|
|
293
|
-
},
|
|
294
|
-
async unlockEntryRequest(_, args, context) {
|
|
295
|
-
return resolve(async () => {
|
|
296
|
-
await checkPermissions(context);
|
|
297
|
-
const useCase = context.container.resolve(UnlockEntryRequestUseCase);
|
|
298
|
-
const result = await useCase.execute({
|
|
299
|
-
id: args.id,
|
|
300
|
-
type: args.type
|
|
301
|
-
});
|
|
302
|
-
if (result.isFail()) {
|
|
303
|
-
throw result.error;
|
|
304
|
-
}
|
|
305
|
-
return result.value;
|
|
306
|
-
});
|
|
307
290
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
plugin.name = "recordLocking.graphql.schema.locking";
|
|
312
|
-
return plugin;
|
|
291
|
+
});
|
|
292
|
+
plugin.name = "recordLocking.graphql.schema.locking";
|
|
293
|
+
return plugin;
|
|
313
294
|
};
|
|
295
|
+
export { createGraphQLSchema };
|
|
314
296
|
|
|
315
297
|
//# sourceMappingURL=schema.js.map
|