@nmshd/consumption 2.0.0-alpha.5 → 2.0.0-alpha.8
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/dist/buildInformation.js +4 -4
- package/dist/consumption/ConsumptionBaseController.d.ts +1 -1
- package/dist/consumption/ConsumptionController.js +2 -2
- package/dist/consumption/ConsumptionController.js.map +1 -1
- package/dist/modules/attributes/ConsumptionAttributesController.d.ts +1 -1
- package/dist/modules/drafts/DraftsController.d.ts +1 -1
- package/dist/modules/relationships/RelationshipInfoController.d.ts +1 -1
- package/dist/modules/requests/incoming/DecideRequestParametersValidator.d.ts +5 -1
- package/dist/modules/requests/incoming/DecideRequestParametersValidator.js +55 -1
- package/dist/modules/requests/incoming/DecideRequestParametersValidator.js.map +1 -1
- package/dist/modules/requests/incoming/IncomingRequestsController.d.ts +6 -6
- package/dist/modules/requests/incoming/IncomingRequestsController.js +15 -12
- package/dist/modules/requests/incoming/IncomingRequestsController.js.map +1 -1
- package/dist/modules/requests/incoming/decide/DecideRequestItemGroupParameters.d.ts +1 -0
- package/dist/modules/requests/incoming/decide/DecideRequestItemGroupParameters.js +5 -0
- package/dist/modules/requests/incoming/decide/DecideRequestItemGroupParameters.js.map +1 -1
- package/dist/modules/requests/incoming/decide/DecideRequestItemParameters.d.ts +1 -0
- package/dist/modules/requests/incoming/decide/DecideRequestItemParameters.js +5 -0
- package/dist/modules/requests/incoming/decide/DecideRequestItemParameters.js.map +1 -1
- package/dist/modules/requests/outgoing/OutgoingRequestsController.d.ts +6 -6
- package/dist/modules/requests/outgoing/OutgoingRequestsController.js +11 -8
- package/dist/modules/requests/outgoing/OutgoingRequestsController.js.map +1 -1
- package/dist/modules/settings/SettingsController.d.ts +1 -1
- package/dist/modules/sharedItems/SharedItemsController.d.ts +1 -1
- package/lib-web/nmshd.consumption.js +97 -27
- package/lib-web/nmshd.consumption.js.map +1 -1
- package/lib-web/nmshd.consumption.min.js +1 -1
- package/lib-web/nmshd.consumption.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -17,10 +17,10 @@ const content_1 = __webpack_require__(/*! @nmshd/content */ "@nmshd/content");
|
|
|
17
17
|
const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
|
|
18
18
|
const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
|
|
19
19
|
exports.buildInformation = {
|
|
20
|
-
version: "2.0.0-alpha.
|
|
21
|
-
build: "
|
|
22
|
-
date: "2022-
|
|
23
|
-
commit: "
|
|
20
|
+
version: "2.0.0-alpha.8",
|
|
21
|
+
build: "26",
|
|
22
|
+
date: "2022-05-05T12:20:20+00:00",
|
|
23
|
+
commit: "c699fbc6fc9984848f31155fdf1713706bdfffe5",
|
|
24
24
|
dependencies: {},
|
|
25
25
|
libraries: {
|
|
26
26
|
transport: transport_1.buildInformation,
|
|
@@ -110,8 +110,8 @@ class ConsumptionController {
|
|
|
110
110
|
this._attributes = await new modules_1.ConsumptionAttributesController(this).init();
|
|
111
111
|
this._drafts = await new modules_1.DraftsController(this).init();
|
|
112
112
|
const processorRegistry = new modules_1.RequestItemProcessorRegistry(requestItemProcessors);
|
|
113
|
-
this._outgoingRequests = await new modules_1.OutgoingRequestsController(this, processorRegistry).init();
|
|
114
|
-
this._incomingRequests = await new IncomingRequestsController_1.IncomingRequestsController(this, processorRegistry).init();
|
|
113
|
+
this._outgoingRequests = await new modules_1.OutgoingRequestsController(await this.accountController.getSynchronizedCollection("Requests"), processorRegistry, this).init();
|
|
114
|
+
this._incomingRequests = await new IncomingRequestsController_1.IncomingRequestsController(await this.accountController.getSynchronizedCollection("Requests"), processorRegistry, this).init();
|
|
115
115
|
this._settings = await new modules_1.SettingsController(this).init();
|
|
116
116
|
this._sharedItems = await new modules_1.SharedItemsController(this).init();
|
|
117
117
|
this._relationshipInfo = await new modules_1.RelationshipInfoController(this).init();
|
|
@@ -1233,13 +1233,67 @@ exports.RelationshipTheme = RelationshipTheme;
|
|
|
1233
1233
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1234
1234
|
exports.DecideRequestParametersValidator = void 0;
|
|
1235
1235
|
const ts_utils_1 = __webpack_require__(/*! @js-soft/ts-utils */ "./node_modules/@js-soft/ts-utils/dist/index.js");
|
|
1236
|
+
const content_1 = __webpack_require__(/*! @nmshd/content */ "@nmshd/content");
|
|
1237
|
+
const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
|
|
1238
|
+
const DecideRequestItemGroupParameters_1 = __webpack_require__(/*! ./decide/DecideRequestItemGroupParameters */ "./dist/modules/requests/incoming/decide/DecideRequestItemGroupParameters.js");
|
|
1239
|
+
const DecideRequestItemParameters_1 = __webpack_require__(/*! ./decide/DecideRequestItemParameters */ "./dist/modules/requests/incoming/decide/DecideRequestItemParameters.js");
|
|
1236
1240
|
class DecideRequestParametersValidator {
|
|
1237
1241
|
validate(params, request) {
|
|
1242
|
+
if (!request.id.equals(transport_1.CoreId.from(params.requestId))) {
|
|
1243
|
+
return ts_utils_1.Result.fail(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidRequestId", "The id of the request does not match the id of the response"));
|
|
1244
|
+
}
|
|
1238
1245
|
if (params.items.length !== request.content.items.length) {
|
|
1239
|
-
return ts_utils_1.Result.fail(
|
|
1246
|
+
return ts_utils_1.Result.fail(this.invalidNumberOfItemsError("Number of items in Request and Response do not match"));
|
|
1247
|
+
}
|
|
1248
|
+
for (let i = 0; i < params.items.length; i++) {
|
|
1249
|
+
const validationResult = this.checkItemOrGroup(request.content.items[i], params.items[i], i.toString(), params.accept);
|
|
1250
|
+
if (validationResult.isError)
|
|
1251
|
+
return validationResult;
|
|
1240
1252
|
}
|
|
1241
1253
|
return ts_utils_1.Result.ok(undefined);
|
|
1242
1254
|
}
|
|
1255
|
+
checkItemOrGroup(requestItem, responseItem, index, isParentAccepted) {
|
|
1256
|
+
if (requestItem instanceof content_1.RequestItem) {
|
|
1257
|
+
return this.checkItem(requestItem, responseItem, index, isParentAccepted);
|
|
1258
|
+
}
|
|
1259
|
+
return this.checkItemGroup(requestItem, responseItem, index, isParentAccepted);
|
|
1260
|
+
}
|
|
1261
|
+
checkItem(requestItem, response, index, isParentAccepted) {
|
|
1262
|
+
if ((0, DecideRequestItemGroupParameters_1.isDecideRequestItemGroupParametersJSON)(response)) {
|
|
1263
|
+
return ts_utils_1.Result.fail(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", `The RequestItem with index '${index}' was answered as a RequestItemGroup.`));
|
|
1264
|
+
}
|
|
1265
|
+
if (!isParentAccepted && response.accept) {
|
|
1266
|
+
return ts_utils_1.Result.fail(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", `The RequestItem with index '${index}' was accepted, but the parent was not accepted.`));
|
|
1267
|
+
}
|
|
1268
|
+
if (isParentAccepted && requestItem.mustBeAccepted && !response.accept) {
|
|
1269
|
+
return ts_utils_1.Result.fail(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", `The RequestItem with index '${index}', which is flagged as 'mustBeAccepted', was not accepted.`));
|
|
1270
|
+
}
|
|
1271
|
+
return ts_utils_1.Result.ok(undefined);
|
|
1272
|
+
}
|
|
1273
|
+
checkItemGroup(requestItemGroup, responseItemGroup, index, isParentAccepted) {
|
|
1274
|
+
if ((0, DecideRequestItemParameters_1.isDecideRequestItemParametersJSON)(responseItemGroup)) {
|
|
1275
|
+
return ts_utils_1.Result.fail(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", `The RequestItemGroup with index '${index}' was answered as a RequestItem.`));
|
|
1276
|
+
}
|
|
1277
|
+
if (responseItemGroup.items.length !== requestItemGroup.items.length) {
|
|
1278
|
+
return ts_utils_1.Result.fail(this.invalidNumberOfItemsError("Number of items in RequestItemGroup and ResponseItemGroup do not match"));
|
|
1279
|
+
}
|
|
1280
|
+
const isGroupAccepted = responseItemGroup.items.some((value) => value.accept);
|
|
1281
|
+
if (!isParentAccepted && isGroupAccepted) {
|
|
1282
|
+
return ts_utils_1.Result.fail(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", `The RequestItemGroup with index '${index}' was accepted, but the parent was not accepted.`));
|
|
1283
|
+
}
|
|
1284
|
+
if (isParentAccepted && requestItemGroup.mustBeAccepted && !isGroupAccepted) {
|
|
1285
|
+
return ts_utils_1.Result.fail(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", `The RequestItemGroup with index '${index}', which is flagged as 'mustBeAccepted', was not accepted. Please accept all 'mustBeAccepted' items in this group.`));
|
|
1286
|
+
}
|
|
1287
|
+
for (let i = 0; i < responseItemGroup.items.length; i++) {
|
|
1288
|
+
const validationResult = this.checkItem(requestItemGroup.items[i], responseItemGroup.items[i], `${index}.${i}`, isGroupAccepted);
|
|
1289
|
+
if (validationResult.isError)
|
|
1290
|
+
return validationResult;
|
|
1291
|
+
}
|
|
1292
|
+
return ts_utils_1.Result.ok(undefined);
|
|
1293
|
+
}
|
|
1294
|
+
invalidNumberOfItemsError(message) {
|
|
1295
|
+
return new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidNumberOfItems", message);
|
|
1296
|
+
}
|
|
1243
1297
|
}
|
|
1244
1298
|
exports.DecideRequestParametersValidator = DecideRequestParametersValidator;
|
|
1245
1299
|
//# sourceMappingURL=DecideRequestParametersValidator.js.map
|
|
@@ -1270,21 +1324,17 @@ const DecideRequestParametersValidator_1 = __webpack_require__(/*! ./DecideReque
|
|
|
1270
1324
|
const ReceivedIncomingRequestParameters_1 = __webpack_require__(/*! ./received/ReceivedIncomingRequestParameters */ "./dist/modules/requests/incoming/received/ReceivedIncomingRequestParameters.js");
|
|
1271
1325
|
const RequireManualDecisionOfIncomingRequestParameters_1 = __webpack_require__(/*! ./requireManualDecision/RequireManualDecisionOfIncomingRequestParameters */ "./dist/modules/requests/incoming/requireManualDecision/RequireManualDecisionOfIncomingRequestParameters.js");
|
|
1272
1326
|
class IncomingRequestsController extends consumption_1.ConsumptionBaseController {
|
|
1273
|
-
constructor(
|
|
1327
|
+
constructor(consumptionRequests, processorRegistry, parent) {
|
|
1274
1328
|
super(consumption_1.ConsumptionControllerName.RequestsController, parent);
|
|
1329
|
+
this.consumptionRequests = consumptionRequests;
|
|
1275
1330
|
this.processorRegistry = processorRegistry;
|
|
1276
1331
|
this.decideRequestParamsValidator = new DecideRequestParametersValidator_1.DecideRequestParametersValidator();
|
|
1277
1332
|
}
|
|
1278
|
-
async init() {
|
|
1279
|
-
await super.init();
|
|
1280
|
-
this.consumptionRequests = await this.parent.accountController.getSynchronizedCollection("Requests");
|
|
1281
|
-
return this;
|
|
1282
|
-
}
|
|
1283
1333
|
async received(params) {
|
|
1284
1334
|
const parsedParams = ReceivedIncomingRequestParameters_1.ReceivedIncomingRequestParameters.from(params);
|
|
1285
1335
|
const infoFromSource = this.extractInfoFromSource(parsedParams.requestSourceObject);
|
|
1286
1336
|
const consumptionRequest = ConsumptionRequest_1.ConsumptionRequest.from({
|
|
1287
|
-
id: parsedParams.receivedRequest.id ?? (await
|
|
1337
|
+
id: parsedParams.receivedRequest.id ?? (await consumption_1.ConsumptionIds.request.generate()),
|
|
1288
1338
|
createdAt: transport_1.CoreDate.utc(),
|
|
1289
1339
|
status: ConsumptionRequestStatus_1.ConsumptionRequestStatus.Open,
|
|
1290
1340
|
content: parsedParams.receivedRequest,
|
|
@@ -1359,7 +1409,7 @@ class IncomingRequestsController extends consumption_1.ConsumptionBaseController
|
|
|
1359
1409
|
return request;
|
|
1360
1410
|
}
|
|
1361
1411
|
async canAccept(params) {
|
|
1362
|
-
return await this.canDecide({ ...params, accept:
|
|
1412
|
+
return await this.canDecide({ ...params, accept: true });
|
|
1363
1413
|
}
|
|
1364
1414
|
async canReject(params) {
|
|
1365
1415
|
return await this.canDecide({ ...params, accept: false });
|
|
@@ -1408,7 +1458,7 @@ class IncomingRequestsController extends consumption_1.ConsumptionBaseController
|
|
|
1408
1458
|
if (!canAccept.isSuccess()) {
|
|
1409
1459
|
throw new Error("Cannot accept the Request with the given parameters. Call 'canAccept' to get more information.");
|
|
1410
1460
|
}
|
|
1411
|
-
return await this.decide({ ...params, accept:
|
|
1461
|
+
return await this.decide({ ...params, accept: true });
|
|
1412
1462
|
}
|
|
1413
1463
|
async reject(params) {
|
|
1414
1464
|
const canReject = await this.canReject(params);
|
|
@@ -1503,13 +1553,20 @@ class IncomingRequestsController extends consumption_1.ConsumptionBaseController
|
|
|
1503
1553
|
await this.update(request);
|
|
1504
1554
|
return request;
|
|
1505
1555
|
}
|
|
1506
|
-
async
|
|
1507
|
-
|
|
1556
|
+
async getIncomingRequests(query) {
|
|
1557
|
+
query ??= {};
|
|
1558
|
+
query.isOwn = false;
|
|
1559
|
+
const requestDocs = await this.consumptionRequests.find(query);
|
|
1560
|
+
const requests = requestDocs.map((r) => ConsumptionRequest_1.ConsumptionRequest.from(r));
|
|
1561
|
+
return requests;
|
|
1562
|
+
}
|
|
1563
|
+
async getIncomingRequest(idIncomingRequest) {
|
|
1564
|
+
const requestDoc = await this.consumptionRequests.findOne({ id: idIncomingRequest.toString(), isOwn: false });
|
|
1508
1565
|
const request = requestDoc ? ConsumptionRequest_1.ConsumptionRequest.from(requestDoc) : undefined;
|
|
1509
1566
|
return request;
|
|
1510
1567
|
}
|
|
1511
1568
|
async getOrThrow(id) {
|
|
1512
|
-
const request = await this.
|
|
1569
|
+
const request = await this.getIncomingRequest(transport_1.CoreId.from(id));
|
|
1513
1570
|
if (!request) {
|
|
1514
1571
|
throw transport_1.TransportErrors.general.recordNotFound(ConsumptionRequest_1.ConsumptionRequest, id.toString());
|
|
1515
1572
|
}
|
|
@@ -1635,6 +1692,11 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
1635
1692
|
"use strict";
|
|
1636
1693
|
|
|
1637
1694
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1695
|
+
exports.isDecideRequestItemGroupParametersJSON = void 0;
|
|
1696
|
+
function isDecideRequestItemGroupParametersJSON(json) {
|
|
1697
|
+
return typeof json.items !== "undefined" && typeof json.accept === "undefined";
|
|
1698
|
+
}
|
|
1699
|
+
exports.isDecideRequestItemGroupParametersJSON = isDecideRequestItemGroupParametersJSON;
|
|
1638
1700
|
//# sourceMappingURL=DecideRequestItemGroupParameters.js.map
|
|
1639
1701
|
|
|
1640
1702
|
/***/ }),
|
|
@@ -1648,6 +1710,11 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
1648
1710
|
"use strict";
|
|
1649
1711
|
|
|
1650
1712
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1713
|
+
exports.isDecideRequestItemParametersJSON = void 0;
|
|
1714
|
+
function isDecideRequestItemParametersJSON(json) {
|
|
1715
|
+
return typeof json.items === "undefined" && typeof json.accept !== "undefined";
|
|
1716
|
+
}
|
|
1717
|
+
exports.isDecideRequestItemParametersJSON = isDecideRequestItemParametersJSON;
|
|
1651
1718
|
//# sourceMappingURL=DecideRequestItemParameters.js.map
|
|
1652
1719
|
|
|
1653
1720
|
/***/ }),
|
|
@@ -2260,15 +2327,11 @@ const CreateOutgoingRequestFromRelationshipCreationChangeParameters_1 = __webpac
|
|
|
2260
2327
|
const CreateOutgoingRequestParameters_1 = __webpack_require__(/*! ./createOutgoingRequest/CreateOutgoingRequestParameters */ "./dist/modules/requests/outgoing/createOutgoingRequest/CreateOutgoingRequestParameters.js");
|
|
2261
2328
|
const SentOutgoingRequestParameters_1 = __webpack_require__(/*! ./sentOutgoingRequest/SentOutgoingRequestParameters */ "./dist/modules/requests/outgoing/sentOutgoingRequest/SentOutgoingRequestParameters.js");
|
|
2262
2329
|
class OutgoingRequestsController extends consumption_1.ConsumptionBaseController {
|
|
2263
|
-
constructor(
|
|
2330
|
+
constructor(consumptionRequests, processorRegistry, parent) {
|
|
2264
2331
|
super(consumption_1.ConsumptionControllerName.RequestsController, parent);
|
|
2332
|
+
this.consumptionRequests = consumptionRequests;
|
|
2265
2333
|
this.processorRegistry = processorRegistry;
|
|
2266
2334
|
}
|
|
2267
|
-
async init() {
|
|
2268
|
-
await super.init();
|
|
2269
|
-
this.consumptionRequests = await this.parent.accountController.getSynchronizedCollection("Requests");
|
|
2270
|
-
return this;
|
|
2271
|
-
}
|
|
2272
2335
|
async canCreate(params) {
|
|
2273
2336
|
const parsedParams = CreateOutgoingRequestParameters_1.CreateOutgoingRequestParameters.from(params);
|
|
2274
2337
|
const innerResults = await this.canCreateItems(parsedParams.content.items);
|
|
@@ -2443,13 +2506,20 @@ class OutgoingRequestsController extends consumption_1.ConsumptionBaseController
|
|
|
2443
2506
|
const processor = this.processorRegistry.getProcessorForItem(requestItem);
|
|
2444
2507
|
await processor.applyIncomingResponseItem(responseItem, requestItem);
|
|
2445
2508
|
}
|
|
2446
|
-
async
|
|
2509
|
+
async getOutgoingRequests(query) {
|
|
2510
|
+
query ??= {};
|
|
2511
|
+
query.isOwn = true;
|
|
2512
|
+
const requestDocs = await this.consumptionRequests.find(query);
|
|
2513
|
+
const requests = requestDocs.map((r) => ConsumptionRequest_1.ConsumptionRequest.from(r));
|
|
2514
|
+
return requests;
|
|
2515
|
+
}
|
|
2516
|
+
async getOutgoingRequest(id) {
|
|
2447
2517
|
const requestDoc = await this.consumptionRequests.findOne({ id: id.toString(), isOwn: true });
|
|
2448
2518
|
const request = requestDoc ? ConsumptionRequest_1.ConsumptionRequest.from(requestDoc) : undefined;
|
|
2449
2519
|
return request;
|
|
2450
2520
|
}
|
|
2451
2521
|
async getOrThrow(id) {
|
|
2452
|
-
const request = await this.
|
|
2522
|
+
const request = await this.getOutgoingRequest(id);
|
|
2453
2523
|
if (!request) {
|
|
2454
2524
|
throw transport_1.TransportErrors.general.recordNotFound(ConsumptionRequest_1.ConsumptionRequest, id.toString());
|
|
2455
2525
|
}
|