@webiny/api-record-locking 5.40.0-beta.3

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.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -0
  3. package/abstractions/IGetLockRecordUseCase.d.ts +8 -0
  4. package/abstractions/IGetLockRecordUseCase.js +7 -0
  5. package/abstractions/IGetLockRecordUseCase.js.map +1 -0
  6. package/abstractions/IGetLockedEntryLockRecordUseCase.d.ts +8 -0
  7. package/abstractions/IGetLockedEntryLockRecordUseCase.js +7 -0
  8. package/abstractions/IGetLockedEntryLockRecordUseCase.js.map +1 -0
  9. package/abstractions/IIsEntryLocked.d.ts +8 -0
  10. package/abstractions/IIsEntryLocked.js +7 -0
  11. package/abstractions/IIsEntryLocked.js.map +1 -0
  12. package/abstractions/IKickOutCurrentUserUseCase.d.ts +5 -0
  13. package/abstractions/IKickOutCurrentUserUseCase.js +7 -0
  14. package/abstractions/IKickOutCurrentUserUseCase.js.map +1 -0
  15. package/abstractions/IListAllLockRecordsUseCase.d.ts +9 -0
  16. package/abstractions/IListAllLockRecordsUseCase.js +7 -0
  17. package/abstractions/IListAllLockRecordsUseCase.js.map +1 -0
  18. package/abstractions/IListLockRecordsUseCase.d.ts +10 -0
  19. package/abstractions/IListLockRecordsUseCase.js +7 -0
  20. package/abstractions/IListLockRecordsUseCase.js.map +1 -0
  21. package/abstractions/ILockEntryUseCase.d.ts +11 -0
  22. package/abstractions/ILockEntryUseCase.js +7 -0
  23. package/abstractions/ILockEntryUseCase.js.map +1 -0
  24. package/abstractions/IUnlockEntryRequestUseCase.d.ts +11 -0
  25. package/abstractions/IUnlockEntryRequestUseCase.js +7 -0
  26. package/abstractions/IUnlockEntryRequestUseCase.js.map +1 -0
  27. package/abstractions/IUnlockEntryUseCase.d.ts +12 -0
  28. package/abstractions/IUnlockEntryUseCase.js +7 -0
  29. package/abstractions/IUnlockEntryUseCase.js.map +1 -0
  30. package/abstractions/IUpdateEntryLockUseCase.d.ts +11 -0
  31. package/abstractions/IUpdateEntryLockUseCase.js +7 -0
  32. package/abstractions/IUpdateEntryLockUseCase.js.map +1 -0
  33. package/crud/crud.d.ts +6 -0
  34. package/crud/crud.js +188 -0
  35. package/crud/crud.js.map +1 -0
  36. package/crud/model.d.ts +2 -0
  37. package/crud/model.js +127 -0
  38. package/crud/model.js.map +1 -0
  39. package/graphql/schema.d.ts +7 -0
  40. package/graphql/schema.js +280 -0
  41. package/graphql/schema.js.map +1 -0
  42. package/index.d.ts +3 -0
  43. package/index.js +38 -0
  44. package/index.js.map +1 -0
  45. package/package.json +64 -0
  46. package/types.d.ts +172 -0
  47. package/types.js +30 -0
  48. package/types.js.map +1 -0
  49. package/useCases/GetLockRecord/GetLockRecordUseCase.d.ts +10 -0
  50. package/useCases/GetLockRecord/GetLockRecordUseCase.js +35 -0
  51. package/useCases/GetLockRecord/GetLockRecordUseCase.js.map +1 -0
  52. package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.d.ts +16 -0
  53. package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js +27 -0
  54. package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js.map +1 -0
  55. package/useCases/IsEntryLocked/IsEntryLockedUseCase.d.ts +16 -0
  56. package/useCases/IsEntryLocked/IsEntryLockedUseCase.js +35 -0
  57. package/useCases/IsEntryLocked/IsEntryLockedUseCase.js.map +1 -0
  58. package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.d.ts +12 -0
  59. package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.js +46 -0
  60. package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.js.map +1 -0
  61. package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.d.ts +10 -0
  62. package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.js +32 -0
  63. package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.js.map +1 -0
  64. package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.d.ts +14 -0
  65. package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.js +27 -0
  66. package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.js.map +1 -0
  67. package/useCases/LockEntryUseCase/LockEntryUseCase.d.ts +13 -0
  68. package/useCases/LockEntryUseCase/LockEntryUseCase.js +51 -0
  69. package/useCases/LockEntryUseCase/LockEntryUseCase.js.map +1 -0
  70. package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.d.ts +20 -0
  71. package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.js +67 -0
  72. package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.js.map +1 -0
  73. package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.d.ts +15 -0
  74. package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.js +78 -0
  75. package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.js.map +1 -0
  76. package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.d.ts +18 -0
  77. package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.js +48 -0
  78. package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.js.map +1 -0
  79. package/useCases/index.d.ts +28 -0
  80. package/useCases/index.js +83 -0
  81. package/useCases/index.js.map +1 -0
  82. package/utils/calculateExpiresOn.d.ts +2 -0
  83. package/utils/calculateExpiresOn.js +15 -0
  84. package/utils/calculateExpiresOn.js.map +1 -0
  85. package/utils/checkPermissions.d.ts +7 -0
  86. package/utils/checkPermissions.js +21 -0
  87. package/utils/checkPermissions.js.map +1 -0
  88. package/utils/convertEntryToLockRecord.d.ts +28 -0
  89. package/utils/convertEntryToLockRecord.js +88 -0
  90. package/utils/convertEntryToLockRecord.js.map +1 -0
  91. package/utils/convertWhereCondition.d.ts +4 -0
  92. package/utils/convertWhereCondition.js +41 -0
  93. package/utils/convertWhereCondition.js.map +1 -0
  94. package/utils/getTimeout.d.ts +4 -0
  95. package/utils/getTimeout.js +20 -0
  96. package/utils/getTimeout.js.map +1 -0
  97. package/utils/isLockedFactory.d.ts +5 -0
  98. package/utils/isLockedFactory.js +20 -0
  99. package/utils/isLockedFactory.js.map +1 -0
  100. package/utils/lockRecordDatabaseId.d.ts +2 -0
  101. package/utils/lockRecordDatabaseId.js +24 -0
  102. package/utils/lockRecordDatabaseId.js.map +1 -0
  103. package/utils/resolve.d.ts +8 -0
  104. package/utils/resolve.js +30 -0
  105. package/utils/resolve.js.map +1 -0
  106. package/utils/validateSameIdentity.d.ts +6 -0
  107. package/utils/validateSameIdentity.js +24 -0
  108. package/utils/validateSameIdentity.js.map +1 -0
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_types","require","IRecordLockingLockRecordActionType","exports"],"sources":["types.ts"],"sourcesContent":["import {\n CmsContext,\n CmsEntry,\n CmsEntryListParams,\n CmsEntryMeta,\n CmsError,\n CmsIdentity,\n CmsModel,\n CmsModelManager\n} from \"@webiny/api-headless-cms/types\";\nimport { Topic } from \"@webiny/pubsub/types\";\nimport {\n Context as IWebsocketsContext,\n IWebsocketsContextObject\n} from \"@webiny/api-websockets/types\";\n\nexport { CmsError, CmsEntry };\n\nexport type IRecordLockingIdentity = CmsIdentity;\n\nexport type IRecordLockingModelManager = CmsModelManager<IRecordLockingLockRecordValues>;\n\nexport type IRecordLockingMeta = CmsEntryMeta;\n\nexport interface IHasFullAccessCallable {\n (): Promise<boolean>;\n}\n\nexport interface IGetWebsocketsContextCallable {\n (): IWebsocketsContextObject;\n}\n\nexport interface IGetIdentity {\n (): IRecordLockingIdentity;\n}\n\nexport interface IRecordLockingLockRecordValues {\n targetId: string;\n type: IRecordLockingLockRecordEntryType;\n actions?: IRecordLockingLockRecordAction[];\n}\nexport enum IRecordLockingLockRecordActionType {\n requested = \"requested\",\n approved = \"approved\",\n denied = \"denied\"\n}\n\nexport interface IRecordLockingLockRecordRequestedAction {\n type: IRecordLockingLockRecordActionType.requested;\n message?: string;\n createdOn: Date;\n createdBy: IRecordLockingIdentity;\n}\n\nexport interface IRecordLockingLockRecordApprovedAction {\n type: IRecordLockingLockRecordActionType.approved;\n message?: string;\n createdOn: Date;\n createdBy: IRecordLockingIdentity;\n}\n\nexport interface IRecordLockingLockRecordDeniedAction {\n type: IRecordLockingLockRecordActionType.denied;\n message?: string;\n createdOn: Date;\n createdBy: IRecordLockingIdentity;\n}\n\nexport type IRecordLockingLockRecordAction =\n | IRecordLockingLockRecordRequestedAction\n | IRecordLockingLockRecordApprovedAction\n | IRecordLockingLockRecordDeniedAction;\n\nexport interface IRecordLockingLockRecordObject {\n id: string;\n targetId: string;\n type: IRecordLockingLockRecordEntryType;\n lockedBy: IRecordLockingIdentity;\n lockedOn: Date;\n updatedOn: Date;\n expiresOn: Date;\n actions?: IRecordLockingLockRecordAction[];\n}\n\nexport interface IRecordLockingLockRecord extends IRecordLockingLockRecordObject {\n toObject(): IRecordLockingLockRecordObject;\n addAction(action: IRecordLockingLockRecordAction): void;\n getUnlockRequested(): IRecordLockingLockRecordRequestedAction | undefined;\n getUnlockApproved(): IRecordLockingLockRecordApprovedAction | undefined;\n getUnlockDenied(): IRecordLockingLockRecordDeniedAction | undefined;\n}\n\n/**\n * Do not use any special chars other than #, as we use this to create lock record IDs.\n */\nexport type IRecordLockingLockRecordEntryType = string;\n\nexport type IRecordLockingListAllLockRecordsParams = Pick<\n CmsEntryListParams,\n \"where\" | \"limit\" | \"sort\" | \"after\"\n>;\n\nexport type IRecordLockingListLockRecordsParams = IRecordLockingListAllLockRecordsParams;\n\nexport interface IRecordLockingListAllLockRecordsResponse {\n items: IRecordLockingLockRecord[];\n meta: IRecordLockingMeta;\n}\n\nexport type IRecordLockingListLockRecordsResponse = IRecordLockingListAllLockRecordsResponse;\n\nexport interface IRecordLockingGetLockRecordParams {\n id: string;\n type: IRecordLockingLockRecordEntryType;\n}\n\nexport interface IRecordLockingIsLockedParams {\n id: string;\n type: IRecordLockingLockRecordEntryType;\n}\n\nexport interface IRecordLockingGetLockedEntryLockRecordParams {\n id: string;\n type: IRecordLockingLockRecordEntryType;\n}\n\nexport interface IRecordLockingLockEntryParams {\n id: string;\n type: IRecordLockingLockRecordEntryType;\n}\n\nexport interface IRecordLockingUpdateEntryLockParams {\n id: string;\n type: IRecordLockingLockRecordEntryType;\n}\n\nexport interface IRecordLockingUnlockEntryParams {\n id: string;\n type: IRecordLockingLockRecordEntryType;\n force?: boolean;\n}\n\nexport interface IRecordLockingUnlockEntryRequestParams {\n id: string;\n type: IRecordLockingLockRecordEntryType;\n}\n\nexport interface OnEntryBeforeLockTopicParams {\n id: string;\n type: IRecordLockingLockRecordEntryType;\n}\n\nexport interface OnEntryAfterLockTopicParams {\n id: string;\n type: IRecordLockingLockRecordEntryType;\n record: IRecordLockingLockRecord;\n}\n\nexport interface OnEntryLockErrorTopicParams {\n id: string;\n type: IRecordLockingLockRecordEntryType;\n error: CmsError;\n}\n\nexport interface OnEntryBeforeUnlockTopicParams {\n id: string;\n type: IRecordLockingLockRecordEntryType;\n getIdentity: IGetIdentity;\n}\n\nexport interface OnEntryAfterUnlockTopicParams {\n id: string;\n type: IRecordLockingLockRecordEntryType;\n record: IRecordLockingLockRecord;\n}\n\nexport interface OnEntryUnlockErrorTopicParams {\n id: string;\n type: IRecordLockingLockRecordEntryType;\n error: CmsError;\n}\n\nexport interface OnEntryBeforeUnlockRequestTopicParams {\n id: string;\n type: IRecordLockingLockRecordEntryType;\n}\n\nexport interface OnEntryAfterUnlockRequestTopicParams {\n id: string;\n type: IRecordLockingLockRecordEntryType;\n record: IRecordLockingLockRecord;\n}\n\nexport interface OnEntryUnlockRequestErrorTopicParams {\n id: string;\n type: IRecordLockingLockRecordEntryType;\n error: CmsError;\n}\n\nexport interface IRecordLocking {\n onEntryBeforeLock: Topic<OnEntryBeforeLockTopicParams>;\n onEntryAfterLock: Topic<OnEntryAfterLockTopicParams>;\n onEntryLockError: Topic<OnEntryLockErrorTopicParams>;\n onEntryBeforeUnlock: Topic<OnEntryBeforeUnlockTopicParams>;\n onEntryAfterUnlock: Topic<OnEntryAfterUnlockTopicParams>;\n onEntryUnlockError: Topic<OnEntryUnlockErrorTopicParams>;\n onEntryBeforeUnlockRequest: Topic<OnEntryBeforeUnlockRequestTopicParams>;\n onEntryAfterUnlockRequest: Topic<OnEntryAfterUnlockRequestTopicParams>;\n onEntryUnlockRequestError: Topic<OnEntryUnlockRequestErrorTopicParams>;\n getModel(): Promise<CmsModel>;\n listAllLockRecords(\n params?: IRecordLockingListAllLockRecordsParams\n ): Promise<IRecordLockingListAllLockRecordsResponse>;\n /**\n * Same call as listAllLockRecords, except this one will filter out records with expired lock.\n */\n listLockRecords(\n params?: IRecordLockingListLockRecordsParams\n ): Promise<IRecordLockingListLockRecordsResponse>;\n getLockRecord(\n params: IRecordLockingGetLockRecordParams\n ): Promise<IRecordLockingLockRecord | null>;\n isEntryLocked(params: IRecordLockingIsLockedParams): Promise<boolean>;\n getLockedEntryLockRecord(\n params: IRecordLockingGetLockedEntryLockRecordParams\n ): Promise<IRecordLockingLockRecord | null>;\n lockEntry(params: IRecordLockingLockEntryParams): Promise<IRecordLockingLockRecord>;\n updateEntryLock(params: IRecordLockingUpdateEntryLockParams): Promise<IRecordLockingLockRecord>;\n unlockEntry(params: IRecordLockingUnlockEntryParams): Promise<IRecordLockingLockRecord>;\n unlockEntryRequest(\n params: IRecordLockingUnlockEntryRequestParams\n ): Promise<IRecordLockingLockRecord>;\n}\n\nexport interface Context extends CmsContext, IWebsocketsContext {\n recordLocking: IRecordLocking;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AASwC,IAgC5BC,kCAAkC,GAAAC,OAAA,CAAAD,kCAAA,0BAAlCA,kCAAkC;EAAlCA,kCAAkC;EAAlCA,kCAAkC;EAAlCA,kCAAkC;EAAA,OAAlCA,kCAAkC;AAAA;AAmD9C;AACA;AACA","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ import { IGetLockRecordUseCase, IGetLockRecordUseCaseExecuteParams } from "../../abstractions/IGetLockRecordUseCase";
2
+ import { IRecordLockingModelManager, IRecordLockingLockRecord } from "../../types";
3
+ export interface IGetLockRecordUseCaseParams {
4
+ getManager(): Promise<IRecordLockingModelManager>;
5
+ }
6
+ export declare class GetLockRecordUseCase implements IGetLockRecordUseCase {
7
+ private readonly getManager;
8
+ constructor(params: IGetLockRecordUseCaseParams);
9
+ execute(input: IGetLockRecordUseCaseExecuteParams): Promise<IRecordLockingLockRecord | null>;
10
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.GetLockRecordUseCase = void 0;
7
+ var _handlerGraphql = require("@webiny/handler-graphql");
8
+ var _convertEntryToLockRecord = require("../../utils/convertEntryToLockRecord");
9
+ var _lockRecordDatabaseId = require("../../utils/lockRecordDatabaseId");
10
+ var _utils = require("@webiny/utils");
11
+ class GetLockRecordUseCase {
12
+ constructor(params) {
13
+ this.getManager = params.getManager;
14
+ }
15
+ async execute(input) {
16
+ const recordId = (0, _lockRecordDatabaseId.createLockRecordDatabaseId)(input.id);
17
+ const id = (0, _utils.createIdentifier)({
18
+ id: recordId,
19
+ version: 1
20
+ });
21
+ try {
22
+ const manager = await this.getManager();
23
+ const result = await manager.get(id);
24
+ return (0, _convertEntryToLockRecord.convertEntryToLockRecord)(result);
25
+ } catch (ex) {
26
+ if (ex instanceof _handlerGraphql.NotFoundError) {
27
+ return null;
28
+ }
29
+ throw ex;
30
+ }
31
+ }
32
+ }
33
+ exports.GetLockRecordUseCase = GetLockRecordUseCase;
34
+
35
+ //# sourceMappingURL=GetLockRecordUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_handlerGraphql","require","_convertEntryToLockRecord","_lockRecordDatabaseId","_utils","GetLockRecordUseCase","constructor","params","getManager","execute","input","recordId","createLockRecordDatabaseId","id","createIdentifier","version","manager","result","get","convertEntryToLockRecord","ex","NotFoundError","exports"],"sources":["GetLockRecordUseCase.ts"],"sourcesContent":["import {\n IGetLockRecordUseCase,\n IGetLockRecordUseCaseExecuteParams\n} from \"~/abstractions/IGetLockRecordUseCase\";\nimport { IRecordLockingModelManager, IRecordLockingLockRecord } from \"~/types\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { convertEntryToLockRecord } from \"~/utils/convertEntryToLockRecord\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId\";\nimport { createIdentifier } from \"@webiny/utils\";\n\nexport interface IGetLockRecordUseCaseParams {\n getManager(): Promise<IRecordLockingModelManager>;\n}\n\nexport class GetLockRecordUseCase implements IGetLockRecordUseCase {\n private readonly getManager: IGetLockRecordUseCaseParams[\"getManager\"];\n\n public constructor(params: IGetLockRecordUseCaseParams) {\n this.getManager = params.getManager;\n }\n\n public async execute(\n input: IGetLockRecordUseCaseExecuteParams\n ): Promise<IRecordLockingLockRecord | null> {\n const recordId = createLockRecordDatabaseId(input.id);\n const id = createIdentifier({\n id: recordId,\n version: 1\n });\n try {\n const manager = await this.getManager();\n const result = await manager.get(id);\n return convertEntryToLockRecord(result);\n } catch (ex) {\n if (ex instanceof NotFoundError) {\n return null;\n }\n throw ex;\n }\n }\n}\n"],"mappings":";;;;;;AAKA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,yBAAA,GAAAD,OAAA;AACA,IAAAE,qBAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAMO,MAAMI,oBAAoB,CAAkC;EAGxDC,WAAWA,CAACC,MAAmC,EAAE;IACpD,IAAI,CAACC,UAAU,GAAGD,MAAM,CAACC,UAAU;EACvC;EAEA,MAAaC,OAAOA,CAChBC,KAAyC,EACD;IACxC,MAAMC,QAAQ,GAAG,IAAAC,gDAA0B,EAACF,KAAK,CAACG,EAAE,CAAC;IACrD,MAAMA,EAAE,GAAG,IAAAC,uBAAgB,EAAC;MACxBD,EAAE,EAAEF,QAAQ;MACZI,OAAO,EAAE;IACb,CAAC,CAAC;IACF,IAAI;MACA,MAAMC,OAAO,GAAG,MAAM,IAAI,CAACR,UAAU,CAAC,CAAC;MACvC,MAAMS,MAAM,GAAG,MAAMD,OAAO,CAACE,GAAG,CAACL,EAAE,CAAC;MACpC,OAAO,IAAAM,kDAAwB,EAACF,MAAM,CAAC;IAC3C,CAAC,CAAC,OAAOG,EAAE,EAAE;MACT,IAAIA,EAAE,YAAYC,6BAAa,EAAE;QAC7B,OAAO,IAAI;MACf;MACA,MAAMD,EAAE;IACZ;EACJ;AACJ;AAACE,OAAA,CAAAjB,oBAAA,GAAAA,oBAAA","ignoreList":[]}
@@ -0,0 +1,16 @@
1
+ import { IGetLockRecordUseCase } from "../../abstractions/IGetLockRecordUseCase";
2
+ import { IGetIdentity, IRecordLockingLockRecord } from "../../types";
3
+ import { IGetLockedEntryLockRecordUseCase, IGetLockedEntryLockRecordUseCaseExecuteParams } from "../../abstractions/IGetLockedEntryLockRecordUseCase";
4
+ import { IIsLocked } from "../../utils/isLockedFactory";
5
+ export interface IGetLockedEntryLockRecordUseCaseParams {
6
+ getLockRecordUseCase: IGetLockRecordUseCase;
7
+ isLocked: IIsLocked;
8
+ getIdentity: IGetIdentity;
9
+ }
10
+ export declare class GetLockedEntryLockRecordUseCase implements IGetLockedEntryLockRecordUseCase {
11
+ private readonly getLockRecordUseCase;
12
+ private readonly isLocked;
13
+ private readonly getIdentity;
14
+ constructor(params: IGetLockedEntryLockRecordUseCaseParams);
15
+ execute(params: IGetLockedEntryLockRecordUseCaseExecuteParams): Promise<IRecordLockingLockRecord | null>;
16
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.GetLockedEntryLockRecordUseCase = void 0;
7
+ class GetLockedEntryLockRecordUseCase {
8
+ constructor(params) {
9
+ this.getLockRecordUseCase = params.getLockRecordUseCase;
10
+ this.isLocked = params.isLocked;
11
+ this.getIdentity = params.getIdentity;
12
+ }
13
+ async execute(params) {
14
+ const result = await this.getLockRecordUseCase.execute(params);
15
+ if (!result?.lockedBy) {
16
+ return null;
17
+ }
18
+ const identity = this.getIdentity();
19
+ if (identity.id === result.lockedBy.id) {
20
+ return null;
21
+ }
22
+ return this.isLocked(result) ? result : null;
23
+ }
24
+ }
25
+ exports.GetLockedEntryLockRecordUseCase = GetLockedEntryLockRecordUseCase;
26
+
27
+ //# sourceMappingURL=GetLockedEntryLockRecordUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["GetLockedEntryLockRecordUseCase","constructor","params","getLockRecordUseCase","isLocked","getIdentity","execute","result","lockedBy","identity","id","exports"],"sources":["GetLockedEntryLockRecordUseCase.ts"],"sourcesContent":["import { IGetLockRecordUseCase } from \"~/abstractions/IGetLockRecordUseCase\";\nimport { IGetIdentity, IRecordLockingLockRecord } from \"~/types\";\nimport {\n IGetLockedEntryLockRecordUseCase,\n IGetLockedEntryLockRecordUseCaseExecuteParams\n} from \"~/abstractions/IGetLockedEntryLockRecordUseCase\";\nimport { IIsLocked } from \"~/utils/isLockedFactory\";\n\nexport interface IGetLockedEntryLockRecordUseCaseParams {\n getLockRecordUseCase: IGetLockRecordUseCase;\n isLocked: IIsLocked;\n getIdentity: IGetIdentity;\n}\n\nexport class GetLockedEntryLockRecordUseCase implements IGetLockedEntryLockRecordUseCase {\n private readonly getLockRecordUseCase: IGetLockRecordUseCase;\n private readonly isLocked: IIsLocked;\n private readonly getIdentity: IGetIdentity;\n\n public constructor(params: IGetLockedEntryLockRecordUseCaseParams) {\n this.getLockRecordUseCase = params.getLockRecordUseCase;\n this.isLocked = params.isLocked;\n this.getIdentity = params.getIdentity;\n }\n\n public async execute(\n params: IGetLockedEntryLockRecordUseCaseExecuteParams\n ): Promise<IRecordLockingLockRecord | null> {\n const result = await this.getLockRecordUseCase.execute(params);\n if (!result?.lockedBy) {\n return null;\n }\n const identity = this.getIdentity();\n if (identity.id === result.lockedBy.id) {\n return null;\n }\n return this.isLocked(result) ? result : null;\n }\n}\n"],"mappings":";;;;;;AAcO,MAAMA,+BAA+B,CAA6C;EAK9EC,WAAWA,CAACC,MAA8C,EAAE;IAC/D,IAAI,CAACC,oBAAoB,GAAGD,MAAM,CAACC,oBAAoB;IACvD,IAAI,CAACC,QAAQ,GAAGF,MAAM,CAACE,QAAQ;IAC/B,IAAI,CAACC,WAAW,GAAGH,MAAM,CAACG,WAAW;EACzC;EAEA,MAAaC,OAAOA,CAChBJ,MAAqD,EACb;IACxC,MAAMK,MAAM,GAAG,MAAM,IAAI,CAACJ,oBAAoB,CAACG,OAAO,CAACJ,MAAM,CAAC;IAC9D,IAAI,CAACK,MAAM,EAAEC,QAAQ,EAAE;MACnB,OAAO,IAAI;IACf;IACA,MAAMC,QAAQ,GAAG,IAAI,CAACJ,WAAW,CAAC,CAAC;IACnC,IAAII,QAAQ,CAACC,EAAE,KAAKH,MAAM,CAACC,QAAQ,CAACE,EAAE,EAAE;MACpC,OAAO,IAAI;IACf;IACA,OAAO,IAAI,CAACN,QAAQ,CAACG,MAAM,CAAC,GAAGA,MAAM,GAAG,IAAI;EAChD;AACJ;AAACI,OAAA,CAAAX,+BAAA,GAAAA,+BAAA","ignoreList":[]}
@@ -0,0 +1,16 @@
1
+ import { IIsEntryLockedUseCase, IIsEntryLockedUseCaseExecuteParams } from "../../abstractions/IIsEntryLocked";
2
+ import { IGetLockRecordUseCase } from "../../abstractions/IGetLockRecordUseCase";
3
+ import { IIsLocked } from "../../utils/isLockedFactory";
4
+ import { IGetIdentity } from "../../types";
5
+ export interface IIsEntryLockedParams {
6
+ getLockRecordUseCase: IGetLockRecordUseCase;
7
+ isLocked: IIsLocked;
8
+ getIdentity: IGetIdentity;
9
+ }
10
+ export declare class IsEntryLockedUseCase implements IIsEntryLockedUseCase {
11
+ private readonly getLockRecordUseCase;
12
+ private readonly isLocked;
13
+ private readonly getIdentity;
14
+ constructor(params: IIsEntryLockedParams);
15
+ execute(params: IIsEntryLockedUseCaseExecuteParams): Promise<boolean>;
16
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.IsEntryLockedUseCase = void 0;
7
+ var _handlerGraphql = require("@webiny/handler-graphql");
8
+ class IsEntryLockedUseCase {
9
+ constructor(params) {
10
+ this.getLockRecordUseCase = params.getLockRecordUseCase;
11
+ this.isLocked = params.isLocked;
12
+ this.getIdentity = params.getIdentity;
13
+ }
14
+ async execute(params) {
15
+ try {
16
+ const result = await this.getLockRecordUseCase.execute(params);
17
+ if (!result) {
18
+ return false;
19
+ }
20
+ const identity = this.getIdentity();
21
+ if (result.lockedBy.id === identity.id) {
22
+ return false;
23
+ }
24
+ return this.isLocked(result);
25
+ } catch (ex) {
26
+ if (ex instanceof _handlerGraphql.NotFoundError === false) {
27
+ throw ex;
28
+ }
29
+ return false;
30
+ }
31
+ }
32
+ }
33
+ exports.IsEntryLockedUseCase = IsEntryLockedUseCase;
34
+
35
+ //# sourceMappingURL=IsEntryLockedUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_handlerGraphql","require","IsEntryLockedUseCase","constructor","params","getLockRecordUseCase","isLocked","getIdentity","execute","result","identity","lockedBy","id","ex","NotFoundError","exports"],"sources":["IsEntryLockedUseCase.ts"],"sourcesContent":["import {\n IIsEntryLockedUseCase,\n IIsEntryLockedUseCaseExecuteParams\n} from \"~/abstractions/IIsEntryLocked\";\nimport { IGetLockRecordUseCase } from \"~/abstractions/IGetLockRecordUseCase\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { IIsLocked } from \"~/utils/isLockedFactory\";\nimport { IGetIdentity } from \"~/types\";\n\nexport interface IIsEntryLockedParams {\n getLockRecordUseCase: IGetLockRecordUseCase;\n isLocked: IIsLocked;\n getIdentity: IGetIdentity;\n}\n\nexport class IsEntryLockedUseCase implements IIsEntryLockedUseCase {\n private readonly getLockRecordUseCase: IGetLockRecordUseCase;\n private readonly isLocked: IIsLocked;\n private readonly getIdentity: IGetIdentity;\n\n public constructor(params: IIsEntryLockedParams) {\n this.getLockRecordUseCase = params.getLockRecordUseCase;\n this.isLocked = params.isLocked;\n this.getIdentity = params.getIdentity;\n }\n\n public async execute(params: IIsEntryLockedUseCaseExecuteParams): Promise<boolean> {\n try {\n const result = await this.getLockRecordUseCase.execute(params);\n if (!result) {\n return false;\n }\n const identity = this.getIdentity();\n if (result.lockedBy.id === identity.id) {\n return false;\n }\n\n return this.isLocked(result);\n } catch (ex) {\n if (ex instanceof NotFoundError === false) {\n throw ex;\n }\n return false;\n }\n }\n}\n"],"mappings":";;;;;;AAKA,IAAAA,eAAA,GAAAC,OAAA;AAUO,MAAMC,oBAAoB,CAAkC;EAKxDC,WAAWA,CAACC,MAA4B,EAAE;IAC7C,IAAI,CAACC,oBAAoB,GAAGD,MAAM,CAACC,oBAAoB;IACvD,IAAI,CAACC,QAAQ,GAAGF,MAAM,CAACE,QAAQ;IAC/B,IAAI,CAACC,WAAW,GAAGH,MAAM,CAACG,WAAW;EACzC;EAEA,MAAaC,OAAOA,CAACJ,MAA0C,EAAoB;IAC/E,IAAI;MACA,MAAMK,MAAM,GAAG,MAAM,IAAI,CAACJ,oBAAoB,CAACG,OAAO,CAACJ,MAAM,CAAC;MAC9D,IAAI,CAACK,MAAM,EAAE;QACT,OAAO,KAAK;MAChB;MACA,MAAMC,QAAQ,GAAG,IAAI,CAACH,WAAW,CAAC,CAAC;MACnC,IAAIE,MAAM,CAACE,QAAQ,CAACC,EAAE,KAAKF,QAAQ,CAACE,EAAE,EAAE;QACpC,OAAO,KAAK;MAChB;MAEA,OAAO,IAAI,CAACN,QAAQ,CAACG,MAAM,CAAC;IAChC,CAAC,CAAC,OAAOI,EAAE,EAAE;MACT,IAAIA,EAAE,YAAYC,6BAAa,KAAK,KAAK,EAAE;QACvC,MAAMD,EAAE;MACZ;MACA,OAAO,KAAK;IAChB;EACJ;AACJ;AAACE,OAAA,CAAAb,oBAAA,GAAAA,oBAAA","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ import { IKickOutCurrentUserUseCase, IKickOutCurrentUserUseCaseExecuteParams } from "../../abstractions/IKickOutCurrentUserUseCase";
2
+ import { IGetIdentity, IGetWebsocketsContextCallable } from "../../types";
3
+ export interface IKickOutCurrentUserUseCaseParams {
4
+ getWebsockets: IGetWebsocketsContextCallable;
5
+ getIdentity: IGetIdentity;
6
+ }
7
+ export declare class KickOutCurrentUserUseCase implements IKickOutCurrentUserUseCase {
8
+ private readonly getWebsockets;
9
+ private readonly getIdentity;
10
+ constructor(params: IKickOutCurrentUserUseCaseParams);
11
+ execute(record: IKickOutCurrentUserUseCaseExecuteParams): Promise<void>;
12
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.KickOutCurrentUserUseCase = void 0;
7
+ var _utils = require("@webiny/utils");
8
+ class KickOutCurrentUserUseCase {
9
+ constructor(params) {
10
+ this.getWebsockets = params.getWebsockets;
11
+ this.getIdentity = params.getIdentity;
12
+ }
13
+ async execute(record) {
14
+ const {
15
+ lockedBy,
16
+ id
17
+ } = record;
18
+ const websockets = this.getWebsockets();
19
+ const {
20
+ id: entryId
21
+ } = (0, _utils.parseIdentifier)(id);
22
+ const identity = this.getIdentity();
23
+
24
+ /**
25
+ * We do not want any errors to leak out of this method.
26
+ * Just log the error, if any.
27
+ */
28
+ try {
29
+ await websockets.send({
30
+ id: lockedBy.id
31
+ }, {
32
+ action: `recordLocking.entry.kickOut.${entryId}`,
33
+ data: {
34
+ record: record.toObject(),
35
+ user: identity
36
+ }
37
+ });
38
+ } catch (ex) {
39
+ console.error(`Could not send the kickOut message to a user with identity id: ${lockedBy.id}. More info in next log line.`);
40
+ console.info(ex);
41
+ }
42
+ }
43
+ }
44
+ exports.KickOutCurrentUserUseCase = KickOutCurrentUserUseCase;
45
+
46
+ //# sourceMappingURL=KickOutCurrentUserUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_utils","require","KickOutCurrentUserUseCase","constructor","params","getWebsockets","getIdentity","execute","record","lockedBy","id","websockets","entryId","parseIdentifier","identity","send","action","data","toObject","user","ex","console","error","info","exports"],"sources":["KickOutCurrentUserUseCase.ts"],"sourcesContent":["import {\n IKickOutCurrentUserUseCase,\n IKickOutCurrentUserUseCaseExecuteParams\n} from \"~/abstractions/IKickOutCurrentUserUseCase\";\nimport { IGetIdentity, IGetWebsocketsContextCallable } from \"~/types\";\nimport { parseIdentifier } from \"@webiny/utils\";\n\nexport interface IKickOutCurrentUserUseCaseParams {\n getWebsockets: IGetWebsocketsContextCallable;\n getIdentity: IGetIdentity;\n}\n\nexport class KickOutCurrentUserUseCase implements IKickOutCurrentUserUseCase {\n private readonly getWebsockets: IGetWebsocketsContextCallable;\n private readonly getIdentity: IGetIdentity;\n\n public constructor(params: IKickOutCurrentUserUseCaseParams) {\n this.getWebsockets = params.getWebsockets;\n this.getIdentity = params.getIdentity;\n }\n\n public async execute(record: IKickOutCurrentUserUseCaseExecuteParams): Promise<void> {\n const { lockedBy, id } = record;\n\n const websockets = this.getWebsockets();\n\n const { id: entryId } = parseIdentifier(id);\n\n const identity = this.getIdentity();\n\n /**\n * We do not want any errors to leak out of this method.\n * Just log the error, if any.\n */\n try {\n await websockets.send(\n { id: lockedBy.id },\n {\n action: `recordLocking.entry.kickOut.${entryId}`,\n data: {\n record: record.toObject(),\n user: identity\n }\n }\n );\n } catch (ex) {\n console.error(\n `Could not send the kickOut message to a user with identity id: ${lockedBy.id}. More info in next log line.`\n );\n console.info(ex);\n }\n }\n}\n"],"mappings":";;;;;;AAKA,IAAAA,MAAA,GAAAC,OAAA;AAOO,MAAMC,yBAAyB,CAAuC;EAIlEC,WAAWA,CAACC,MAAwC,EAAE;IACzD,IAAI,CAACC,aAAa,GAAGD,MAAM,CAACC,aAAa;IACzC,IAAI,CAACC,WAAW,GAAGF,MAAM,CAACE,WAAW;EACzC;EAEA,MAAaC,OAAOA,CAACC,MAA+C,EAAiB;IACjF,MAAM;MAAEC,QAAQ;MAAEC;IAAG,CAAC,GAAGF,MAAM;IAE/B,MAAMG,UAAU,GAAG,IAAI,CAACN,aAAa,CAAC,CAAC;IAEvC,MAAM;MAAEK,EAAE,EAAEE;IAAQ,CAAC,GAAG,IAAAC,sBAAe,EAACH,EAAE,CAAC;IAE3C,MAAMI,QAAQ,GAAG,IAAI,CAACR,WAAW,CAAC,CAAC;;IAEnC;AACR;AACA;AACA;IACQ,IAAI;MACA,MAAMK,UAAU,CAACI,IAAI,CACjB;QAAEL,EAAE,EAAED,QAAQ,CAACC;MAAG,CAAC,EACnB;QACIM,MAAM,EAAG,+BAA8BJ,OAAQ,EAAC;QAChDK,IAAI,EAAE;UACFT,MAAM,EAAEA,MAAM,CAACU,QAAQ,CAAC,CAAC;UACzBC,IAAI,EAAEL;QACV;MACJ,CACJ,CAAC;IACL,CAAC,CAAC,OAAOM,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CACR,kEAAiEb,QAAQ,CAACC,EAAG,+BAClF,CAAC;MACDW,OAAO,CAACE,IAAI,CAACH,EAAE,CAAC;IACpB;EACJ;AACJ;AAACI,OAAA,CAAAtB,yBAAA,GAAAA,yBAAA","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ import { IListAllLockRecordsUseCase, IListAllLockRecordsUseCaseExecuteParams, IListAllLockRecordsUseCaseExecuteResponse } from "../../abstractions/IListAllLockRecordsUseCase";
2
+ import { IRecordLockingModelManager } from "../../types";
3
+ export interface IListAllLockRecordsUseCaseParams {
4
+ getManager(): Promise<IRecordLockingModelManager>;
5
+ }
6
+ export declare class ListAllLockRecordsUseCase implements IListAllLockRecordsUseCase {
7
+ private readonly getManager;
8
+ constructor(params: IListAllLockRecordsUseCaseParams);
9
+ execute(input: IListAllLockRecordsUseCaseExecuteParams): Promise<IListAllLockRecordsUseCaseExecuteResponse>;
10
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ListAllLockRecordsUseCase = void 0;
7
+ var _convertEntryToLockRecord = require("../../utils/convertEntryToLockRecord");
8
+ var _convertWhereCondition = require("../../utils/convertWhereCondition");
9
+ class ListAllLockRecordsUseCase {
10
+ constructor(params) {
11
+ this.getManager = params.getManager;
12
+ }
13
+ async execute(input) {
14
+ try {
15
+ const manager = await this.getManager();
16
+ const params = {
17
+ ...input,
18
+ where: (0, _convertWhereCondition.convertWhereCondition)(input.where)
19
+ };
20
+ const [items, meta] = await manager.listLatest(params);
21
+ return {
22
+ items: items.map(_convertEntryToLockRecord.convertEntryToLockRecord),
23
+ meta
24
+ };
25
+ } catch (ex) {
26
+ throw ex;
27
+ }
28
+ }
29
+ }
30
+ exports.ListAllLockRecordsUseCase = ListAllLockRecordsUseCase;
31
+
32
+ //# sourceMappingURL=ListAllLockRecordsUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_convertEntryToLockRecord","require","_convertWhereCondition","ListAllLockRecordsUseCase","constructor","params","getManager","execute","input","manager","where","convertWhereCondition","items","meta","listLatest","map","convertEntryToLockRecord","ex","exports"],"sources":["ListAllLockRecordsUseCase.ts"],"sourcesContent":["import {\n IListAllLockRecordsUseCase,\n IListAllLockRecordsUseCaseExecuteParams,\n IListAllLockRecordsUseCaseExecuteResponse\n} from \"~/abstractions/IListAllLockRecordsUseCase\";\nimport { IRecordLockingModelManager } from \"~/types\";\nimport { convertEntryToLockRecord } from \"~/utils/convertEntryToLockRecord\";\nimport { convertWhereCondition } from \"~/utils/convertWhereCondition\";\n\nexport interface IListAllLockRecordsUseCaseParams {\n getManager(): Promise<IRecordLockingModelManager>;\n}\n\nexport class ListAllLockRecordsUseCase implements IListAllLockRecordsUseCase {\n private readonly getManager: () => Promise<IRecordLockingModelManager>;\n public constructor(params: IListAllLockRecordsUseCaseParams) {\n this.getManager = params.getManager;\n }\n public async execute(\n input: IListAllLockRecordsUseCaseExecuteParams\n ): Promise<IListAllLockRecordsUseCaseExecuteResponse> {\n try {\n const manager = await this.getManager();\n const params: IListAllLockRecordsUseCaseExecuteParams = {\n ...input,\n where: convertWhereCondition(input.where)\n };\n\n const [items, meta] = await manager.listLatest(params);\n return {\n items: items.map(convertEntryToLockRecord),\n meta\n };\n } catch (ex) {\n throw ex;\n }\n }\n}\n"],"mappings":";;;;;;AAMA,IAAAA,yBAAA,GAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AAMO,MAAME,yBAAyB,CAAuC;EAElEC,WAAWA,CAACC,MAAwC,EAAE;IACzD,IAAI,CAACC,UAAU,GAAGD,MAAM,CAACC,UAAU;EACvC;EACA,MAAaC,OAAOA,CAChBC,KAA8C,EACI;IAClD,IAAI;MACA,MAAMC,OAAO,GAAG,MAAM,IAAI,CAACH,UAAU,CAAC,CAAC;MACvC,MAAMD,MAA+C,GAAG;QACpD,GAAGG,KAAK;QACRE,KAAK,EAAE,IAAAC,4CAAqB,EAACH,KAAK,CAACE,KAAK;MAC5C,CAAC;MAED,MAAM,CAACE,KAAK,EAAEC,IAAI,CAAC,GAAG,MAAMJ,OAAO,CAACK,UAAU,CAACT,MAAM,CAAC;MACtD,OAAO;QACHO,KAAK,EAAEA,KAAK,CAACG,GAAG,CAACC,kDAAwB,CAAC;QAC1CH;MACJ,CAAC;IACL,CAAC,CAAC,OAAOI,EAAE,EAAE;MACT,MAAMA,EAAE;IACZ;EACJ;AACJ;AAACC,OAAA,CAAAf,yBAAA,GAAAA,yBAAA","ignoreList":[]}
@@ -0,0 +1,14 @@
1
+ import { IListLockRecordsUseCase, IListLockRecordsUseCaseExecuteParams, IListLockRecordsUseCaseExecuteResponse } from "../../abstractions/IListLockRecordsUseCase";
2
+ import { IGetIdentity } from "../../types";
3
+ export interface IListLockRecordsUseCaseParams {
4
+ listAllLockRecordsUseCase: IListLockRecordsUseCase;
5
+ timeout: number;
6
+ getIdentity: IGetIdentity;
7
+ }
8
+ export declare class ListLockRecordsUseCase implements IListLockRecordsUseCase {
9
+ private readonly listAllLockRecordsUseCase;
10
+ private readonly timeout;
11
+ private readonly getIdentity;
12
+ constructor(params: IListLockRecordsUseCaseParams);
13
+ execute(input: IListLockRecordsUseCaseExecuteParams): Promise<IListLockRecordsUseCaseExecuteResponse>;
14
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ListLockRecordsUseCase = void 0;
7
+ class ListLockRecordsUseCase {
8
+ constructor(params) {
9
+ this.listAllLockRecordsUseCase = params.listAllLockRecordsUseCase;
10
+ this.timeout = params.timeout;
11
+ this.getIdentity = params.getIdentity;
12
+ }
13
+ async execute(input) {
14
+ const identity = this.getIdentity();
15
+ return this.listAllLockRecordsUseCase.execute({
16
+ ...input,
17
+ where: {
18
+ ...input.where,
19
+ createdBy_not: identity.id,
20
+ savedOn_gte: new Date(new Date().getTime() - this.timeout)
21
+ }
22
+ });
23
+ }
24
+ }
25
+ exports.ListLockRecordsUseCase = ListLockRecordsUseCase;
26
+
27
+ //# sourceMappingURL=ListLockRecordsUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ListLockRecordsUseCase","constructor","params","listAllLockRecordsUseCase","timeout","getIdentity","execute","input","identity","where","createdBy_not","id","savedOn_gte","Date","getTime","exports"],"sources":["ListLockRecordsUseCase.ts"],"sourcesContent":["import {\n IListLockRecordsUseCase,\n IListLockRecordsUseCaseExecuteParams,\n IListLockRecordsUseCaseExecuteResponse\n} from \"~/abstractions/IListLockRecordsUseCase\";\nimport { IGetIdentity } from \"~/types\";\n\nexport interface IListLockRecordsUseCaseParams {\n listAllLockRecordsUseCase: IListLockRecordsUseCase;\n timeout: number;\n getIdentity: IGetIdentity;\n}\n\nexport class ListLockRecordsUseCase implements IListLockRecordsUseCase {\n private readonly listAllLockRecordsUseCase: IListLockRecordsUseCase;\n private readonly timeout: number;\n private readonly getIdentity: IGetIdentity;\n\n public constructor(params: IListLockRecordsUseCaseParams) {\n this.listAllLockRecordsUseCase = params.listAllLockRecordsUseCase;\n this.timeout = params.timeout;\n this.getIdentity = params.getIdentity;\n }\n public async execute(\n input: IListLockRecordsUseCaseExecuteParams\n ): Promise<IListLockRecordsUseCaseExecuteResponse> {\n const identity = this.getIdentity();\n return this.listAllLockRecordsUseCase.execute({\n ...input,\n where: {\n ...input.where,\n createdBy_not: identity.id,\n savedOn_gte: new Date(new Date().getTime() - this.timeout)\n }\n });\n }\n}\n"],"mappings":";;;;;;AAaO,MAAMA,sBAAsB,CAAoC;EAK5DC,WAAWA,CAACC,MAAqC,EAAE;IACtD,IAAI,CAACC,yBAAyB,GAAGD,MAAM,CAACC,yBAAyB;IACjE,IAAI,CAACC,OAAO,GAAGF,MAAM,CAACE,OAAO;IAC7B,IAAI,CAACC,WAAW,GAAGH,MAAM,CAACG,WAAW;EACzC;EACA,MAAaC,OAAOA,CAChBC,KAA2C,EACI;IAC/C,MAAMC,QAAQ,GAAG,IAAI,CAACH,WAAW,CAAC,CAAC;IACnC,OAAO,IAAI,CAACF,yBAAyB,CAACG,OAAO,CAAC;MAC1C,GAAGC,KAAK;MACRE,KAAK,EAAE;QACH,GAAGF,KAAK,CAACE,KAAK;QACdC,aAAa,EAAEF,QAAQ,CAACG,EAAE;QAC1BC,WAAW,EAAE,IAAIC,IAAI,CAAC,IAAIA,IAAI,CAAC,CAAC,CAACC,OAAO,CAAC,CAAC,GAAG,IAAI,CAACV,OAAO;MAC7D;IACJ,CAAC,CAAC;EACN;AACJ;AAACW,OAAA,CAAAf,sBAAA,GAAAA,sBAAA","ignoreList":[]}
@@ -0,0 +1,13 @@
1
+ import { ILockEntryUseCase, ILockEntryUseCaseExecuteParams } from "../../abstractions/ILockEntryUseCase";
2
+ import { IRecordLockingLockRecord, IRecordLockingModelManager } from "../../types";
3
+ import { IIsEntryLockedUseCase } from "../../abstractions/IIsEntryLocked";
4
+ export interface ILockEntryUseCaseParams {
5
+ isEntryLockedUseCase: IIsEntryLockedUseCase;
6
+ getManager(): Promise<IRecordLockingModelManager>;
7
+ }
8
+ export declare class LockEntryUseCase implements ILockEntryUseCase {
9
+ private readonly isEntryLockedUseCase;
10
+ private readonly getManager;
11
+ constructor(params: ILockEntryUseCaseParams);
12
+ execute(params: ILockEntryUseCaseExecuteParams): Promise<IRecordLockingLockRecord>;
13
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.LockEntryUseCase = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ var _convertEntryToLockRecord = require("../../utils/convertEntryToLockRecord");
10
+ var _lockRecordDatabaseId = require("../../utils/lockRecordDatabaseId");
11
+ var _handlerGraphql = require("@webiny/handler-graphql");
12
+ class LockEntryUseCase {
13
+ constructor(params) {
14
+ this.isEntryLockedUseCase = params.isEntryLockedUseCase;
15
+ this.getManager = params.getManager;
16
+ }
17
+ async execute(params) {
18
+ let locked = false;
19
+ try {
20
+ locked = await this.isEntryLockedUseCase.execute(params);
21
+ } catch (ex) {
22
+ if (ex instanceof _handlerGraphql.NotFoundError === false) {
23
+ throw ex;
24
+ }
25
+ locked = false;
26
+ }
27
+ if (locked) {
28
+ throw new _error.default("Entry is already locked for editing.", "ENTRY_ALREADY_LOCKED", {
29
+ ...params
30
+ });
31
+ }
32
+ try {
33
+ const manager = await this.getManager();
34
+ const id = (0, _lockRecordDatabaseId.createLockRecordDatabaseId)(params.id);
35
+ const entry = await manager.create({
36
+ id,
37
+ targetId: params.id,
38
+ type: params.type,
39
+ actions: []
40
+ });
41
+ return (0, _convertEntryToLockRecord.convertEntryToLockRecord)(entry);
42
+ } catch (ex) {
43
+ throw new _error.default(`Could not lock entry: ${ex.message}`, ex.code || "LOCK_ENTRY_ERROR", {
44
+ ...ex.data
45
+ });
46
+ }
47
+ }
48
+ }
49
+ exports.LockEntryUseCase = LockEntryUseCase;
50
+
51
+ //# sourceMappingURL=LockEntryUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_convertEntryToLockRecord","_lockRecordDatabaseId","_handlerGraphql","LockEntryUseCase","constructor","params","isEntryLockedUseCase","getManager","execute","locked","ex","NotFoundError","WebinyError","manager","id","createLockRecordDatabaseId","entry","create","targetId","type","actions","convertEntryToLockRecord","message","code","data","exports"],"sources":["LockEntryUseCase.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport {\n ILockEntryUseCase,\n ILockEntryUseCaseExecuteParams\n} from \"~/abstractions/ILockEntryUseCase\";\nimport {\n IRecordLockingLockRecord,\n IRecordLockingLockRecordValues,\n IRecordLockingModelManager\n} from \"~/types\";\nimport { IIsEntryLockedUseCase } from \"~/abstractions/IIsEntryLocked\";\nimport { convertEntryToLockRecord } from \"~/utils/convertEntryToLockRecord\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\n\nexport interface ILockEntryUseCaseParams {\n isEntryLockedUseCase: IIsEntryLockedUseCase;\n getManager(): Promise<IRecordLockingModelManager>;\n}\n\nexport class LockEntryUseCase implements ILockEntryUseCase {\n private readonly isEntryLockedUseCase: IIsEntryLockedUseCase;\n private readonly getManager: () => Promise<IRecordLockingModelManager>;\n\n public constructor(params: ILockEntryUseCaseParams) {\n this.isEntryLockedUseCase = params.isEntryLockedUseCase;\n this.getManager = params.getManager;\n }\n\n public async execute(\n params: ILockEntryUseCaseExecuteParams\n ): Promise<IRecordLockingLockRecord> {\n let locked = false;\n try {\n locked = await this.isEntryLockedUseCase.execute(params);\n } catch (ex) {\n if (ex instanceof NotFoundError === false) {\n throw ex;\n }\n locked = false;\n }\n if (locked) {\n throw new WebinyError(\"Entry is already locked for editing.\", \"ENTRY_ALREADY_LOCKED\", {\n ...params\n });\n }\n try {\n const manager = await this.getManager();\n\n const id = createLockRecordDatabaseId(params.id);\n const entry = await manager.create<IRecordLockingLockRecordValues>({\n id,\n targetId: params.id,\n type: params.type,\n actions: []\n });\n return convertEntryToLockRecord(entry);\n } catch (ex) {\n throw new WebinyError(\n `Could not lock entry: ${ex.message}`,\n ex.code || \"LOCK_ENTRY_ERROR\",\n {\n ...ex.data\n }\n );\n }\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAWA,IAAAC,yBAAA,GAAAD,OAAA;AACA,IAAAE,qBAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AAOO,MAAMI,gBAAgB,CAA8B;EAIhDC,WAAWA,CAACC,MAA+B,EAAE;IAChD,IAAI,CAACC,oBAAoB,GAAGD,MAAM,CAACC,oBAAoB;IACvD,IAAI,CAACC,UAAU,GAAGF,MAAM,CAACE,UAAU;EACvC;EAEA,MAAaC,OAAOA,CAChBH,MAAsC,EACL;IACjC,IAAII,MAAM,GAAG,KAAK;IAClB,IAAI;MACAA,MAAM,GAAG,MAAM,IAAI,CAACH,oBAAoB,CAACE,OAAO,CAACH,MAAM,CAAC;IAC5D,CAAC,CAAC,OAAOK,EAAE,EAAE;MACT,IAAIA,EAAE,YAAYC,6BAAa,KAAK,KAAK,EAAE;QACvC,MAAMD,EAAE;MACZ;MACAD,MAAM,GAAG,KAAK;IAClB;IACA,IAAIA,MAAM,EAAE;MACR,MAAM,IAAIG,cAAW,CAAC,sCAAsC,EAAE,sBAAsB,EAAE;QAClF,GAAGP;MACP,CAAC,CAAC;IACN;IACA,IAAI;MACA,MAAMQ,OAAO,GAAG,MAAM,IAAI,CAACN,UAAU,CAAC,CAAC;MAEvC,MAAMO,EAAE,GAAG,IAAAC,gDAA0B,EAACV,MAAM,CAACS,EAAE,CAAC;MAChD,MAAME,KAAK,GAAG,MAAMH,OAAO,CAACI,MAAM,CAAiC;QAC/DH,EAAE;QACFI,QAAQ,EAAEb,MAAM,CAACS,EAAE;QACnBK,IAAI,EAAEd,MAAM,CAACc,IAAI;QACjBC,OAAO,EAAE;MACb,CAAC,CAAC;MACF,OAAO,IAAAC,kDAAwB,EAACL,KAAK,CAAC;IAC1C,CAAC,CAAC,OAAON,EAAE,EAAE;MACT,MAAM,IAAIE,cAAW,CAChB,yBAAwBF,EAAE,CAACY,OAAQ,EAAC,EACrCZ,EAAE,CAACa,IAAI,IAAI,kBAAkB,EAC7B;QACI,GAAGb,EAAE,CAACc;MACV,CACJ,CAAC;IACL;EACJ;AACJ;AAACC,OAAA,CAAAtB,gBAAA,GAAAA,gBAAA","ignoreList":[]}
@@ -0,0 +1,20 @@
1
+ import { IUnlockEntryUseCase, IUnlockEntryUseCaseExecuteParams } from "../../abstractions/IUnlockEntryUseCase";
2
+ import { IGetIdentity, IHasFullAccessCallable, IRecordLockingLockRecord, IRecordLockingModelManager } from "../../types";
3
+ import { IGetLockRecordUseCase } from "../../abstractions/IGetLockRecordUseCase";
4
+ import { IKickOutCurrentUserUseCase } from "../../abstractions/IKickOutCurrentUserUseCase";
5
+ export interface IUnlockEntryUseCaseParams {
6
+ readonly getLockRecordUseCase: IGetLockRecordUseCase;
7
+ readonly kickOutCurrentUserUseCase: IKickOutCurrentUserUseCase;
8
+ getManager(): Promise<IRecordLockingModelManager>;
9
+ getIdentity: IGetIdentity;
10
+ hasFullAccess: IHasFullAccessCallable;
11
+ }
12
+ export declare class UnlockEntryUseCase implements IUnlockEntryUseCase {
13
+ private readonly getLockRecordUseCase;
14
+ private readonly kickOutCurrentUserUseCase;
15
+ private readonly getManager;
16
+ private readonly getIdentity;
17
+ private readonly hasFullAccess;
18
+ constructor(params: IUnlockEntryUseCaseParams);
19
+ execute(params: IUnlockEntryUseCaseExecuteParams): Promise<IRecordLockingLockRecord>;
20
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.UnlockEntryUseCase = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ var _lockRecordDatabaseId = require("../../utils/lockRecordDatabaseId");
10
+ var _validateSameIdentity = require("../../utils/validateSameIdentity");
11
+ var _apiSecurity = require("@webiny/api-security");
12
+ class UnlockEntryUseCase {
13
+ constructor(params) {
14
+ this.getLockRecordUseCase = params.getLockRecordUseCase;
15
+ this.kickOutCurrentUserUseCase = params.kickOutCurrentUserUseCase;
16
+ this.getManager = params.getManager;
17
+ this.getIdentity = params.getIdentity;
18
+ this.hasFullAccess = params.hasFullAccess;
19
+ }
20
+ async execute(params) {
21
+ const record = await this.getLockRecordUseCase.execute(params);
22
+ if (!record) {
23
+ throw new _error.default("Lock Record not found.", "LOCK_RECORD_NOT_FOUND", {
24
+ ...params
25
+ });
26
+ }
27
+
28
+ /**
29
+ * We need to validate that the user executing unlock is the same user that locked the entry.
30
+ * In case it is not the same user, there is a possibility that it is a user which has full access,
31
+ * and at that point, we allow unlocking, but we also need to message the user who locked the entry.
32
+ *
33
+ */
34
+ let kickOutCurrentUser = false;
35
+ try {
36
+ (0, _validateSameIdentity.validateSameIdentity)({
37
+ getIdentity: this.getIdentity,
38
+ target: record.lockedBy
39
+ });
40
+ } catch (ex) {
41
+ if (!params.force) {
42
+ throw ex;
43
+ }
44
+ const hasFullAccess = await this.hasFullAccess();
45
+ if (ex instanceof _apiSecurity.NotAuthorizedError === false || !hasFullAccess) {
46
+ throw ex;
47
+ }
48
+ kickOutCurrentUser = true;
49
+ }
50
+ try {
51
+ const manager = await this.getManager();
52
+ await manager.delete((0, _lockRecordDatabaseId.createLockRecordDatabaseId)(params.id));
53
+ if (!kickOutCurrentUser) {
54
+ return record;
55
+ }
56
+ await this.kickOutCurrentUserUseCase.execute(record);
57
+ return record;
58
+ } catch (ex) {
59
+ throw new _error.default(`Could not unlock entry: ${ex.message}`, ex.code || "UNLOCK_ENTRY_ERROR", {
60
+ ...ex.data
61
+ });
62
+ }
63
+ }
64
+ }
65
+ exports.UnlockEntryUseCase = UnlockEntryUseCase;
66
+
67
+ //# sourceMappingURL=UnlockEntryUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_lockRecordDatabaseId","_validateSameIdentity","_apiSecurity","UnlockEntryUseCase","constructor","params","getLockRecordUseCase","kickOutCurrentUserUseCase","getManager","getIdentity","hasFullAccess","execute","record","WebinyError","kickOutCurrentUser","validateSameIdentity","target","lockedBy","ex","force","NotAuthorizedError","manager","delete","createLockRecordDatabaseId","id","message","code","data","exports"],"sources":["UnlockEntryUseCase.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport {\n IUnlockEntryUseCase,\n IUnlockEntryUseCaseExecuteParams\n} from \"~/abstractions/IUnlockEntryUseCase\";\nimport {\n IGetIdentity,\n IHasFullAccessCallable,\n IRecordLockingLockRecord,\n IRecordLockingModelManager\n} from \"~/types\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId\";\nimport { IGetLockRecordUseCase } from \"~/abstractions/IGetLockRecordUseCase\";\nimport { validateSameIdentity } from \"~/utils/validateSameIdentity\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport { IKickOutCurrentUserUseCase } from \"~/abstractions/IKickOutCurrentUserUseCase\";\n\nexport interface IUnlockEntryUseCaseParams {\n readonly getLockRecordUseCase: IGetLockRecordUseCase;\n readonly kickOutCurrentUserUseCase: IKickOutCurrentUserUseCase;\n getManager(): Promise<IRecordLockingModelManager>;\n getIdentity: IGetIdentity;\n hasFullAccess: IHasFullAccessCallable;\n}\n\nexport class UnlockEntryUseCase implements IUnlockEntryUseCase {\n private readonly getLockRecordUseCase: IGetLockRecordUseCase;\n private readonly kickOutCurrentUserUseCase: IKickOutCurrentUserUseCase;\n private readonly getManager: () => Promise<IRecordLockingModelManager>;\n private readonly getIdentity: IGetIdentity;\n private readonly hasFullAccess: IHasFullAccessCallable;\n\n public constructor(params: IUnlockEntryUseCaseParams) {\n this.getLockRecordUseCase = params.getLockRecordUseCase;\n this.kickOutCurrentUserUseCase = params.kickOutCurrentUserUseCase;\n this.getManager = params.getManager;\n this.getIdentity = params.getIdentity;\n this.hasFullAccess = params.hasFullAccess;\n }\n\n public async execute(\n params: IUnlockEntryUseCaseExecuteParams\n ): Promise<IRecordLockingLockRecord> {\n const record = await this.getLockRecordUseCase.execute(params);\n if (!record) {\n throw new WebinyError(\"Lock Record not found.\", \"LOCK_RECORD_NOT_FOUND\", {\n ...params\n });\n }\n\n /**\n * We need to validate that the user executing unlock is the same user that locked the entry.\n * In case it is not the same user, there is a possibility that it is a user which has full access,\n * and at that point, we allow unlocking, but we also need to message the user who locked the entry.\n *\n */\n let kickOutCurrentUser = false;\n try {\n validateSameIdentity({\n getIdentity: this.getIdentity,\n target: record.lockedBy\n });\n } catch (ex) {\n if (!params.force) {\n throw ex;\n }\n const hasFullAccess = await this.hasFullAccess();\n if (ex instanceof NotAuthorizedError === false || !hasFullAccess) {\n throw ex;\n }\n\n kickOutCurrentUser = true;\n }\n\n try {\n const manager = await this.getManager();\n await manager.delete(createLockRecordDatabaseId(params.id));\n\n if (!kickOutCurrentUser) {\n return record;\n }\n await this.kickOutCurrentUserUseCase.execute(record);\n return record;\n } catch (ex) {\n throw new WebinyError(\n `Could not unlock entry: ${ex.message}`,\n ex.code || \"UNLOCK_ENTRY_ERROR\",\n {\n ...ex.data\n }\n );\n }\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAWA,IAAAC,qBAAA,GAAAD,OAAA;AAEA,IAAAE,qBAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAWO,MAAMI,kBAAkB,CAAgC;EAOpDC,WAAWA,CAACC,MAAiC,EAAE;IAClD,IAAI,CAACC,oBAAoB,GAAGD,MAAM,CAACC,oBAAoB;IACvD,IAAI,CAACC,yBAAyB,GAAGF,MAAM,CAACE,yBAAyB;IACjE,IAAI,CAACC,UAAU,GAAGH,MAAM,CAACG,UAAU;IACnC,IAAI,CAACC,WAAW,GAAGJ,MAAM,CAACI,WAAW;IACrC,IAAI,CAACC,aAAa,GAAGL,MAAM,CAACK,aAAa;EAC7C;EAEA,MAAaC,OAAOA,CAChBN,MAAwC,EACP;IACjC,MAAMO,MAAM,GAAG,MAAM,IAAI,CAACN,oBAAoB,CAACK,OAAO,CAACN,MAAM,CAAC;IAC9D,IAAI,CAACO,MAAM,EAAE;MACT,MAAM,IAAIC,cAAW,CAAC,wBAAwB,EAAE,uBAAuB,EAAE;QACrE,GAAGR;MACP,CAAC,CAAC;IACN;;IAEA;AACR;AACA;AACA;AACA;AACA;IACQ,IAAIS,kBAAkB,GAAG,KAAK;IAC9B,IAAI;MACA,IAAAC,0CAAoB,EAAC;QACjBN,WAAW,EAAE,IAAI,CAACA,WAAW;QAC7BO,MAAM,EAAEJ,MAAM,CAACK;MACnB,CAAC,CAAC;IACN,CAAC,CAAC,OAAOC,EAAE,EAAE;MACT,IAAI,CAACb,MAAM,CAACc,KAAK,EAAE;QACf,MAAMD,EAAE;MACZ;MACA,MAAMR,aAAa,GAAG,MAAM,IAAI,CAACA,aAAa,CAAC,CAAC;MAChD,IAAIQ,EAAE,YAAYE,+BAAkB,KAAK,KAAK,IAAI,CAACV,aAAa,EAAE;QAC9D,MAAMQ,EAAE;MACZ;MAEAJ,kBAAkB,GAAG,IAAI;IAC7B;IAEA,IAAI;MACA,MAAMO,OAAO,GAAG,MAAM,IAAI,CAACb,UAAU,CAAC,CAAC;MACvC,MAAMa,OAAO,CAACC,MAAM,CAAC,IAAAC,gDAA0B,EAAClB,MAAM,CAACmB,EAAE,CAAC,CAAC;MAE3D,IAAI,CAACV,kBAAkB,EAAE;QACrB,OAAOF,MAAM;MACjB;MACA,MAAM,IAAI,CAACL,yBAAyB,CAACI,OAAO,CAACC,MAAM,CAAC;MACpD,OAAOA,MAAM;IACjB,CAAC,CAAC,OAAOM,EAAE,EAAE;MACT,MAAM,IAAIL,cAAW,CAChB,2BAA0BK,EAAE,CAACO,OAAQ,EAAC,EACvCP,EAAE,CAACQ,IAAI,IAAI,oBAAoB,EAC/B;QACI,GAAGR,EAAE,CAACS;MACV,CACJ,CAAC;IACL;EACJ;AACJ;AAACC,OAAA,CAAAzB,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -0,0 +1,15 @@
1
+ import { IUnlockEntryRequestUseCase, IUnlockEntryRequestUseCaseExecuteParams } from "../../abstractions/IUnlockEntryRequestUseCase";
2
+ import { IGetIdentity, IRecordLockingLockRecord, IRecordLockingModelManager } from "../../types";
3
+ import { IGetLockRecordUseCase } from "../../abstractions/IGetLockRecordUseCase";
4
+ export interface IUnlockEntryRequestUseCaseParams {
5
+ getLockRecordUseCase: IGetLockRecordUseCase;
6
+ getManager: () => Promise<IRecordLockingModelManager>;
7
+ getIdentity: IGetIdentity;
8
+ }
9
+ export declare class UnlockEntryRequestUseCase implements IUnlockEntryRequestUseCase {
10
+ private readonly getLockRecordUseCase;
11
+ private readonly getManager;
12
+ private readonly getIdentity;
13
+ constructor(params: IUnlockEntryRequestUseCaseParams);
14
+ execute(params: IUnlockEntryRequestUseCaseExecuteParams): Promise<IRecordLockingLockRecord>;
15
+ }