@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.
- package/LICENSE +21 -0
- package/README.md +10 -0
- package/abstractions/IGetLockRecordUseCase.d.ts +8 -0
- package/abstractions/IGetLockRecordUseCase.js +7 -0
- package/abstractions/IGetLockRecordUseCase.js.map +1 -0
- package/abstractions/IGetLockedEntryLockRecordUseCase.d.ts +8 -0
- package/abstractions/IGetLockedEntryLockRecordUseCase.js +7 -0
- package/abstractions/IGetLockedEntryLockRecordUseCase.js.map +1 -0
- package/abstractions/IIsEntryLocked.d.ts +8 -0
- package/abstractions/IIsEntryLocked.js +7 -0
- package/abstractions/IIsEntryLocked.js.map +1 -0
- package/abstractions/IKickOutCurrentUserUseCase.d.ts +5 -0
- package/abstractions/IKickOutCurrentUserUseCase.js +7 -0
- package/abstractions/IKickOutCurrentUserUseCase.js.map +1 -0
- package/abstractions/IListAllLockRecordsUseCase.d.ts +9 -0
- package/abstractions/IListAllLockRecordsUseCase.js +7 -0
- package/abstractions/IListAllLockRecordsUseCase.js.map +1 -0
- package/abstractions/IListLockRecordsUseCase.d.ts +10 -0
- package/abstractions/IListLockRecordsUseCase.js +7 -0
- package/abstractions/IListLockRecordsUseCase.js.map +1 -0
- package/abstractions/ILockEntryUseCase.d.ts +11 -0
- package/abstractions/ILockEntryUseCase.js +7 -0
- package/abstractions/ILockEntryUseCase.js.map +1 -0
- package/abstractions/IUnlockEntryRequestUseCase.d.ts +11 -0
- package/abstractions/IUnlockEntryRequestUseCase.js +7 -0
- package/abstractions/IUnlockEntryRequestUseCase.js.map +1 -0
- package/abstractions/IUnlockEntryUseCase.d.ts +12 -0
- package/abstractions/IUnlockEntryUseCase.js +7 -0
- package/abstractions/IUnlockEntryUseCase.js.map +1 -0
- package/abstractions/IUpdateEntryLockUseCase.d.ts +11 -0
- package/abstractions/IUpdateEntryLockUseCase.js +7 -0
- package/abstractions/IUpdateEntryLockUseCase.js.map +1 -0
- package/crud/crud.d.ts +6 -0
- package/crud/crud.js +188 -0
- package/crud/crud.js.map +1 -0
- package/crud/model.d.ts +2 -0
- package/crud/model.js +127 -0
- package/crud/model.js.map +1 -0
- package/graphql/schema.d.ts +7 -0
- package/graphql/schema.js +280 -0
- package/graphql/schema.js.map +1 -0
- package/index.d.ts +3 -0
- package/index.js +38 -0
- package/index.js.map +1 -0
- package/package.json +64 -0
- package/types.d.ts +172 -0
- package/types.js +30 -0
- package/types.js.map +1 -0
- package/useCases/GetLockRecord/GetLockRecordUseCase.d.ts +10 -0
- package/useCases/GetLockRecord/GetLockRecordUseCase.js +35 -0
- package/useCases/GetLockRecord/GetLockRecordUseCase.js.map +1 -0
- package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.d.ts +16 -0
- package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js +27 -0
- package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js.map +1 -0
- package/useCases/IsEntryLocked/IsEntryLockedUseCase.d.ts +16 -0
- package/useCases/IsEntryLocked/IsEntryLockedUseCase.js +35 -0
- package/useCases/IsEntryLocked/IsEntryLockedUseCase.js.map +1 -0
- package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.d.ts +12 -0
- package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.js +46 -0
- package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.js.map +1 -0
- package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.d.ts +10 -0
- package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.js +32 -0
- package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.js.map +1 -0
- package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.d.ts +14 -0
- package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.js +27 -0
- package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.js.map +1 -0
- package/useCases/LockEntryUseCase/LockEntryUseCase.d.ts +13 -0
- package/useCases/LockEntryUseCase/LockEntryUseCase.js +51 -0
- package/useCases/LockEntryUseCase/LockEntryUseCase.js.map +1 -0
- package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.d.ts +20 -0
- package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.js +67 -0
- package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.js.map +1 -0
- package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.d.ts +15 -0
- package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.js +78 -0
- package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.js.map +1 -0
- package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.d.ts +18 -0
- package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.js +48 -0
- package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.js.map +1 -0
- package/useCases/index.d.ts +28 -0
- package/useCases/index.js +83 -0
- package/useCases/index.js.map +1 -0
- package/utils/calculateExpiresOn.d.ts +2 -0
- package/utils/calculateExpiresOn.js +15 -0
- package/utils/calculateExpiresOn.js.map +1 -0
- package/utils/checkPermissions.d.ts +7 -0
- package/utils/checkPermissions.js +21 -0
- package/utils/checkPermissions.js.map +1 -0
- package/utils/convertEntryToLockRecord.d.ts +28 -0
- package/utils/convertEntryToLockRecord.js +88 -0
- package/utils/convertEntryToLockRecord.js.map +1 -0
- package/utils/convertWhereCondition.d.ts +4 -0
- package/utils/convertWhereCondition.js +41 -0
- package/utils/convertWhereCondition.js.map +1 -0
- package/utils/getTimeout.d.ts +4 -0
- package/utils/getTimeout.js +20 -0
- package/utils/getTimeout.js.map +1 -0
- package/utils/isLockedFactory.d.ts +5 -0
- package/utils/isLockedFactory.js +20 -0
- package/utils/isLockedFactory.js.map +1 -0
- package/utils/lockRecordDatabaseId.d.ts +2 -0
- package/utils/lockRecordDatabaseId.js +24 -0
- package/utils/lockRecordDatabaseId.js.map +1 -0
- package/utils/resolve.d.ts +8 -0
- package/utils/resolve.js +30 -0
- package/utils/resolve.js.map +1 -0
- package/utils/validateSameIdentity.d.ts +6 -0
- package/utils/validateSameIdentity.js +24 -0
- package/utils/validateSameIdentity.js.map +1 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.UnlockEntryRequestUseCase = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _types = require("../../types");
|
|
10
|
+
var _lockRecordDatabaseId = require("../../utils/lockRecordDatabaseId");
|
|
11
|
+
var _utils = require("@webiny/utils");
|
|
12
|
+
var _convertEntryToLockRecord = require("../../utils/convertEntryToLockRecord");
|
|
13
|
+
class UnlockEntryRequestUseCase {
|
|
14
|
+
constructor(params) {
|
|
15
|
+
this.getLockRecordUseCase = params.getLockRecordUseCase;
|
|
16
|
+
this.getManager = params.getManager;
|
|
17
|
+
this.getIdentity = params.getIdentity;
|
|
18
|
+
}
|
|
19
|
+
async execute(params) {
|
|
20
|
+
const record = await this.getLockRecordUseCase.execute(params);
|
|
21
|
+
if (!record) {
|
|
22
|
+
throw new _error.default("Entry is not locked.", "ENTRY_NOT_LOCKED", {
|
|
23
|
+
...params
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const unlockRequested = record.getUnlockRequested();
|
|
27
|
+
if (unlockRequested) {
|
|
28
|
+
const currentIdentity = this.getIdentity();
|
|
29
|
+
/**
|
|
30
|
+
* If a current identity did not request unlock, we will not allow that user to continue.
|
|
31
|
+
*/
|
|
32
|
+
if (unlockRequested.createdBy.id !== currentIdentity.id) {
|
|
33
|
+
throw new _error.default("Unlock request already sent.", "UNLOCK_REQUEST_ALREADY_SENT", {
|
|
34
|
+
...params,
|
|
35
|
+
identity: unlockRequested.createdBy
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const approved = record.getUnlockApproved();
|
|
39
|
+
const denied = record.getUnlockDenied();
|
|
40
|
+
if (approved || denied) {
|
|
41
|
+
return record;
|
|
42
|
+
}
|
|
43
|
+
throw new _error.default("Unlock request already sent.", "UNLOCK_REQUEST_ALREADY_SENT", {
|
|
44
|
+
...params,
|
|
45
|
+
identity: unlockRequested.createdBy
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
record.addAction({
|
|
49
|
+
type: _types.IRecordLockingLockRecordActionType.requested,
|
|
50
|
+
createdOn: new Date(),
|
|
51
|
+
createdBy: this.getIdentity()
|
|
52
|
+
});
|
|
53
|
+
try {
|
|
54
|
+
const manager = await this.getManager();
|
|
55
|
+
const entryId = (0, _lockRecordDatabaseId.createLockRecordDatabaseId)(record.id);
|
|
56
|
+
const id = (0, _utils.createIdentifier)({
|
|
57
|
+
id: entryId,
|
|
58
|
+
version: 1
|
|
59
|
+
});
|
|
60
|
+
const result = await manager.update(id, record.toObject());
|
|
61
|
+
return (0, _convertEntryToLockRecord.convertEntryToLockRecord)(result);
|
|
62
|
+
} catch (ex) {
|
|
63
|
+
throw new _error.default("Could not update record with a unlock request.", "UNLOCK_REQUEST_ERROR", {
|
|
64
|
+
...ex.data,
|
|
65
|
+
error: {
|
|
66
|
+
message: ex.message,
|
|
67
|
+
code: ex.code
|
|
68
|
+
},
|
|
69
|
+
id: params.id,
|
|
70
|
+
type: params.type,
|
|
71
|
+
recordId: record.id
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.UnlockEntryRequestUseCase = UnlockEntryRequestUseCase;
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=UnlockEntryRequestUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_types","_lockRecordDatabaseId","_utils","_convertEntryToLockRecord","UnlockEntryRequestUseCase","constructor","params","getLockRecordUseCase","getManager","getIdentity","execute","record","WebinyError","unlockRequested","getUnlockRequested","currentIdentity","createdBy","id","identity","approved","getUnlockApproved","denied","getUnlockDenied","addAction","type","IRecordLockingLockRecordActionType","requested","createdOn","Date","manager","entryId","createLockRecordDatabaseId","createIdentifier","version","result","update","toObject","convertEntryToLockRecord","ex","data","error","message","code","recordId","exports"],"sources":["UnlockEntryRequestUseCase.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport {\n IUnlockEntryRequestUseCase,\n IUnlockEntryRequestUseCaseExecuteParams\n} from \"~/abstractions/IUnlockEntryRequestUseCase\";\nimport {\n IGetIdentity,\n IRecordLockingLockRecord,\n IRecordLockingLockRecordActionType,\n IRecordLockingModelManager\n} from \"~/types\";\nimport { IGetLockRecordUseCase } from \"~/abstractions/IGetLockRecordUseCase\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId\";\nimport { createIdentifier } from \"@webiny/utils\";\nimport { convertEntryToLockRecord } from \"~/utils/convertEntryToLockRecord\";\n\nexport interface IUnlockEntryRequestUseCaseParams {\n getLockRecordUseCase: IGetLockRecordUseCase;\n getManager: () => Promise<IRecordLockingModelManager>;\n getIdentity: IGetIdentity;\n}\n\nexport class UnlockEntryRequestUseCase implements IUnlockEntryRequestUseCase {\n private readonly getLockRecordUseCase: IGetLockRecordUseCase;\n private readonly getManager: () => Promise<IRecordLockingModelManager>;\n private readonly getIdentity: IGetIdentity;\n\n public constructor(params: IUnlockEntryRequestUseCaseParams) {\n this.getLockRecordUseCase = params.getLockRecordUseCase;\n this.getManager = params.getManager;\n this.getIdentity = params.getIdentity;\n }\n\n public async execute(\n params: IUnlockEntryRequestUseCaseExecuteParams\n ): Promise<IRecordLockingLockRecord> {\n const record = await this.getLockRecordUseCase.execute(params);\n if (!record) {\n throw new WebinyError(\"Entry is not locked.\", \"ENTRY_NOT_LOCKED\", {\n ...params\n });\n }\n const unlockRequested = record.getUnlockRequested();\n if (unlockRequested) {\n const currentIdentity = this.getIdentity();\n /**\n * If a current identity did not request unlock, we will not allow that user to continue.\n */\n if (unlockRequested.createdBy.id !== currentIdentity.id) {\n throw new WebinyError(\n \"Unlock request already sent.\",\n \"UNLOCK_REQUEST_ALREADY_SENT\",\n {\n ...params,\n identity: unlockRequested.createdBy\n }\n );\n }\n const approved = record.getUnlockApproved();\n const denied = record.getUnlockDenied();\n if (approved || denied) {\n return record;\n }\n throw new WebinyError(\"Unlock request already sent.\", \"UNLOCK_REQUEST_ALREADY_SENT\", {\n ...params,\n identity: unlockRequested.createdBy\n });\n }\n\n record.addAction({\n type: IRecordLockingLockRecordActionType.requested,\n createdOn: new Date(),\n createdBy: this.getIdentity()\n });\n\n try {\n const manager = await this.getManager();\n\n const entryId = createLockRecordDatabaseId(record.id);\n const id = createIdentifier({\n id: entryId,\n version: 1\n });\n const result = await manager.update(id, record.toObject());\n return convertEntryToLockRecord(result);\n } catch (ex) {\n throw new WebinyError(\n \"Could not update record with a unlock request.\",\n \"UNLOCK_REQUEST_ERROR\",\n {\n ...ex.data,\n error: {\n message: ex.message,\n code: ex.code\n },\n id: params.id,\n type: params.type,\n recordId: record.id\n }\n );\n }\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAD,OAAA;AAOA,IAAAE,qBAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,yBAAA,GAAAJ,OAAA;AAQO,MAAMK,yBAAyB,CAAuC;EAKlEC,WAAWA,CAACC,MAAwC,EAAE;IACzD,IAAI,CAACC,oBAAoB,GAAGD,MAAM,CAACC,oBAAoB;IACvD,IAAI,CAACC,UAAU,GAAGF,MAAM,CAACE,UAAU;IACnC,IAAI,CAACC,WAAW,GAAGH,MAAM,CAACG,WAAW;EACzC;EAEA,MAAaC,OAAOA,CAChBJ,MAA+C,EACd;IACjC,MAAMK,MA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e,uBAAgB,EAAC;QACxBf,EAAE,EAAEa,OAAO;QACXG,OAAO,EAAE;MACb,CAAC,CAAC;MACF,MAAMC,MAAM,GAAG,MAAML,OAAO,CAACM,MAAM,CAAClB,EAAE,EAAEN,MAAM,CAACyB,QAAQ,CAAC,CAAC,CAAC;MAC1D,OAAO,IAAAC,kDAAwB,EAACH,MAAM,CAAC;IAC3C,CAAC,CAAC,OAAOI,EAAE,EAAE;MACT,MAAM,IAAI1B,cAAW,CACjB,gDAAgD,EAChD,sBAAsB,EACtB;QACI,GAAG0B,EAAE,CAACC,IAAI;QACVC,KAAK,EAAE;UACHC,OAAO,EAAEH,EAAE,CAACG,OAAO;UACnBC,IAAI,EAAEJ,EAAE,CAACI;QACb,CAAC;QACDzB,EAAE,EAAEX,MAAM,CAACW,EAAE;QACbO,IAAI,EAAElB,MAAM,CAACkB,IAAI;QACjBmB,QAAQ,EAAEhC,MAAM,CAACM;MACrB,CACJ,CAAC;IACL;EACJ;AACJ;AAAC2B,OAAA,CAAAxC,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IUpdateEntryLockUseCase, IUpdateEntryLockUseCaseExecuteParams } from "../../abstractions/IUpdateEntryLockUseCase";
|
|
2
|
+
import { IGetIdentity, IRecordLockingLockRecord, IRecordLockingModelManager } from "../../types";
|
|
3
|
+
import { IGetLockRecordUseCase } from "../../abstractions/IGetLockRecordUseCase";
|
|
4
|
+
import { ILockEntryUseCase } from "../../abstractions/ILockEntryUseCase";
|
|
5
|
+
export interface IUpdateEntryLockUseCaseParams {
|
|
6
|
+
readonly getLockRecordUseCase: IGetLockRecordUseCase;
|
|
7
|
+
readonly lockEntryUseCase: ILockEntryUseCase;
|
|
8
|
+
getManager(): Promise<IRecordLockingModelManager>;
|
|
9
|
+
getIdentity: IGetIdentity;
|
|
10
|
+
}
|
|
11
|
+
export declare class UpdateEntryLockUseCase implements IUpdateEntryLockUseCase {
|
|
12
|
+
private readonly getLockRecordUseCase;
|
|
13
|
+
private readonly lockEntryUseCase;
|
|
14
|
+
private readonly getManager;
|
|
15
|
+
private readonly getIdentity;
|
|
16
|
+
constructor(params: IUpdateEntryLockUseCaseParams);
|
|
17
|
+
execute(params: IUpdateEntryLockUseCaseExecuteParams): Promise<IRecordLockingLockRecord>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UpdateEntryLockUseCase = void 0;
|
|
7
|
+
var _error = require("@webiny/error");
|
|
8
|
+
var _convertEntryToLockRecord = require("../../utils/convertEntryToLockRecord");
|
|
9
|
+
var _lockRecordDatabaseId = require("../../utils/lockRecordDatabaseId");
|
|
10
|
+
var _utils = require("@webiny/utils");
|
|
11
|
+
var _validateSameIdentity = require("../../utils/validateSameIdentity");
|
|
12
|
+
class UpdateEntryLockUseCase {
|
|
13
|
+
constructor(params) {
|
|
14
|
+
this.getLockRecordUseCase = params.getLockRecordUseCase;
|
|
15
|
+
this.lockEntryUseCase = params.lockEntryUseCase;
|
|
16
|
+
this.getManager = params.getManager;
|
|
17
|
+
this.getIdentity = params.getIdentity;
|
|
18
|
+
}
|
|
19
|
+
async execute(params) {
|
|
20
|
+
const record = await this.getLockRecordUseCase.execute(params);
|
|
21
|
+
if (!record) {
|
|
22
|
+
return this.lockEntryUseCase.execute(params);
|
|
23
|
+
}
|
|
24
|
+
(0, _validateSameIdentity.validateSameIdentity)({
|
|
25
|
+
getIdentity: this.getIdentity,
|
|
26
|
+
target: record.lockedBy
|
|
27
|
+
});
|
|
28
|
+
try {
|
|
29
|
+
const manager = await this.getManager();
|
|
30
|
+
const entryId = (0, _lockRecordDatabaseId.createLockRecordDatabaseId)(record.id);
|
|
31
|
+
const id = (0, _utils.createIdentifier)({
|
|
32
|
+
id: entryId,
|
|
33
|
+
version: 1
|
|
34
|
+
});
|
|
35
|
+
const result = await manager.update(id, {
|
|
36
|
+
savedOn: new Date().toISOString()
|
|
37
|
+
});
|
|
38
|
+
return (0, _convertEntryToLockRecord.convertEntryToLockRecord)(result);
|
|
39
|
+
} catch (ex) {
|
|
40
|
+
throw new _error.WebinyError(`Could not update lock entry: ${ex.message}`, ex.code || "UPDATE_LOCK_ENTRY_ERROR", {
|
|
41
|
+
...ex.data
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.UpdateEntryLockUseCase = UpdateEntryLockUseCase;
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=UpdateEntryLockUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","require","_convertEntryToLockRecord","_lockRecordDatabaseId","_utils","_validateSameIdentity","UpdateEntryLockUseCase","constructor","params","getLockRecordUseCase","lockEntryUseCase","getManager","getIdentity","execute","record","validateSameIdentity","target","lockedBy","manager","entryId","createLockRecordDatabaseId","id","createIdentifier","version","result","update","savedOn","Date","toISOString","convertEntryToLockRecord","ex","WebinyError","message","code","data","exports"],"sources":["UpdateEntryLockUseCase.ts"],"sourcesContent":["import {\n IUpdateEntryLockUseCase,\n IUpdateEntryLockUseCaseExecuteParams\n} from \"~/abstractions/IUpdateEntryLockUseCase\";\nimport { IGetIdentity, IRecordLockingLockRecord, IRecordLockingModelManager } from \"~/types\";\nimport { IGetLockRecordUseCase } from \"~/abstractions/IGetLockRecordUseCase\";\nimport { WebinyError } from \"@webiny/error\";\nimport { convertEntryToLockRecord } from \"~/utils/convertEntryToLockRecord\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId\";\nimport { createIdentifier } from \"@webiny/utils\";\nimport { validateSameIdentity } from \"~/utils/validateSameIdentity\";\nimport { ILockEntryUseCase } from \"~/abstractions/ILockEntryUseCase\";\n\nexport interface IUpdateEntryLockUseCaseParams {\n readonly getLockRecordUseCase: IGetLockRecordUseCase;\n readonly lockEntryUseCase: ILockEntryUseCase;\n getManager(): Promise<IRecordLockingModelManager>;\n getIdentity: IGetIdentity;\n}\n\nexport class UpdateEntryLockUseCase implements IUpdateEntryLockUseCase {\n private readonly getLockRecordUseCase: IGetLockRecordUseCase;\n private readonly lockEntryUseCase: ILockEntryUseCase;\n private readonly getManager: () => Promise<IRecordLockingModelManager>;\n private readonly getIdentity: IGetIdentity;\n\n public constructor(params: IUpdateEntryLockUseCaseParams) {\n this.getLockRecordUseCase = params.getLockRecordUseCase;\n this.lockEntryUseCase = params.lockEntryUseCase;\n this.getManager = params.getManager;\n this.getIdentity = params.getIdentity;\n }\n\n public async execute(\n params: IUpdateEntryLockUseCaseExecuteParams\n ): Promise<IRecordLockingLockRecord> {\n const record = await this.getLockRecordUseCase.execute(params);\n if (!record) {\n return this.lockEntryUseCase.execute(params);\n }\n\n validateSameIdentity({\n getIdentity: this.getIdentity,\n target: record.lockedBy\n });\n\n try {\n const manager = await this.getManager();\n\n const entryId = createLockRecordDatabaseId(record.id);\n const id = createIdentifier({\n id: entryId,\n version: 1\n });\n const result = await manager.update(id, {\n savedOn: new Date().toISOString()\n });\n return convertEntryToLockRecord(result);\n } catch (ex) {\n throw new WebinyError(\n `Could not update lock entry: ${ex.message}`,\n ex.code || \"UPDATE_LOCK_ENTRY_ERROR\",\n {\n ...ex.data\n }\n );\n }\n }\n}\n"],"mappings":";;;;;;AAMA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,yBAAA,GAAAD,OAAA;AACA,IAAAE,qBAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,qBAAA,GAAAJ,OAAA;AAUO,MAAMK,sBAAsB,CAAoC;EAM5DC,WAAWA,CAACC,MAAqC,EAAE;IACtD,IAAI,CAACC,oBAAoB,GAAGD,MAAM,CAACC,oBAAoB;IACvD,IAAI,CAACC,gBAAgB,GAAGF,MAAM,CAACE,gBAAgB;IAC/C,IAAI,CAAC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elManager } from "../types";
|
|
2
|
+
import { IListAllLockRecordsUseCase } from "../abstractions/IListAllLockRecordsUseCase";
|
|
3
|
+
import { IListLockRecordsUseCase } from "../abstractions/IListLockRecordsUseCase";
|
|
4
|
+
import { IGetLockRecordUseCase } from "../abstractions/IGetLockRecordUseCase";
|
|
5
|
+
import { IIsEntryLockedUseCase } from "../abstractions/IIsEntryLocked";
|
|
6
|
+
import { IGetLockedEntryLockRecordUseCase } from "../abstractions/IGetLockedEntryLockRecordUseCase";
|
|
7
|
+
import { ILockEntryUseCase } from "../abstractions/ILockEntryUseCase";
|
|
8
|
+
import { IUpdateEntryLockUseCase } from "../abstractions/IUpdateEntryLockUseCase";
|
|
9
|
+
import { IUnlockEntryUseCase } from "../abstractions/IUnlockEntryUseCase";
|
|
10
|
+
import { IUnlockEntryRequestUseCase } from "../abstractions/IUnlockEntryRequestUseCase";
|
|
11
|
+
export interface ICreateUseCasesParams {
|
|
12
|
+
getIdentity: IGetIdentity;
|
|
13
|
+
getManager(): Promise<IRecordLockingModelManager>;
|
|
14
|
+
hasFullAccess: IHasFullAccessCallable;
|
|
15
|
+
getWebsockets: IGetWebsocketsContextCallable;
|
|
16
|
+
}
|
|
17
|
+
export interface ICreateUseCasesResponse {
|
|
18
|
+
listAllLockRecordsUseCase: IListAllLockRecordsUseCase;
|
|
19
|
+
listLockRecordsUseCase: IListLockRecordsUseCase;
|
|
20
|
+
getLockRecordUseCase: IGetLockRecordUseCase;
|
|
21
|
+
isEntryLockedUseCase: IIsEntryLockedUseCase;
|
|
22
|
+
getLockedEntryLockRecordUseCase: IGetLockedEntryLockRecordUseCase;
|
|
23
|
+
lockEntryUseCase: ILockEntryUseCase;
|
|
24
|
+
updateEntryLockUseCase: IUpdateEntryLockUseCase;
|
|
25
|
+
unlockEntryUseCase: IUnlockEntryUseCase;
|
|
26
|
+
unlockEntryRequestUseCase: IUnlockEntryRequestUseCase;
|
|
27
|
+
}
|
|
28
|
+
export declare const createUseCases: (params: ICreateUseCasesParams) => ICreateUseCasesResponse;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createUseCases = void 0;
|
|
7
|
+
var _GetLockRecordUseCase = require("./GetLockRecord/GetLockRecordUseCase");
|
|
8
|
+
var _IsEntryLockedUseCase = require("./IsEntryLocked/IsEntryLockedUseCase");
|
|
9
|
+
var _LockEntryUseCase = require("./LockEntryUseCase/LockEntryUseCase");
|
|
10
|
+
var _UnlockEntryUseCase = require("./UnlockEntryUseCase/UnlockEntryUseCase");
|
|
11
|
+
var _UnlockEntryRequestUseCase = require("./UnlockRequestUseCase/UnlockEntryRequestUseCase");
|
|
12
|
+
var _ListAllLockRecordsUseCase = require("./ListAllLockRecordsUseCase/ListAllLockRecordsUseCase");
|
|
13
|
+
var _ListLockRecordsUseCase = require("./ListLockRecordsUseCase/ListLockRecordsUseCase");
|
|
14
|
+
var _isLockedFactory = require("../utils/isLockedFactory");
|
|
15
|
+
var _UpdateEntryLockUseCase = require("./UpdateEntryLock/UpdateEntryLockUseCase");
|
|
16
|
+
var _getTimeout = require("../utils/getTimeout");
|
|
17
|
+
var _KickOutCurrentUserUseCase = require("./KickOutCurrentUser/KickOutCurrentUserUseCase");
|
|
18
|
+
var _GetLockedEntryLockRecordUseCase = require("./GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase");
|
|
19
|
+
const createUseCases = params => {
|
|
20
|
+
const timeout = (0, _getTimeout.getTimeout)();
|
|
21
|
+
const isLocked = (0, _isLockedFactory.isLockedFactory)(timeout);
|
|
22
|
+
const listAllLockRecordsUseCase = new _ListAllLockRecordsUseCase.ListAllLockRecordsUseCase({
|
|
23
|
+
getManager: params.getManager
|
|
24
|
+
});
|
|
25
|
+
const listLockRecordsUseCase = new _ListLockRecordsUseCase.ListLockRecordsUseCase({
|
|
26
|
+
listAllLockRecordsUseCase,
|
|
27
|
+
timeout,
|
|
28
|
+
getIdentity: params.getIdentity
|
|
29
|
+
});
|
|
30
|
+
const getLockRecordUseCase = new _GetLockRecordUseCase.GetLockRecordUseCase({
|
|
31
|
+
getManager: params.getManager
|
|
32
|
+
});
|
|
33
|
+
const isEntryLockedUseCase = new _IsEntryLockedUseCase.IsEntryLockedUseCase({
|
|
34
|
+
getLockRecordUseCase,
|
|
35
|
+
isLocked,
|
|
36
|
+
getIdentity: params.getIdentity
|
|
37
|
+
});
|
|
38
|
+
const getLockedEntryLockRecordUseCase = new _GetLockedEntryLockRecordUseCase.GetLockedEntryLockRecordUseCase({
|
|
39
|
+
getLockRecordUseCase,
|
|
40
|
+
isLocked,
|
|
41
|
+
getIdentity: params.getIdentity
|
|
42
|
+
});
|
|
43
|
+
const lockEntryUseCase = new _LockEntryUseCase.LockEntryUseCase({
|
|
44
|
+
isEntryLockedUseCase,
|
|
45
|
+
getManager: params.getManager
|
|
46
|
+
});
|
|
47
|
+
const updateEntryLockUseCase = new _UpdateEntryLockUseCase.UpdateEntryLockUseCase({
|
|
48
|
+
getLockRecordUseCase,
|
|
49
|
+
lockEntryUseCase,
|
|
50
|
+
getManager: params.getManager,
|
|
51
|
+
getIdentity: params.getIdentity
|
|
52
|
+
});
|
|
53
|
+
const kickOutCurrentUserUseCase = new _KickOutCurrentUserUseCase.KickOutCurrentUserUseCase({
|
|
54
|
+
getWebsockets: params.getWebsockets,
|
|
55
|
+
getIdentity: params.getIdentity
|
|
56
|
+
});
|
|
57
|
+
const unlockEntryUseCase = new _UnlockEntryUseCase.UnlockEntryUseCase({
|
|
58
|
+
getLockRecordUseCase,
|
|
59
|
+
kickOutCurrentUserUseCase,
|
|
60
|
+
getManager: params.getManager,
|
|
61
|
+
getIdentity: params.getIdentity,
|
|
62
|
+
hasFullAccess: params.hasFullAccess
|
|
63
|
+
});
|
|
64
|
+
const unlockEntryRequestUseCase = new _UnlockEntryRequestUseCase.UnlockEntryRequestUseCase({
|
|
65
|
+
getLockRecordUseCase,
|
|
66
|
+
getIdentity: params.getIdentity,
|
|
67
|
+
getManager: params.getManager
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
listAllLockRecordsUseCase,
|
|
71
|
+
listLockRecordsUseCase,
|
|
72
|
+
getLockRecordUseCase,
|
|
73
|
+
isEntryLockedUseCase,
|
|
74
|
+
getLockedEntryLockRecordUseCase,
|
|
75
|
+
lockEntryUseCase,
|
|
76
|
+
updateEntryLockUseCase,
|
|
77
|
+
unlockEntryUseCase,
|
|
78
|
+
unlockEntryRequestUseCase
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
exports.createUseCases = createUseCases;
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_GetLockRecordUseCase","require","_IsEntryLockedUseCase","_LockEntryUseCase","_UnlockEntryUseCase","_UnlockEntryRequestUseCase","_ListAllLockRecordsUseCase","_ListLockRecordsUseCase","_isLockedFactory","_UpdateEntryLockUseCase","_getTimeout","_KickOutCurrentUserUseCase","_GetLockedEntryLockRecordUseCase","createUseCases","params","timeout","getTimeout","isLocked","isLockedFactory","listAllLockRecordsUseCase","ListAllLockRecordsUseCase","getManager","listLockRecordsUseCase","ListLockRecordsUseCase","getIdentity","getLockRecordUseCase","GetLockRecordUseCase","isEntryLockedUseCase","IsEntryLockedUseCase","getLockedEntryLockRecordUseCase","GetLockedEntryLockRecordUseCase","lockEntryUseCase","LockEntryUseCase","updateEntryLockUseCase","UpdateEntryLockUseCase","kickOutCurrentUserUseCase","KickOutCurrentUserUseCase","getWebsockets","unlockEntryUseCase","UnlockEntryUseCase","hasFullAccess","unlockEntryRequestUseCase","UnlockEntryRequestUseCase","exports"],"sources":["index.ts"],"sourcesContent":["import {\n IGetIdentity,\n IGetWebsocketsContextCallable,\n IHasFullAccessCallable,\n IRecordLockingModelManager\n} from \"~/types\";\nimport { GetLockRecordUseCase } from \"./GetLockRecord/GetLockRecordUseCase\";\nimport { IsEntryLockedUseCase } from \"./IsEntryLocked/IsEntryLockedUseCase\";\nimport { LockEntryUseCase } from \"./LockEntryUseCase/LockEntryUseCase\";\nimport { UnlockEntryUseCase } from \"./UnlockEntryUseCase/UnlockEntryUseCase\";\nimport { UnlockEntryRequestUseCase } from \"./UnlockRequestUseCase/UnlockEntryRequestUseCase\";\nimport { ListAllLockRecordsUseCase } from \"./ListAllLockRecordsUseCase/ListAllLockRecordsUseCase\";\nimport { ListLockRecordsUseCase } from \"./ListLockRecordsUseCase/ListLockRecordsUseCase\";\nimport { isLockedFactory } from \"~/utils/isLockedFactory\";\nimport { UpdateEntryLockUseCase } from \"~/useCases/UpdateEntryLock/UpdateEntryLockUseCase\";\nimport { getTimeout } from \"~/utils/getTimeout\";\nimport { KickOutCurrentUserUseCase } from \"./KickOutCurrentUser/KickOutCurrentUserUseCase\";\nimport { GetLockedEntryLockRecordUseCase } from \"~/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase\";\nimport { IListAllLockRecordsUseCase } from \"~/abstractions/IListAllLockRecordsUseCase\";\nimport { IListLockRecordsUseCase } from \"~/abstractions/IListLockRecordsUseCase\";\nimport { IGetLockRecordUseCase } from \"~/abstractions/IGetLockRecordUseCase\";\nimport { IIsEntryLockedUseCase } from \"~/abstractions/IIsEntryLocked\";\nimport { IGetLockedEntryLockRecordUseCase } from \"~/abstractions/IGetLockedEntryLockRecordUseCase\";\nimport { ILockEntryUseCase } from \"~/abstractions/ILockEntryUseCase\";\nimport { IUpdateEntryLockUseCase } from \"~/abstractions/IUpdateEntryLockUseCase\";\nimport { IUnlockEntryUseCase } from \"~/abstractions/IUnlockEntryUseCase\";\nimport { IUnlockEntryRequestUseCase } from \"~/abstractions/IUnlockEntryRequestUseCase\";\n\nexport interface ICreateUseCasesParams {\n getIdentity: IGetIdentity;\n getManager(): Promise<IRecordLockingModelManager>;\n hasFullAccess: IHasFullAccessCallable;\n getWebsockets: IGetWebsocketsContextCallable;\n}\n\nexport interface ICreateUseCasesResponse {\n listAllLockRecordsUseCase: IListAllLockRecordsUseCase;\n listLockRecordsUseCase: IListLockRecordsUseCase;\n getLockRecordUseCase: IGetLockRecordUseCase;\n isEntryLockedUseCase: IIsEntryLockedUseCase;\n getLockedEntryLockRecordUseCase: IGetLockedEntryLockRecordUseCase;\n lockEntryUseCase: ILockEntryUseCase;\n updateEntryLockUseCase: IUpdateEntryLockUseCase;\n unlockEntryUseCase: IUnlockEntryUseCase;\n unlockEntryRequestUseCase: IUnlockEntryRequestUseCase;\n}\n\nexport const createUseCases = (params: ICreateUseCasesParams): ICreateUseCasesResponse => {\n const timeout = getTimeout();\n const isLocked = isLockedFactory(timeout);\n\n const listAllLockRecordsUseCase = new ListAllLockRecordsUseCase({\n getManager: params.getManager\n });\n\n const listLockRecordsUseCase = new ListLockRecordsUseCase({\n listAllLockRecordsUseCase,\n timeout,\n getIdentity: params.getIdentity\n });\n\n const getLockRecordUseCase = new GetLockRecordUseCase({\n getManager: params.getManager\n });\n\n const isEntryLockedUseCase = new IsEntryLockedUseCase({\n getLockRecordUseCase,\n isLocked,\n getIdentity: params.getIdentity\n });\n\n const getLockedEntryLockRecordUseCase = new GetLockedEntryLockRecordUseCase({\n getLockRecordUseCase,\n isLocked,\n getIdentity: params.getIdentity\n });\n\n const lockEntryUseCase = new LockEntryUseCase({\n isEntryLockedUseCase,\n getManager: params.getManager\n });\n\n const updateEntryLockUseCase = new UpdateEntryLockUseCase({\n getLockRecordUseCase,\n lockEntryUseCase,\n getManager: params.getManager,\n getIdentity: params.getIdentity\n });\n\n const kickOutCurrentUserUseCase = new KickOutCurrentUserUseCase({\n getWebsockets: params.getWebsockets,\n getIdentity: params.getIdentity\n });\n\n const unlockEntryUseCase = new UnlockEntryUseCase({\n getLockRecordUseCase,\n kickOutCurrentUserUseCase,\n getManager: params.getManager,\n getIdentity: params.getIdentity,\n hasFullAccess: params.hasFullAccess\n });\n\n const unlockEntryRequestUseCase = new UnlockEntryRequestUseCase({\n getLockRecordUseCase,\n getIdentity: params.getIdentity,\n getManager: params.getManager\n });\n\n return {\n listAllLockRecordsUseCase,\n listLockRecordsUseCase,\n getLockRecordUseCase,\n isEntryLockedUseCase,\n getLockedEntryLockRecordUseCase,\n lockEntryUseCase,\n updateEntryLockUseCase,\n unlockEntryUseCase,\n unlockEntryRequestUseCase\n };\n};\n"],"mappings":";;;;;;AAMA,IAAAA,qBAAA,GAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,0BAAA,GAAAJ,OAAA;AACA,IAAAK,0BAAA,GAAAL,OAAA;AACA,IAAAM,uBAAA,GAAAN,OAAA;AACA,IAAAO,gBAAA,GAAAP,OAAA;AACA,IAAAQ,uBAAA,GAAAR,OAAA;AACA,IAAAS,WAAA,GAAAT,OAAA;AACA,IAAAU,0BAAA,GAAAV,OAAA;AACA,IAAAW,gCAAA,GAAAX,OAAA;AA8BO,MAAMY,cAAc,GAAIC,MAA6B,IAA8B;EACtF,MAAMC,OAAO,GAAG,IAAAC,sBAAU,EAAC,CAAC;EAC5B,MAAMC,QAAQ,GAAG,IAAAC,gCAAe,EAACH,OAAO,CAAC;EAEzC,MAAMI,yBAAyB,GAAG,IAAIC,oDAAyB,CAAC;IAC5DC,UAAU,EAAEP,MAAM,CAACO;EACvB,CAAC,CAAC;EAEF,MAAMC,sBAAsB,GAAG,IAAIC,8CAAsB,CAAC;IACtDJ,yBAAyB;IACzBJ,OAAO;IACPS,WAAW,EAAEV,MAAM,CAACU;EACxB,CAAC,CAAC;EAEF,MAAMC,oBAAoB,GAAG,IAAIC,0CAAoB,CAAC;IAClDL,UAAU,EAAEP,MAAM,CAACO;EACvB,CAAC,CAAC;EAEF,MAAMM,oBAAoB,GAAG,IAAIC,0CAAoB,CAAC;IAClDH,oBAAoB;IACpBR,QAAQ;IACRO,WAAW,EAAE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|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.calculateExpiresOn = void 0;
|
|
7
|
+
var _getTimeout = require("./getTimeout");
|
|
8
|
+
const calculateExpiresOn = input => {
|
|
9
|
+
const timeout = (0, _getTimeout.getTimeout)();
|
|
10
|
+
const savedOn = new Date(input.savedOn);
|
|
11
|
+
return new Date(savedOn.getTime() + timeout);
|
|
12
|
+
};
|
|
13
|
+
exports.calculateExpiresOn = calculateExpiresOn;
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=calculateExpiresOn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_getTimeout","require","calculateExpiresOn","input","timeout","getTimeout","savedOn","Date","getTime","exports"],"sources":["calculateExpiresOn.ts"],"sourcesContent":["import { IHeadlessCmsLockRecordParams } from \"./convertEntryToLockRecord\";\nimport { getTimeout } from \"./getTimeout\";\n\nexport const calculateExpiresOn = (input: Pick<IHeadlessCmsLockRecordParams, \"savedOn\">): Date => {\n const timeout = getTimeout();\n\n const savedOn = new Date(input.savedOn);\n\n return new Date(savedOn.getTime() + timeout);\n};\n"],"mappings":";;;;;;AACA,IAAAA,WAAA,GAAAC,OAAA;AAEO,MAAMC,kBAAkB,GAAIC,KAAoD,IAAW;EAC9F,MAAMC,OAAO,GAAG,IAAAC,sBAAU,EAAC,CAAC;EAE5B,MAAMC,OAAO,GAAG,IAAIC,IAAI,CAACJ,KAAK,CAACG,OAAO,CAAC;EAEvC,OAAO,IAAIC,IAAI,CAACD,OAAO,CAACE,OAAO,CAAC,CAAC,GAAGJ,OAAO,CAAC;AAChD,CAAC;AAACK,OAAA,CAAAP,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.checkPermissions = void 0;
|
|
7
|
+
var _apiSecurity = require("@webiny/api-security");
|
|
8
|
+
/**
|
|
9
|
+
* Simple permission check. Only full access can access the websockets API via GraphQL - ({name: "*"})
|
|
10
|
+
*
|
|
11
|
+
* @throws
|
|
12
|
+
*/
|
|
13
|
+
const checkPermissions = async context => {
|
|
14
|
+
const identity = context.security.getIdentity();
|
|
15
|
+
if (!identity.id) {
|
|
16
|
+
throw new _apiSecurity.NotAuthorizedError();
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.checkPermissions = checkPermissions;
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=checkPermissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_apiSecurity","require","checkPermissions","context","identity","security","getIdentity","id","NotAuthorizedError","exports"],"sources":["checkPermissions.ts"],"sourcesContent":["import { NotAuthorizedError } from \"@webiny/api-security\";\nimport { Context } from \"~/types\";\n\n/**\n * Simple permission check. Only full access can access the websockets API via GraphQL - ({name: \"*\"})\n *\n * @throws\n */\nexport const checkPermissions = async (context: Pick<Context, \"security\">): Promise<void> => {\n const identity = context.security.getIdentity();\n if (!identity.id) {\n throw new NotAuthorizedError();\n }\n};\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAGA;AACA;AACA;AACA;AACA;AACO,MAAMC,gBAAgB,GAAG,MAAOC,OAAkC,IAAoB;EACzF,MAAMC,QAAQ,GAAGD,OAAO,CAACE,QAAQ,CAACC,WAAW,CAAC,CAAC;EAC/C,IAAI,CAACF,QAAQ,CAACG,EAAE,EAAE;IACd,MAAM,IAAIC,+BAAkB,CAAC,CAAC;EAClC;AACJ,CAAC;AAACC,OAAA,CAAAP,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CmsEntry, IRecordLockingIdentity } from "../types";
|
|
2
|
+
import { IRecordLockingLockRecord, IRecordLockingLockRecordAction, IRecordLockingLockRecordApprovedAction, IRecordLockingLockRecordDeniedAction, IRecordLockingLockRecordEntryType, IRecordLockingLockRecordObject, IRecordLockingLockRecordRequestedAction, IRecordLockingLockRecordValues } from "../types";
|
|
3
|
+
export declare const convertEntryToLockRecord: (entry: CmsEntry<IRecordLockingLockRecordValues>) => IRecordLockingLockRecord;
|
|
4
|
+
export declare type IHeadlessCmsLockRecordParams = Pick<CmsEntry<IRecordLockingLockRecordValues>, "entryId" | "values" | "createdBy" | "createdOn" | "savedOn">;
|
|
5
|
+
export declare class HeadlessCmsLockRecord implements IRecordLockingLockRecord {
|
|
6
|
+
private readonly _id;
|
|
7
|
+
private readonly _targetId;
|
|
8
|
+
private readonly _type;
|
|
9
|
+
private readonly _lockedBy;
|
|
10
|
+
private readonly _lockedOn;
|
|
11
|
+
private readonly _updatedOn;
|
|
12
|
+
private readonly _expiresOn;
|
|
13
|
+
private _actions?;
|
|
14
|
+
get id(): string;
|
|
15
|
+
get targetId(): string;
|
|
16
|
+
get type(): IRecordLockingLockRecordEntryType;
|
|
17
|
+
get lockedBy(): IRecordLockingIdentity;
|
|
18
|
+
get lockedOn(): Date;
|
|
19
|
+
get updatedOn(): Date;
|
|
20
|
+
get expiresOn(): Date;
|
|
21
|
+
get actions(): IRecordLockingLockRecordAction[] | undefined;
|
|
22
|
+
constructor(input: IHeadlessCmsLockRecordParams);
|
|
23
|
+
toObject(): IRecordLockingLockRecordObject;
|
|
24
|
+
addAction(action: IRecordLockingLockRecordAction): void;
|
|
25
|
+
getUnlockRequested(): IRecordLockingLockRecordRequestedAction | undefined;
|
|
26
|
+
getUnlockApproved(): IRecordLockingLockRecordApprovedAction | undefined;
|
|
27
|
+
getUnlockDenied(): IRecordLockingLockRecordDeniedAction | undefined;
|
|
28
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.convertEntryToLockRecord = exports.HeadlessCmsLockRecord = void 0;
|
|
7
|
+
var _types = require("../types");
|
|
8
|
+
var _lockRecordDatabaseId = require("./lockRecordDatabaseId");
|
|
9
|
+
var _calculateExpiresOn = require("./calculateExpiresOn");
|
|
10
|
+
const convertEntryToLockRecord = entry => {
|
|
11
|
+
return new HeadlessCmsLockRecord(entry);
|
|
12
|
+
};
|
|
13
|
+
exports.convertEntryToLockRecord = convertEntryToLockRecord;
|
|
14
|
+
class HeadlessCmsLockRecord {
|
|
15
|
+
get id() {
|
|
16
|
+
return this._id;
|
|
17
|
+
}
|
|
18
|
+
get targetId() {
|
|
19
|
+
return this._targetId;
|
|
20
|
+
}
|
|
21
|
+
get type() {
|
|
22
|
+
return this._type;
|
|
23
|
+
}
|
|
24
|
+
get lockedBy() {
|
|
25
|
+
return this._lockedBy;
|
|
26
|
+
}
|
|
27
|
+
get lockedOn() {
|
|
28
|
+
return this._lockedOn;
|
|
29
|
+
}
|
|
30
|
+
get updatedOn() {
|
|
31
|
+
return this._updatedOn;
|
|
32
|
+
}
|
|
33
|
+
get expiresOn() {
|
|
34
|
+
return this._expiresOn;
|
|
35
|
+
}
|
|
36
|
+
get actions() {
|
|
37
|
+
return this._actions;
|
|
38
|
+
}
|
|
39
|
+
constructor(input) {
|
|
40
|
+
this._id = (0, _lockRecordDatabaseId.removeLockRecordDatabasePrefix)(input.entryId);
|
|
41
|
+
this._targetId = input.values.targetId;
|
|
42
|
+
this._type = input.values.type;
|
|
43
|
+
this._lockedBy = input.createdBy;
|
|
44
|
+
this._lockedOn = new Date(input.createdOn);
|
|
45
|
+
this._updatedOn = new Date(input.savedOn);
|
|
46
|
+
this._expiresOn = (0, _calculateExpiresOn.calculateExpiresOn)(input);
|
|
47
|
+
this._actions = input.values.actions;
|
|
48
|
+
}
|
|
49
|
+
toObject() {
|
|
50
|
+
return {
|
|
51
|
+
id: this._id,
|
|
52
|
+
targetId: this._targetId,
|
|
53
|
+
type: this._type,
|
|
54
|
+
lockedBy: this._lockedBy,
|
|
55
|
+
lockedOn: this._lockedOn,
|
|
56
|
+
updatedOn: this._updatedOn,
|
|
57
|
+
expiresOn: this._expiresOn,
|
|
58
|
+
actions: this._actions
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
addAction(action) {
|
|
62
|
+
if (!this._actions) {
|
|
63
|
+
this._actions = [];
|
|
64
|
+
}
|
|
65
|
+
this._actions.push(action);
|
|
66
|
+
}
|
|
67
|
+
getUnlockRequested() {
|
|
68
|
+
if (!this._actions?.length) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
return this._actions.find(action => action.type === _types.IRecordLockingLockRecordActionType.requested);
|
|
72
|
+
}
|
|
73
|
+
getUnlockApproved() {
|
|
74
|
+
if (!this._actions?.length) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
return this._actions.find(action => action.type === _types.IRecordLockingLockRecordActionType.approved);
|
|
78
|
+
}
|
|
79
|
+
getUnlockDenied() {
|
|
80
|
+
if (!this._actions?.length) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
return this._actions.find(action => action.type === _types.IRecordLockingLockRecordActionType.denied);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.HeadlessCmsLockRecord = HeadlessCmsLockRecord;
|
|
87
|
+
|
|
88
|
+
//# sourceMappingURL=convertEntryToLockRecord.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_types","require","_lockRecordDatabaseId","_calculateExpiresOn","convertEntryToLockRecord","entry","HeadlessCmsLockRecord","exports","id","_id","targetId","_targetId","type","_type","lockedBy","_lockedBy","lockedOn","_lockedOn","updatedOn","_updatedOn","expiresOn","_expiresOn","actions","_actions","constructor","input","removeLockRecordDatabasePrefix","entryId","values","createdBy","Date","createdOn","savedOn","calculateExpiresOn","toObject","addAction","action","push","getUnlockRequested","length","undefined","find","IRecordLockingLockRecordActionType","requested","getUnlockApproved","approved","getUnlockDenied","denied"],"sources":["convertEntryToLockRecord.ts"],"sourcesContent":["import { CmsEntry, IRecordLockingIdentity } from \"~/types\";\nimport {\n IRecordLockingLockRecord,\n IRecordLockingLockRecordAction,\n IRecordLockingLockRecordActionType,\n IRecordLockingLockRecordApprovedAction,\n IRecordLockingLockRecordDeniedAction,\n IRecordLockingLockRecordEntryType,\n IRecordLockingLockRecordObject,\n IRecordLockingLockRecordRequestedAction,\n IRecordLockingLockRecordValues\n} from \"~/types\";\nimport { removeLockRecordDatabasePrefix } from \"~/utils/lockRecordDatabaseId\";\nimport { calculateExpiresOn } from \"~/utils/calculateExpiresOn\";\n\nexport const convertEntryToLockRecord = (\n entry: CmsEntry<IRecordLockingLockRecordValues>\n): IRecordLockingLockRecord => {\n return new HeadlessCmsLockRecord(entry);\n};\n\nexport type IHeadlessCmsLockRecordParams = Pick<\n CmsEntry<IRecordLockingLockRecordValues>,\n \"entryId\" | \"values\" | \"createdBy\" | \"createdOn\" | \"savedOn\"\n>;\n\nexport class HeadlessCmsLockRecord implements IRecordLockingLockRecord {\n private readonly _id: string;\n private readonly _targetId: string;\n private readonly _type: IRecordLockingLockRecordEntryType;\n private readonly _lockedBy: IRecordLockingIdentity;\n private readonly _lockedOn: Date;\n private readonly _updatedOn: Date;\n private readonly _expiresOn: Date;\n private _actions?: IRecordLockingLockRecordAction[];\n\n public get id(): string {\n return this._id;\n }\n\n public get targetId(): string {\n return this._targetId;\n }\n\n public get type(): IRecordLockingLockRecordEntryType {\n return this._type;\n }\n\n public get lockedBy(): IRecordLockingIdentity {\n return this._lockedBy;\n }\n\n public get lockedOn(): Date {\n return this._lockedOn;\n }\n\n public get updatedOn(): Date {\n return this._updatedOn;\n }\n\n public get expiresOn(): Date {\n return this._expiresOn;\n }\n\n public get actions(): IRecordLockingLockRecordAction[] | undefined {\n return this._actions;\n }\n\n public constructor(input: IHeadlessCmsLockRecordParams) {\n this._id = removeLockRecordDatabasePrefix(input.entryId);\n this._targetId = input.values.targetId;\n this._type = input.values.type;\n this._lockedBy = input.createdBy;\n this._lockedOn = new Date(input.createdOn);\n this._updatedOn = new Date(input.savedOn);\n this._expiresOn = calculateExpiresOn(input);\n this._actions = input.values.actions;\n }\n\n public toObject(): IRecordLockingLockRecordObject {\n return {\n id: this._id,\n targetId: this._targetId,\n type: this._type,\n lockedBy: this._lockedBy,\n lockedOn: this._lockedOn,\n updatedOn: this._updatedOn,\n expiresOn: this._expiresOn,\n actions: this._actions\n };\n }\n\n public addAction(action: IRecordLockingLockRecordAction) {\n if (!this._actions) {\n this._actions = [];\n }\n this._actions.push(action);\n }\n\n public getUnlockRequested(): IRecordLockingLockRecordRequestedAction | undefined {\n if (!this._actions?.length) {\n return undefined;\n }\n return this._actions.find(\n (action): action is IRecordLockingLockRecordRequestedAction =>\n action.type === IRecordLockingLockRecordActionType.requested\n );\n }\n\n public getUnlockApproved(): IRecordLockingLockRecordApprovedAction | undefined {\n if (!this._actions?.length) {\n return undefined;\n }\n return this._actions.find(\n (action): action is IRecordLockingLockRecordApprovedAction =>\n action.type === IRecordLockingLockRecordActionType.approved\n );\n }\n\n public getUnlockDenied(): IRecordLockingLockRecordDeniedAction | undefined {\n if (!this._actions?.length) {\n return undefined;\n }\n return this._actions.find(\n (action): action is IRecordLockingLockRecordDeniedAction =>\n action.type === IRecordLockingLockRecordActionType.denied\n );\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAWA,IAAAC,qBAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AAEO,MAAMG,wBAAwB,GACjCC,KAA+C,IACpB;EAC3B,OAAO,IAAIC,qBAAqB,CAACD,KAAK,CAAC;AAC3C,CAAC;AAACE,OAAA,CAAAH,wBAAA,GAAAA,wBAAA;AAOK,MAAME,qBAAqB,CAAqC;EAUnE,IAAWE,EAAEA,CAAA,EAAW;IACpB,OAAO,IAAI,CAACC,GAAG;EACnB;EAEA,IAAWC,QAAQA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
|
5
|
+
});
|
|
6
|
+
exports.convertWhereCondition = void 0;
|
|
7
|
+
var _lockRecordDatabaseId = require("./lockRecordDatabaseId");
|
|
8
|
+
const attachPrefix = value => {
|
|
9
|
+
if (!value) {
|
|
10
|
+
return value;
|
|
11
|
+
} else if (Array.isArray(value)) {
|
|
12
|
+
return value.map(_lockRecordDatabaseId.createLockRecordDatabaseId);
|
|
13
|
+
}
|
|
14
|
+
return (0, _lockRecordDatabaseId.createLockRecordDatabaseId)(value);
|
|
15
|
+
};
|
|
16
|
+
const convertWhereCondition = where => {
|
|
17
|
+
if (!where) {
|
|
18
|
+
return where;
|
|
19
|
+
}
|
|
20
|
+
for (const key in where) {
|
|
21
|
+
if (key.startsWith("AND") || key.startsWith("OR")) {
|
|
22
|
+
const value = where[key];
|
|
23
|
+
if (!value) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
for (const subKey in value) {
|
|
27
|
+
value[subKey] = convertWhereCondition(value[subKey]);
|
|
28
|
+
}
|
|
29
|
+
continue;
|
|
30
|
+
} else if (key.startsWith("id") === false) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const newKey = key.replace("id", "entryId");
|
|
34
|
+
where[newKey] = attachPrefix(where[key]);
|
|
35
|
+
delete where[key];
|
|
36
|
+
}
|
|
37
|
+
return where;
|
|
38
|
+
};
|
|
39
|
+
exports.convertWhereCondition = convertWhereCondition;
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=convertWhereCondition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_lockRecordDatabaseId","require","attachPrefix","value","Array","isArray","map","createLockRecordDatabaseId","convertWhereCondition","where","key","startsWith","subKey","newKey","replace","exports"],"sources":["convertWhereCondition.ts"],"sourcesContent":["import { IRecordLockingListLockRecordsParams } from \"~/types\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId\";\n\ntype IWhere = IRecordLockingListLockRecordsParams[\"where\"] | undefined;\n\nconst attachPrefix = (value: string | string[] | undefined) => {\n if (!value) {\n return value;\n } else if (Array.isArray(value)) {\n return value.map(createLockRecordDatabaseId);\n }\n return createLockRecordDatabaseId(value);\n};\n\nexport const convertWhereCondition = (where: IWhere): IWhere => {\n if (!where) {\n return where;\n }\n for (const key in where) {\n if (key.startsWith(\"AND\") || key.startsWith(\"OR\")) {\n const value = where[key] as IWhere[] | undefined;\n if (!value) {\n continue;\n }\n for (const subKey in value) {\n value[subKey] = convertWhereCondition(value[subKey]);\n }\n continue;\n } else if (key.startsWith(\"id\") === false) {\n continue;\n }\n const newKey = key.replace(\"id\", \"entryId\");\n where[newKey] = attachPrefix(where[key] as string | string[] | undefined);\n delete where[key];\n }\n return where;\n};\n"],"mappings":";;;;;;AACA,IAAAA,qBAAA,GAAAC,OAAA;AAIA,MAAMC,YAAY,GAAIC,KAAoC,IAAK;EAC3D,IAAI,CAACA,KAAK,EAAE;IACR,OAAOA,KAAK;EAChB,CAAC,MAAM,IAAIC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,EAAE;IAC7B,OAAOA,KAAK,CAACG,GAAG,CAACC,gDAA0B,CAAC;EAChD;EACA,OAAO,IAAAA,gDAA0B,EAACJ,KAAK,CAAC;AAC5C,CAAC;AAEM,MAAMK,qBAAqB,GAAIC,KAAa,IAAa;EAC5D,IAAI,CAACA,KAAK,EAAE;IACR,OAAOA,KAAK;EAChB;EACA,KAAK,MAAMC,GAAG,IAAID,KAAK,EAAE;IACrB,IAAIC,GAAG,CAACC,UAAU,CAAC,KAAK,CAAC,IAAID,GAAG,CAACC,UAAU,CAAC,IAAI,CAAC,EAAE;MAC/C,MAAMR,KAAK,GAAGM,KAAK,CAACC,GAAG,CAAyB;MAChD,IAAI,CAACP,KAAK,EAAE;QACR;MACJ;MACA,KAAK,MAAMS,MAAM,IAAIT,KAAK,EAAE;QACxBA,KAAK,CAACS,MAAM,CAAC,GAAGJ,qBAAqB,CAACL,KAAK,CAACS,MAAM,CAAC,CAAC;MACxD;MACA;IACJ,CAAC,MAAM,IAAIF,GAAG,CAACC,UAAU,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE;MACvC;IACJ;IACA,MAAME,MAAM,GAAGH,GAAG,CAACI,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC;IAC3CL,KAAK,CAACI,MAAM,CAAC,GAAGX,YAAY,CAACO,KAAK,CAACC,GAAG,CAAkC,CAAC;IACzE,OAAOD,KAAK,CAACC,GAAG,CAAC;EACrB;EACA,OAAOD,KAAK;AAChB,CAAC;AAACM,OAAA,CAAAP,qBAAA,GAAAA,qBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getTimeout = void 0;
|
|
7
|
+
const defaultTimeoutInSeconds = 1800;
|
|
8
|
+
/**
|
|
9
|
+
* In milliseconds.
|
|
10
|
+
*/
|
|
11
|
+
const getTimeout = () => {
|
|
12
|
+
const userDefined = process.env.WEBINY_RECORD_LOCK_TIMEOUT ? parseInt(process.env.WEBINY_RECORD_LOCK_TIMEOUT) : undefined;
|
|
13
|
+
if (!userDefined || isNaN(userDefined) || userDefined <= 0) {
|
|
14
|
+
return defaultTimeoutInSeconds * 1000;
|
|
15
|
+
}
|
|
16
|
+
return userDefined * 1000;
|
|
17
|
+
};
|
|
18
|
+
exports.getTimeout = getTimeout;
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=getTimeout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["defaultTimeoutInSeconds","getTimeout","userDefined","process","env","WEBINY_RECORD_LOCK_TIMEOUT","parseInt","undefined","isNaN","exports"],"sources":["getTimeout.ts"],"sourcesContent":["const defaultTimeoutInSeconds = 1800;\n/**\n * In milliseconds.\n */\nexport const getTimeout = () => {\n const userDefined = process.env.WEBINY_RECORD_LOCK_TIMEOUT\n ? parseInt(process.env.WEBINY_RECORD_LOCK_TIMEOUT)\n : undefined;\n if (!userDefined || isNaN(userDefined) || userDefined <= 0) {\n return defaultTimeoutInSeconds * 1000;\n }\n return userDefined * 1000;\n};\n"],"mappings":";;;;;;AAAA,MAAMA,uBAAuB,GAAG,IAAI;AACpC;AACA;AACA;AACO,MAAMC,UAAU,GAAGA,CAAA,KAAM;EAC5B,MAAMC,WAAW,GAAGC,OAAO,CAACC,GAAG,CAACC,0BAA0B,GACpDC,QAAQ,CAACH,OAAO,CAACC,GAAG,CAACC,0BAA0B,CAAC,GAChDE,SAAS;EACf,IAAI,CAACL,WAAW,IAAIM,KAAK,CAACN,WAAW,CAAC,IAAIA,WAAW,IAAI,CAAC,EAAE;IACxD,OAAOF,uBAAuB,GAAG,IAAI;EACzC;EACA,OAAOE,WAAW,GAAG,IAAI;AAC7B,CAAC;AAACO,OAAA,CAAAR,UAAA,GAAAA,UAAA","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isLockedFactory = void 0;
|
|
7
|
+
const isLockedFactory = timeoutInput => {
|
|
8
|
+
const timeout = timeoutInput * 1000;
|
|
9
|
+
return record => {
|
|
10
|
+
if (!record || record.lockedOn instanceof Date === false) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const now = new Date().getTime();
|
|
14
|
+
const lockedOn = record.lockedOn.getTime();
|
|
15
|
+
return lockedOn + timeout >= now;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
exports.isLockedFactory = isLockedFactory;
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=isLockedFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isLockedFactory","timeoutInput","timeout","record","lockedOn","Date","now","getTime","exports"],"sources":["isLockedFactory.ts"],"sourcesContent":["import { IRecordLockingLockRecord } from \"~/types\";\n\nexport interface IIsLocked {\n (record?: Pick<IRecordLockingLockRecord, \"lockedOn\"> | null): boolean;\n}\n\nexport const isLockedFactory = (timeoutInput: number): IIsLocked => {\n const timeout = timeoutInput * 1000;\n return record => {\n if (!record || record.lockedOn instanceof Date === false) {\n return false;\n }\n const now = new Date().getTime();\n const lockedOn = record.lockedOn.getTime();\n return lockedOn + timeout >= now;\n };\n};\n"],"mappings":";;;;;;AAMO,MAAMA,eAAe,GAAIC,YAAoB,IAAgB;EAChE,MAAMC,OAAO,GAAGD,YAAY,GAAG,IAAI;EACnC,OAAOE,MAAM,IAAI;IACb,IAAI,CAACA,MAAM,IAAIA,MAAM,CAACC,QAAQ,YAAYC,IAAI,KAAK,KAAK,EAAE;MACtD,OAAO,KAAK;IAChB;IACA,MAAMC,GAAG,GAAG,IAAID,IAAI,CAAC,CAAC,CAACE,OAAO,CAAC,CAAC;IAChC,MAAMH,QAAQ,GAAGD,MAAM,CAACC,QAAQ,CAACG,OAAO,CAAC,CAAC;IAC1C,OAAOH,QAAQ,GAAGF,OAAO,IAAII,GAAG;EACpC,CAAC;AACL,CAAC;AAACE,OAAA,CAAAR,eAAA,GAAAA,eAAA","ignoreList":[]}
|