@webiny/api-record-locking 0.0.0-unstable.06b2ede40f

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 +7 -0
  34. package/crud/crud.js +204 -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 +9 -0
  43. package/index.js +39 -0
  44. package/index.js.map +1 -0
  45. package/package.json +46 -0
  46. package/types.d.ts +182 -0
  47. package/types.js +30 -0
  48. package/types.js.map +1 -0
  49. package/useCases/GetLockRecord/GetLockRecordUseCase.d.ts +16 -0
  50. package/useCases/GetLockRecord/GetLockRecordUseCase.js +39 -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 +29 -0
  54. package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js.map +1 -0
  55. package/useCases/IsEntryLocked/IsEntryLockedUseCase.d.ts +13 -0
  56. package/useCases/IsEntryLocked/IsEntryLockedUseCase.js +31 -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 +13 -0
  62. package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.js +34 -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 +21 -0
  68. package/useCases/LockEntryUseCase/LockEntryUseCase.js +64 -0
  69. package/useCases/LockEntryUseCase/LockEntryUseCase.js.map +1 -0
  70. package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.d.ts +23 -0
  71. package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.js +90 -0
  72. package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.js.map +1 -0
  73. package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.d.ts +21 -0
  74. package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.js +82 -0
  75. package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.js.map +1 -0
  76. package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.d.ts +26 -0
  77. package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.js +93 -0
  78. package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.js.map +1 -0
  79. package/useCases/index.d.ts +31 -0
  80. package/useCases/index.js +96 -0
  81. package/useCases/index.js.map +1 -0
  82. package/useCases/types.d.ts +5 -0
  83. package/useCases/types.js +7 -0
  84. package/useCases/types.js.map +1 -0
  85. package/utils/calculateExpiresOn.d.ts +2 -0
  86. package/utils/calculateExpiresOn.js +16 -0
  87. package/utils/calculateExpiresOn.js.map +1 -0
  88. package/utils/checkPermissions.d.ts +7 -0
  89. package/utils/checkPermissions.js +21 -0
  90. package/utils/checkPermissions.js.map +1 -0
  91. package/utils/convertEntryToLockRecord.d.ts +28 -0
  92. package/utils/convertEntryToLockRecord.js +91 -0
  93. package/utils/convertEntryToLockRecord.js.map +1 -0
  94. package/utils/convertWhereCondition.d.ts +4 -0
  95. package/utils/convertWhereCondition.js +41 -0
  96. package/utils/convertWhereCondition.js.map +1 -0
  97. package/utils/getTimeout.d.ts +5 -0
  98. package/utils/getTimeout.js +28 -0
  99. package/utils/getTimeout.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.d.ts ADDED
@@ -0,0 +1,182 @@
1
+ import type { CmsContext, CmsEntryListParams, CmsEntryMeta, CmsIdentity, CmsModel, CmsModelManager } from "@webiny/api-headless-cms/types";
2
+ import { CmsEntry, CmsError } from "@webiny/api-headless-cms/types";
3
+ import type { Topic } from "@webiny/pubsub/types";
4
+ import type { Context as IWebsocketsContext, IWebsocketsContextObject } from "@webiny/api-websockets/types";
5
+ import type { SecurityPermission } from "@webiny/api-security/types";
6
+ export { CmsError, CmsEntry };
7
+ export type IRecordLockingIdentity = CmsIdentity;
8
+ export type IRecordLockingModelManager = CmsModelManager<IRecordLockingLockRecordValues>;
9
+ export type IRecordLockingMeta = CmsEntryMeta;
10
+ export interface IHasRecordLockingAccessCallable {
11
+ (): Promise<boolean>;
12
+ }
13
+ export interface IGetWebsocketsContextCallable {
14
+ (): IWebsocketsContextObject;
15
+ }
16
+ export interface IGetIdentity {
17
+ (): IRecordLockingIdentity;
18
+ }
19
+ export interface IRecordLockingLockRecordValues {
20
+ targetId: string;
21
+ type: IRecordLockingLockRecordEntryType;
22
+ actions?: IRecordLockingLockRecordAction[];
23
+ }
24
+ export declare enum RecordLockingLockRecordActionType {
25
+ requested = "requested",
26
+ approved = "approved",
27
+ denied = "denied"
28
+ }
29
+ export interface IRecordLockingLockRecordRequestedAction {
30
+ type: RecordLockingLockRecordActionType.requested;
31
+ message?: string;
32
+ createdOn: Date;
33
+ createdBy: IRecordLockingIdentity;
34
+ }
35
+ export interface IRecordLockingLockRecordApprovedAction {
36
+ type: RecordLockingLockRecordActionType.approved;
37
+ message?: string;
38
+ createdOn: Date;
39
+ createdBy: IRecordLockingIdentity;
40
+ }
41
+ export interface IRecordLockingLockRecordDeniedAction {
42
+ type: RecordLockingLockRecordActionType.denied;
43
+ message?: string;
44
+ createdOn: Date;
45
+ createdBy: IRecordLockingIdentity;
46
+ }
47
+ export type IRecordLockingLockRecordAction = IRecordLockingLockRecordRequestedAction | IRecordLockingLockRecordApprovedAction | IRecordLockingLockRecordDeniedAction;
48
+ export interface IRecordLockingLockRecordObject {
49
+ id: string;
50
+ targetId: string;
51
+ type: IRecordLockingLockRecordEntryType;
52
+ lockedBy: IRecordLockingIdentity;
53
+ lockedOn: Date;
54
+ updatedOn: Date;
55
+ expiresOn: Date;
56
+ actions?: IRecordLockingLockRecordAction[];
57
+ }
58
+ export interface IRecordLockingLockRecord extends IRecordLockingLockRecordObject {
59
+ toObject(): IRecordLockingLockRecordObject;
60
+ addAction(action: IRecordLockingLockRecordAction): void;
61
+ getUnlockRequested(): IRecordLockingLockRecordRequestedAction | undefined;
62
+ getUnlockApproved(): IRecordLockingLockRecordApprovedAction | undefined;
63
+ getUnlockDenied(): IRecordLockingLockRecordDeniedAction | undefined;
64
+ isExpired(): boolean;
65
+ }
66
+ /**
67
+ * Do not use any special chars other than #, as we use this to create lock record IDs.
68
+ */
69
+ export type IRecordLockingLockRecordEntryType = string;
70
+ export type IRecordLockingListAllLockRecordsParams = Pick<CmsEntryListParams, "where" | "limit" | "sort" | "after">;
71
+ export type IRecordLockingListLockRecordsParams = IRecordLockingListAllLockRecordsParams;
72
+ export interface IRecordLockingListAllLockRecordsResponse {
73
+ items: IRecordLockingLockRecord[];
74
+ meta: IRecordLockingMeta;
75
+ }
76
+ export type IRecordLockingListLockRecordsResponse = IRecordLockingListAllLockRecordsResponse;
77
+ export interface IRecordLockingGetLockRecordParams {
78
+ id: string;
79
+ type: IRecordLockingLockRecordEntryType;
80
+ }
81
+ export interface IRecordLockingIsLockedParams {
82
+ id: string;
83
+ type: IRecordLockingLockRecordEntryType;
84
+ }
85
+ export interface IRecordLockingGetLockedEntryLockRecordParams {
86
+ id: string;
87
+ type: IRecordLockingLockRecordEntryType;
88
+ }
89
+ export interface IRecordLockingLockEntryParams {
90
+ id: string;
91
+ type: IRecordLockingLockRecordEntryType;
92
+ }
93
+ export interface IRecordLockingUpdateEntryLockParams {
94
+ id: string;
95
+ type: IRecordLockingLockRecordEntryType;
96
+ }
97
+ export interface IRecordLockingUnlockEntryParams {
98
+ id: string;
99
+ type: IRecordLockingLockRecordEntryType;
100
+ force?: boolean;
101
+ }
102
+ export interface IRecordLockingUnlockEntryRequestParams {
103
+ id: string;
104
+ type: IRecordLockingLockRecordEntryType;
105
+ }
106
+ export interface OnEntryBeforeLockTopicParams {
107
+ id: string;
108
+ type: IRecordLockingLockRecordEntryType;
109
+ }
110
+ export interface OnEntryAfterLockTopicParams {
111
+ id: string;
112
+ type: IRecordLockingLockRecordEntryType;
113
+ record: IRecordLockingLockRecord;
114
+ }
115
+ export interface OnEntryLockErrorTopicParams {
116
+ id: string;
117
+ type: IRecordLockingLockRecordEntryType;
118
+ error: CmsError;
119
+ }
120
+ export interface OnEntryBeforeUnlockTopicParams {
121
+ id: string;
122
+ type: IRecordLockingLockRecordEntryType;
123
+ getIdentity: IGetIdentity;
124
+ }
125
+ export interface OnEntryAfterUnlockTopicParams {
126
+ id: string;
127
+ type: IRecordLockingLockRecordEntryType;
128
+ record: IRecordLockingLockRecord;
129
+ }
130
+ export interface OnEntryUnlockErrorTopicParams {
131
+ id: string;
132
+ type: IRecordLockingLockRecordEntryType;
133
+ error: CmsError;
134
+ }
135
+ export interface OnEntryBeforeUnlockRequestTopicParams {
136
+ id: string;
137
+ type: IRecordLockingLockRecordEntryType;
138
+ }
139
+ export interface OnEntryAfterUnlockRequestTopicParams {
140
+ id: string;
141
+ type: IRecordLockingLockRecordEntryType;
142
+ record: IRecordLockingLockRecord;
143
+ }
144
+ export interface OnEntryUnlockRequestErrorTopicParams {
145
+ id: string;
146
+ type: IRecordLockingLockRecordEntryType;
147
+ error: CmsError;
148
+ }
149
+ export interface IRecordLocking {
150
+ /**
151
+ * In milliseconds.
152
+ */
153
+ getTimeout: () => number;
154
+ onEntryBeforeLock: Topic<OnEntryBeforeLockTopicParams>;
155
+ onEntryAfterLock: Topic<OnEntryAfterLockTopicParams>;
156
+ onEntryLockError: Topic<OnEntryLockErrorTopicParams>;
157
+ onEntryBeforeUnlock: Topic<OnEntryBeforeUnlockTopicParams>;
158
+ onEntryAfterUnlock: Topic<OnEntryAfterUnlockTopicParams>;
159
+ onEntryUnlockError: Topic<OnEntryUnlockErrorTopicParams>;
160
+ onEntryBeforeUnlockRequest: Topic<OnEntryBeforeUnlockRequestTopicParams>;
161
+ onEntryAfterUnlockRequest: Topic<OnEntryAfterUnlockRequestTopicParams>;
162
+ onEntryUnlockRequestError: Topic<OnEntryUnlockRequestErrorTopicParams>;
163
+ getModel(): Promise<CmsModel>;
164
+ listAllLockRecords(params?: IRecordLockingListAllLockRecordsParams): Promise<IRecordLockingListAllLockRecordsResponse>;
165
+ /**
166
+ * Same call as listAllLockRecords, except this one will filter out records with expired lock.
167
+ */
168
+ listLockRecords(params?: IRecordLockingListLockRecordsParams): Promise<IRecordLockingListLockRecordsResponse>;
169
+ getLockRecord(params: IRecordLockingGetLockRecordParams): Promise<IRecordLockingLockRecord | null>;
170
+ isEntryLocked(params: IRecordLockingIsLockedParams): Promise<boolean>;
171
+ getLockedEntryLockRecord(params: IRecordLockingGetLockedEntryLockRecordParams): Promise<IRecordLockingLockRecord | null>;
172
+ lockEntry(params: IRecordLockingLockEntryParams): Promise<IRecordLockingLockRecord>;
173
+ updateEntryLock(params: IRecordLockingUpdateEntryLockParams): Promise<IRecordLockingLockRecord>;
174
+ unlockEntry(params: IRecordLockingUnlockEntryParams): Promise<IRecordLockingLockRecord>;
175
+ unlockEntryRequest(params: IRecordLockingUnlockEntryRequestParams): Promise<IRecordLockingLockRecord>;
176
+ }
177
+ export interface Context extends CmsContext, IWebsocketsContext {
178
+ recordLocking: IRecordLocking;
179
+ }
180
+ export interface RecordLockingSecurityPermission extends SecurityPermission {
181
+ canForceUnlock?: string;
182
+ }
package/types.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "CmsEntry", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _types.CmsEntry;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "CmsError", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _types.CmsError;
16
+ }
17
+ });
18
+ exports.RecordLockingLockRecordActionType = void 0;
19
+ var _types = require("@webiny/api-headless-cms/types");
20
+ let RecordLockingLockRecordActionType = exports.RecordLockingLockRecordActionType = /*#__PURE__*/function (RecordLockingLockRecordActionType) {
21
+ RecordLockingLockRecordActionType["requested"] = "requested";
22
+ RecordLockingLockRecordActionType["approved"] = "approved";
23
+ RecordLockingLockRecordActionType["denied"] = "denied";
24
+ return RecordLockingLockRecordActionType;
25
+ }({});
26
+ /**
27
+ * Do not use any special chars other than #, as we use this to create lock record IDs.
28
+ */
29
+
30
+ //# sourceMappingURL=types.js.map
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_types","require","RecordLockingLockRecordActionType","exports"],"sources":["types.ts"],"sourcesContent":["import type {\n CmsContext,\n CmsEntryListParams,\n CmsEntryMeta,\n CmsIdentity,\n CmsModel,\n CmsModelManager\n} from \"@webiny/api-headless-cms/types\";\nimport { CmsEntry, CmsError } from \"@webiny/api-headless-cms/types\";\nimport type { Topic } from \"@webiny/pubsub/types\";\nimport type {\n Context as IWebsocketsContext,\n IWebsocketsContextObject\n} from \"@webiny/api-websockets/types\";\nimport type { SecurityPermission } from \"@webiny/api-security/types\";\n\nexport { CmsError, CmsEntry };\n\nexport type IRecordLockingIdentity = CmsIdentity;\n\nexport type IRecordLockingModelManager = CmsModelManager<IRecordLockingLockRecordValues>;\n\nexport type IRecordLockingMeta = CmsEntryMeta;\n\nexport interface IHasRecordLockingAccessCallable {\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 RecordLockingLockRecordActionType {\n requested = \"requested\",\n approved = \"approved\",\n denied = \"denied\"\n}\n\nexport interface IRecordLockingLockRecordRequestedAction {\n type: RecordLockingLockRecordActionType.requested;\n message?: string;\n createdOn: Date;\n createdBy: IRecordLockingIdentity;\n}\n\nexport interface IRecordLockingLockRecordApprovedAction {\n type: RecordLockingLockRecordActionType.approved;\n message?: string;\n createdOn: Date;\n createdBy: IRecordLockingIdentity;\n}\n\nexport interface IRecordLockingLockRecordDeniedAction {\n type: RecordLockingLockRecordActionType.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 isExpired(): boolean;\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 /**\n * In milliseconds.\n */\n getTimeout: () => number;\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\nexport interface RecordLockingSecurityPermission extends SecurityPermission {\n canForceUnlock?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAQA,IAAAA,MAAA,GAAAC,OAAA;AAAoE,IAiCxDC,iCAAiC,GAAAC,OAAA,CAAAD,iCAAA,0BAAjCA,iCAAiC;EAAjCA,iCAAiC;EAAjCA,iCAAiC;EAAjCA,iCAAiC;EAAA,OAAjCA,iCAAiC;AAAA;AAoD7C;AACA;AACA","ignoreList":[]}
@@ -0,0 +1,16 @@
1
+ import type { IGetLockRecordUseCase, IGetLockRecordUseCaseExecuteParams } from "../../abstractions/IGetLockRecordUseCase";
2
+ import type { IRecordLockingLockRecord, IRecordLockingModelManager } from "../../types";
3
+ import type { ConvertEntryToLockRecordCb } from "../types";
4
+ import type { Security } from "@webiny/api-security/types";
5
+ export interface IGetLockRecordUseCaseParams {
6
+ getManager(): Promise<IRecordLockingModelManager>;
7
+ getSecurity(): Pick<Security, "withoutAuthorization">;
8
+ convert: ConvertEntryToLockRecordCb;
9
+ }
10
+ export declare class GetLockRecordUseCase implements IGetLockRecordUseCase {
11
+ private readonly getManager;
12
+ private readonly getSecurity;
13
+ private readonly convert;
14
+ constructor(params: IGetLockRecordUseCaseParams);
15
+ execute(input: IGetLockRecordUseCaseExecuteParams): Promise<IRecordLockingLockRecord | null>;
16
+ }
@@ -0,0 +1,39 @@
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 _lockRecordDatabaseId = require("../../utils/lockRecordDatabaseId");
9
+ var _utils = require("@webiny/utils");
10
+ class GetLockRecordUseCase {
11
+ constructor(params) {
12
+ this.getManager = params.getManager;
13
+ this.getSecurity = params.getSecurity;
14
+ this.convert = params.convert;
15
+ }
16
+ async execute(input) {
17
+ const recordId = (0, _lockRecordDatabaseId.createLockRecordDatabaseId)(input.id);
18
+ const id = (0, _utils.createIdentifier)({
19
+ id: recordId,
20
+ version: 1
21
+ });
22
+ const security = this.getSecurity();
23
+ try {
24
+ const manager = await this.getManager();
25
+ return await security.withoutAuthorization(async () => {
26
+ const result = await manager.get(id);
27
+ return this.convert(result);
28
+ });
29
+ } catch (ex) {
30
+ if (ex instanceof _handlerGraphql.NotFoundError) {
31
+ return null;
32
+ }
33
+ throw ex;
34
+ }
35
+ }
36
+ }
37
+ exports.GetLockRecordUseCase = GetLockRecordUseCase;
38
+
39
+ //# sourceMappingURL=GetLockRecordUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_handlerGraphql","require","_lockRecordDatabaseId","_utils","GetLockRecordUseCase","constructor","params","getManager","getSecurity","convert","execute","input","recordId","createLockRecordDatabaseId","id","createIdentifier","version","security","manager","withoutAuthorization","result","get","ex","NotFoundError","exports"],"sources":["GetLockRecordUseCase.ts"],"sourcesContent":["import type {\n IGetLockRecordUseCase,\n IGetLockRecordUseCaseExecuteParams\n} from \"~/abstractions/IGetLockRecordUseCase\";\nimport type { IRecordLockingLockRecord, IRecordLockingModelManager } from \"~/types\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId\";\nimport { createIdentifier } from \"@webiny/utils\";\nimport type { ConvertEntryToLockRecordCb } from \"~/useCases/types\";\nimport type { Security } from \"@webiny/api-security/types\";\n\nexport interface IGetLockRecordUseCaseParams {\n getManager(): Promise<IRecordLockingModelManager>;\n getSecurity(): Pick<Security, \"withoutAuthorization\">;\n convert: ConvertEntryToLockRecordCb;\n}\n\nexport class GetLockRecordUseCase implements IGetLockRecordUseCase {\n private readonly getManager: IGetLockRecordUseCaseParams[\"getManager\"];\n private readonly getSecurity: IGetLockRecordUseCaseParams[\"getSecurity\"];\n private readonly convert: ConvertEntryToLockRecordCb;\n\n public constructor(params: IGetLockRecordUseCaseParams) {\n this.getManager = params.getManager;\n this.getSecurity = params.getSecurity;\n this.convert = params.convert;\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 const security = this.getSecurity();\n try {\n const manager = await this.getManager();\n return await security.withoutAuthorization(async () => {\n const result = await manager.get(id);\n return this.convert(result);\n });\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,qBAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAUO,MAAMG,oBAAoB,CAAkC;EAKxDC,WAAWA,CAACC,MAAmC,EAAE;IACpD,IAAI,CAACC,UAAU,GAAGD,MAAM,CAACC,UAAU;IACnC,IAAI,CAACC,WAAW,GAAGF,MAAM,CAACE,WAAW;IACrC,IAAI,CAACC,OAAO,GAAGH,MAAM,CAACG,OAAO;EACjC;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,MAAMC,QAAQ,GAAG,IAAI,CAACT,WAAW,CAAC,CAAC;IACnC,IAAI;MACA,MAAMU,OAAO,GAAG,MAAM,IAAI,CAACX,UAAU,CAAC,CAAC;MACvC,OAAO,MAAMU,QAAQ,CAACE,oBAAoB,CAAC,YAAY;QACnD,MAAMC,MAAM,GAAG,MAAMF,OAAO,CAACG,GAAG,CAACP,EAAE,CAAC;QACpC,OAAO,IAAI,CAACL,OAAO,CAACW,MAAM,CAAC;MAC/B,CAAC,CAAC;IACN,CAAC,CAAC,OAAOE,EAAE,EAAE;MACT,IAAIA,EAAE,YAAYC,6BAAa,EAAE;QAC7B,OAAO,IAAI;MACf;MACA,MAAMD,EAAE;IACZ;EACJ;AACJ;AAACE,OAAA,CAAApB,oBAAA,GAAAA,oBAAA","ignoreList":[]}
@@ -0,0 +1,16 @@
1
+ import type { IGetLockRecordUseCase } from "../../abstractions/IGetLockRecordUseCase";
2
+ import type { IGetIdentity, IRecordLockingLockRecord } from "../../types";
3
+ import type { IGetLockedEntryLockRecordUseCase, IGetLockedEntryLockRecordUseCaseExecuteParams } from "../../abstractions/IGetLockedEntryLockRecordUseCase";
4
+ export interface IGetLockedEntryLockRecordUseCaseParams {
5
+ getLockRecordUseCase: IGetLockRecordUseCase;
6
+ getIdentity: IGetIdentity;
7
+ }
8
+ /**
9
+ * This use case is used to get a lock record for an entry - and the entry is still locked by someone other than the current user.
10
+ */
11
+ export declare class GetLockedEntryLockRecordUseCase implements IGetLockedEntryLockRecordUseCase {
12
+ private readonly getLockRecordUseCase;
13
+ private readonly getIdentity;
14
+ constructor(params: IGetLockedEntryLockRecordUseCaseParams);
15
+ execute(params: IGetLockedEntryLockRecordUseCaseExecuteParams): Promise<IRecordLockingLockRecord | null>;
16
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.GetLockedEntryLockRecordUseCase = void 0;
7
+ /**
8
+ * This use case is used to get a lock record for an entry - and the entry is still locked by someone other than the current user.
9
+ */
10
+ class GetLockedEntryLockRecordUseCase {
11
+ constructor(params) {
12
+ this.getLockRecordUseCase = params.getLockRecordUseCase;
13
+ this.getIdentity = params.getIdentity;
14
+ }
15
+ async execute(params) {
16
+ const result = await this.getLockRecordUseCase.execute(params);
17
+ if (!result?.lockedBy?.id || result.isExpired()) {
18
+ return null;
19
+ }
20
+ const identity = this.getIdentity();
21
+ if (identity.id === result.lockedBy.id) {
22
+ return null;
23
+ }
24
+ return result;
25
+ }
26
+ }
27
+ exports.GetLockedEntryLockRecordUseCase = GetLockedEntryLockRecordUseCase;
28
+
29
+ //# sourceMappingURL=GetLockedEntryLockRecordUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["GetLockedEntryLockRecordUseCase","constructor","params","getLockRecordUseCase","getIdentity","execute","result","lockedBy","id","isExpired","identity","exports"],"sources":["GetLockedEntryLockRecordUseCase.ts"],"sourcesContent":["import type { IGetLockRecordUseCase } from \"~/abstractions/IGetLockRecordUseCase\";\nimport type { IGetIdentity, IRecordLockingLockRecord } from \"~/types\";\nimport type {\n IGetLockedEntryLockRecordUseCase,\n IGetLockedEntryLockRecordUseCaseExecuteParams\n} from \"~/abstractions/IGetLockedEntryLockRecordUseCase\";\n\nexport interface IGetLockedEntryLockRecordUseCaseParams {\n getLockRecordUseCase: IGetLockRecordUseCase;\n getIdentity: IGetIdentity;\n}\n\n/**\n * This use case is used to get a lock record for an entry - and the entry is still locked by someone other than the current user.\n */\nexport class GetLockedEntryLockRecordUseCase implements IGetLockedEntryLockRecordUseCase {\n private readonly getLockRecordUseCase: IGetLockRecordUseCase;\n private readonly getIdentity: IGetIdentity;\n\n public constructor(params: IGetLockedEntryLockRecordUseCaseParams) {\n this.getLockRecordUseCase = params.getLockRecordUseCase;\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?.id || result.isExpired()) {\n return null;\n }\n const identity = this.getIdentity();\n if (identity.id === result.lockedBy.id) {\n return null;\n }\n return result;\n }\n}\n"],"mappings":";;;;;;AAYA;AACA;AACA;AACO,MAAMA,+BAA+B,CAA6C;EAI9EC,WAAWA,CAACC,MAA8C,EAAE;IAC/D,IAAI,CAACC,oBAAoB,GAAGD,MAAM,CAACC,oBAAoB;IACvD,IAAI,CAACC,WAAW,GAAGF,MAAM,CAACE,WAAW;EACzC;EAEA,MAAaC,OAAOA,CAChBH,MAAqD,EACb;IACxC,MAAMI,MAAM,GAAG,MAAM,IAAI,CAACH,oBAAoB,CAACE,OAAO,CAACH,MAAM,CAAC;IAC9D,IAAI,CAACI,MAAM,EAAEC,QAAQ,EAAEC,EAAE,IAAIF,MAAM,CAACG,SAAS,CAAC,CAAC,EAAE;MAC7C,OAAO,IAAI;IACf;IACA,MAAMC,QAAQ,GAAG,IAAI,CAACN,WAAW,CAAC,CAAC;IACnC,IAAIM,QAAQ,CAACF,EAAE,KAAKF,MAAM,CAACC,QAAQ,CAACC,EAAE,EAAE;MACpC,OAAO,IAAI;IACf;IACA,OAAOF,MAAM;EACjB;AACJ;AAACK,OAAA,CAAAX,+BAAA,GAAAA,+BAAA","ignoreList":[]}
@@ -0,0 +1,13 @@
1
+ import type { IIsEntryLockedUseCase, IIsEntryLockedUseCaseExecuteParams } from "../../abstractions/IIsEntryLocked";
2
+ import type { IGetLockRecordUseCase } from "../../abstractions/IGetLockRecordUseCase";
3
+ import type { IGetIdentity } from "../../types";
4
+ export interface IIsEntryLockedParams {
5
+ getLockRecordUseCase: IGetLockRecordUseCase;
6
+ getIdentity: IGetIdentity;
7
+ }
8
+ export declare class IsEntryLockedUseCase implements IIsEntryLockedUseCase {
9
+ private readonly getLockRecordUseCase;
10
+ private readonly getIdentity;
11
+ constructor(params: IIsEntryLockedParams);
12
+ execute(params: IIsEntryLockedUseCaseExecuteParams): Promise<boolean>;
13
+ }
@@ -0,0 +1,31 @@
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.getIdentity = params.getIdentity;
12
+ }
13
+ async execute(params) {
14
+ try {
15
+ const result = await this.getLockRecordUseCase.execute(params);
16
+ if (!result || result.isExpired()) {
17
+ return false;
18
+ }
19
+ const identity = this.getIdentity();
20
+ return result.lockedBy.id !== identity.id;
21
+ } catch (ex) {
22
+ if (ex instanceof _handlerGraphql.NotFoundError === false) {
23
+ throw ex;
24
+ }
25
+ return false;
26
+ }
27
+ }
28
+ }
29
+ exports.IsEntryLockedUseCase = IsEntryLockedUseCase;
30
+
31
+ //# sourceMappingURL=IsEntryLockedUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_handlerGraphql","require","IsEntryLockedUseCase","constructor","params","getLockRecordUseCase","getIdentity","execute","result","isExpired","identity","lockedBy","id","ex","NotFoundError","exports"],"sources":["IsEntryLockedUseCase.ts"],"sourcesContent":["import type {\n IIsEntryLockedUseCase,\n IIsEntryLockedUseCaseExecuteParams\n} from \"~/abstractions/IIsEntryLocked\";\nimport type { IGetLockRecordUseCase } from \"~/abstractions/IGetLockRecordUseCase\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport type { IGetIdentity } from \"~/types\";\n\nexport interface IIsEntryLockedParams {\n getLockRecordUseCase: IGetLockRecordUseCase;\n getIdentity: IGetIdentity;\n}\n\nexport class IsEntryLockedUseCase implements IIsEntryLockedUseCase {\n private readonly getLockRecordUseCase: IGetLockRecordUseCase;\n private readonly getIdentity: IGetIdentity;\n\n public constructor(params: IIsEntryLockedParams) {\n this.getLockRecordUseCase = params.getLockRecordUseCase;\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 || result.isExpired()) {\n return false;\n }\n const identity = this.getIdentity();\n\n return result.lockedBy.id !== identity.id;\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;AAQO,MAAMC,oBAAoB,CAAkC;EAIxDC,WAAWA,CAACC,MAA4B,EAAE;IAC7C,IAAI,CAACC,oBAAoB,GAAGD,MAAM,CAACC,oBAAoB;IACvD,IAAI,CAACC,WAAW,GAAGF,MAAM,CAACE,WAAW;EACzC;EAEA,MAAaC,OAAOA,CAACH,MAA0C,EAAoB;IAC/E,IAAI;MACA,MAAMI,MAAM,GAAG,MAAM,IAAI,CAACH,oBAAoB,CAACE,OAAO,CAACH,MAAM,CAAC;MAC9D,IAAI,CAACI,MAAM,IAAIA,MAAM,CAACC,SAAS,CAAC,CAAC,EAAE;QAC/B,OAAO,KAAK;MAChB;MACA,MAAMC,QAAQ,GAAG,IAAI,CAACJ,WAAW,CAAC,CAAC;MAEnC,OAAOE,MAAM,CAACG,QAAQ,CAACC,EAAE,KAAKF,QAAQ,CAACE,EAAE;IAC7C,CAAC,CAAC,OAAOC,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 type { IKickOutCurrentUserUseCase, IKickOutCurrentUserUseCaseExecuteParams } from "../../abstractions/IKickOutCurrentUserUseCase";
2
+ import type { 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 type {\n IKickOutCurrentUserUseCase,\n IKickOutCurrentUserUseCaseExecuteParams\n} from \"~/abstractions/IKickOutCurrentUserUseCase\";\nimport type { 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,EAAE,+BAA+BJ,OAAO,EAAE;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,CACT,kEAAkEb,QAAQ,CAACC,EAAE,+BACjF,CAAC;MACDW,OAAO,CAACE,IAAI,CAACH,EAAE,CAAC;IACpB;EACJ;AACJ;AAACI,OAAA,CAAAtB,yBAAA,GAAAA,yBAAA","ignoreList":[]}
@@ -0,0 +1,13 @@
1
+ import type { IListAllLockRecordsUseCase, IListAllLockRecordsUseCaseExecuteParams, IListAllLockRecordsUseCaseExecuteResponse } from "../../abstractions/IListAllLockRecordsUseCase";
2
+ import type { IRecordLockingModelManager } from "../../types";
3
+ import type { ConvertEntryToLockRecordCb } from "../types";
4
+ export interface IListAllLockRecordsUseCaseParams {
5
+ getManager(): Promise<IRecordLockingModelManager>;
6
+ convert: ConvertEntryToLockRecordCb;
7
+ }
8
+ export declare class ListAllLockRecordsUseCase implements IListAllLockRecordsUseCase {
9
+ private readonly getManager;
10
+ private readonly convert;
11
+ constructor(params: IListAllLockRecordsUseCaseParams);
12
+ execute(input: IListAllLockRecordsUseCaseExecuteParams): Promise<IListAllLockRecordsUseCaseExecuteResponse>;
13
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ListAllLockRecordsUseCase = void 0;
7
+ var _convertWhereCondition = require("../../utils/convertWhereCondition");
8
+ class ListAllLockRecordsUseCase {
9
+ constructor(params) {
10
+ this.getManager = params.getManager;
11
+ this.convert = params.convert;
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(item => {
23
+ return this.convert(item);
24
+ }),
25
+ meta
26
+ };
27
+ } catch (ex) {
28
+ throw ex;
29
+ }
30
+ }
31
+ }
32
+ exports.ListAllLockRecordsUseCase = ListAllLockRecordsUseCase;
33
+
34
+ //# sourceMappingURL=ListAllLockRecordsUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_convertWhereCondition","require","ListAllLockRecordsUseCase","constructor","params","getManager","convert","execute","input","manager","where","convertWhereCondition","items","meta","listLatest","map","item","ex","exports"],"sources":["ListAllLockRecordsUseCase.ts"],"sourcesContent":["import type {\n IListAllLockRecordsUseCase,\n IListAllLockRecordsUseCaseExecuteParams,\n IListAllLockRecordsUseCaseExecuteResponse\n} from \"~/abstractions/IListAllLockRecordsUseCase\";\nimport type { IRecordLockingModelManager } from \"~/types\";\nimport { convertWhereCondition } from \"~/utils/convertWhereCondition\";\nimport type { ConvertEntryToLockRecordCb } from \"~/useCases/types\";\n\nexport interface IListAllLockRecordsUseCaseParams {\n getManager(): Promise<IRecordLockingModelManager>;\n convert: ConvertEntryToLockRecordCb;\n}\n\nexport class ListAllLockRecordsUseCase implements IListAllLockRecordsUseCase {\n private readonly getManager: () => Promise<IRecordLockingModelManager>;\n private readonly convert: ConvertEntryToLockRecordCb;\n\n public constructor(params: IListAllLockRecordsUseCaseParams) {\n this.getManager = params.getManager;\n this.convert = params.convert;\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(item => {\n return this.convert(item);\n }),\n meta\n };\n } catch (ex) {\n throw ex;\n }\n }\n}\n"],"mappings":";;;;;;AAMA,IAAAA,sBAAA,GAAAC,OAAA;AAQO,MAAMC,yBAAyB,CAAuC;EAIlEC,WAAWA,CAACC,MAAwC,EAAE;IACzD,IAAI,CAACC,UAAU,GAAGD,MAAM,CAACC,UAAU;IACnC,IAAI,CAACC,OAAO,GAAGF,MAAM,CAACE,OAAO;EACjC;EACA,MAAaC,OAAOA,CAChBC,KAA8C,EACI;IAClD,IAAI;MACA,MAAMC,OAAO,GAAG,MAAM,IAAI,CAACJ,UAAU,CAAC,CAAC;MACvC,MAAMD,MAA+C,GAAG;QACpD,GAAGI,KAAK;QACRE,KAAK,EAAE,IAAAC,4CAAqB,EAACH,KAAK,CAACE,KAAK;MAC5C,CAAC;MAED,MAAM,CAACE,KAAK,EAAEC,IAAI,CAAC,GAAG,MAAMJ,OAAO,CAACK,UAAU,CAACV,MAAM,CAAC;MACtD,OAAO;QACHQ,KAAK,EAAEA,KAAK,CAACG,GAAG,CAACC,IAAI,IAAI;UACrB,OAAO,IAAI,CAACV,OAAO,CAACU,IAAI,CAAC;QAC7B,CAAC,CAAC;QACFH;MACJ,CAAC;IACL,CAAC,CAAC,OAAOI,EAAE,EAAE;MACT,MAAMA,EAAE;IACZ;EACJ;AACJ;AAACC,OAAA,CAAAhB,yBAAA,GAAAA,yBAAA","ignoreList":[]}
@@ -0,0 +1,14 @@
1
+ import type { IListLockRecordsUseCase, IListLockRecordsUseCaseExecuteParams, IListLockRecordsUseCaseExecuteResponse } from "../../abstractions/IListLockRecordsUseCase";
2
+ import type { 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 type {\n IListLockRecordsUseCase,\n IListLockRecordsUseCaseExecuteParams,\n IListLockRecordsUseCaseExecuteResponse\n} from \"~/abstractions/IListLockRecordsUseCase\";\nimport type { 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,21 @@
1
+ import type { ILockEntryUseCase, ILockEntryUseCaseExecuteParams } from "../../abstractions/ILockEntryUseCase";
2
+ import type { IRecordLockingLockRecord, IRecordLockingModelManager } from "../../types";
3
+ import type { IIsEntryLockedUseCase } from "../../abstractions/IIsEntryLocked";
4
+ import type { ConvertEntryToLockRecordCb } from "../types";
5
+ import type { Security, SecurityIdentity } from "@webiny/api-security/types";
6
+ export interface ILockEntryUseCaseParams {
7
+ isEntryLockedUseCase: IIsEntryLockedUseCase;
8
+ getManager(): Promise<IRecordLockingModelManager>;
9
+ getSecurity(): Pick<Security, "withoutAuthorization">;
10
+ getIdentity(): SecurityIdentity;
11
+ convert: ConvertEntryToLockRecordCb;
12
+ }
13
+ export declare class LockEntryUseCase implements ILockEntryUseCase {
14
+ private readonly isEntryLockedUseCase;
15
+ private readonly getManager;
16
+ private readonly getSecurity;
17
+ private readonly getIdentity;
18
+ private readonly convert;
19
+ constructor(params: ILockEntryUseCaseParams);
20
+ execute(params: ILockEntryUseCaseExecuteParams): Promise<IRecordLockingLockRecord>;
21
+ }