@nmshd/consumption 2.0.0-alpha.26 → 2.0.0-alpha.29
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/modules/attributes/LocalAttributesController.js +4 -4
- package/dist/modules/attributes/LocalAttributesController.js.map +1 -1
- package/dist/modules/attributes/local/CreateSharedLocalAttributeCopyParams.d.ts +6 -3
- package/dist/modules/attributes/local/CreateSharedLocalAttributeCopyParams.js +6 -1
- package/dist/modules/attributes/local/CreateSharedLocalAttributeCopyParams.js.map +1 -1
- package/dist/modules/attributes/local/LocalAttribute.d.ts +4 -2
- package/dist/modules/attributes/local/LocalAttribute.js +8 -2
- package/dist/modules/attributes/local/LocalAttribute.js.map +1 -1
- package/dist/modules/requests/itemProcessors/createAttribute/CreateAttributeRequestItemProcessor.d.ts +1 -1
- package/dist/modules/requests/itemProcessors/createAttribute/CreateAttributeRequestItemProcessor.js +25 -8
- package/dist/modules/requests/itemProcessors/createAttribute/CreateAttributeRequestItemProcessor.js.map +1 -1
- package/dist/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.js +2 -2
- package/dist/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.js.map +1 -1
- package/dist/modules/requests/itemProcessors/readAttribute/AcceptReadAttributeRequestItemParameters.d.ts +5 -5
- package/dist/modules/requests/itemProcessors/readAttribute/AcceptReadAttributeRequestItemParameters.js +8 -8
- package/dist/modules/requests/itemProcessors/readAttribute/AcceptReadAttributeRequestItemParameters.js.map +1 -1
- package/dist/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.js +5 -5
- package/dist/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.js.map +1 -1
- package/dist/modules/requests/itemProcessors/shareAttribute/ShareAttributeRequestItemProcessor.js +3 -2
- package/dist/modules/requests/itemProcessors/shareAttribute/ShareAttributeRequestItemProcessor.js.map +1 -1
- package/lib-web/nmshd.consumption.js +65 -36
- 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 +2 -2
|
@@ -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-07-
|
|
23
|
-
commit: "
|
|
20
|
+
version: "2.0.0-alpha.29",
|
|
21
|
+
build: "49",
|
|
22
|
+
date: "2022-07-11T08:42:45+00:00",
|
|
23
|
+
commit: "ef1ee4d2fd7cd13d85238e6ed6ac8ba98c744230",
|
|
24
24
|
dependencies: {"@js-soft/docdb-querytranslator":"^1.0.1","ts-simple-nameof":"^1.3.1"},
|
|
25
25
|
libraries: {
|
|
26
26
|
transport: transport_1.buildInformation,
|
|
@@ -426,16 +426,16 @@ class LocalAttributesController extends consumption_1.ConsumptionBaseController
|
|
|
426
426
|
}
|
|
427
427
|
async createSharedLocalAttributeCopy(params) {
|
|
428
428
|
const parsedParams = CreateSharedLocalAttributeCopyParams_1.CreateSharedLocalAttributeCopyParams.from(params);
|
|
429
|
-
const sourceAttribute = await this.getLocalAttribute(parsedParams.
|
|
429
|
+
const sourceAttribute = await this.getLocalAttribute(parsedParams.sourceAttributeId);
|
|
430
430
|
if (!sourceAttribute) {
|
|
431
|
-
throw consumption_1.ConsumptionErrors.attributes.predecessorNotFound(parsedParams.
|
|
431
|
+
throw consumption_1.ConsumptionErrors.attributes.predecessorNotFound(parsedParams.sourceAttributeId.toString());
|
|
432
432
|
}
|
|
433
433
|
const shareInfo = LocalAttributeShareInfo_1.LocalAttributeShareInfo.from({
|
|
434
434
|
peer: parsedParams.peer,
|
|
435
435
|
requestReference: parsedParams.requestReference,
|
|
436
|
-
sourceAttribute: parsedParams.
|
|
436
|
+
sourceAttribute: parsedParams.sourceAttributeId
|
|
437
437
|
});
|
|
438
|
-
const sharedLocalAttributeCopy = await LocalAttribute_1.LocalAttribute.fromAttribute(sourceAttribute.content, undefined, shareInfo);
|
|
438
|
+
const sharedLocalAttributeCopy = await LocalAttribute_1.LocalAttribute.fromAttribute(sourceAttribute.content, undefined, shareInfo, parsedParams.attributeId);
|
|
439
439
|
await this.attributes.create(sharedLocalAttributeCopy);
|
|
440
440
|
return sharedLocalAttributeCopy;
|
|
441
441
|
}
|
|
@@ -596,9 +596,14 @@ class CreateSharedLocalAttributeCopyParams extends ts_serval_1.Serializable {
|
|
|
596
596
|
}
|
|
597
597
|
__decorate([
|
|
598
598
|
(0, ts_serval_1.serialize)(),
|
|
599
|
-
(0, ts_serval_1.validate)(),
|
|
599
|
+
(0, ts_serval_1.validate)({ nullable: true }),
|
|
600
600
|
__metadata("design:type", transport_1.CoreId)
|
|
601
601
|
], CreateSharedLocalAttributeCopyParams.prototype, "attributeId", void 0);
|
|
602
|
+
__decorate([
|
|
603
|
+
(0, ts_serval_1.serialize)(),
|
|
604
|
+
(0, ts_serval_1.validate)(),
|
|
605
|
+
__metadata("design:type", transport_1.CoreId)
|
|
606
|
+
], CreateSharedLocalAttributeCopyParams.prototype, "sourceAttributeId", void 0);
|
|
602
607
|
__decorate([
|
|
603
608
|
(0, ts_serval_1.serialize)(),
|
|
604
609
|
(0, ts_serval_1.validate)(),
|
|
@@ -651,13 +656,19 @@ let LocalAttribute = class LocalAttribute extends transport_1.CoreSynchronizable
|
|
|
651
656
|
];
|
|
652
657
|
this.userdataProperties = [(0, ts_simple_nameof_1.nameof)((r) => r.content)];
|
|
653
658
|
}
|
|
659
|
+
isIdentityAttribute() {
|
|
660
|
+
return this.content instanceof content_1.IdentityAttribute;
|
|
661
|
+
}
|
|
662
|
+
isOwnedBy(identity) {
|
|
663
|
+
return this.content.owner.equals(identity);
|
|
664
|
+
}
|
|
654
665
|
static from(value) {
|
|
655
666
|
return this.fromAny(value);
|
|
656
667
|
}
|
|
657
|
-
static async fromAttribute(attribute, succeeds, shareInfo) {
|
|
668
|
+
static async fromAttribute(attribute, succeeds, shareInfo, id) {
|
|
658
669
|
return this.from({
|
|
670
|
+
id: id ?? (await consumption_1.ConsumptionIds.attribute.generate()),
|
|
659
671
|
content: attribute,
|
|
660
|
-
id: await consumption_1.ConsumptionIds.attribute.generate(),
|
|
661
672
|
createdAt: transport_1.CoreDate.utc(),
|
|
662
673
|
succeeds: succeeds,
|
|
663
674
|
shareInfo: shareInfo
|
|
@@ -2067,7 +2078,14 @@ const consumption_1 = __webpack_require__(/*! ../../../../consumption */ "./dist
|
|
|
2067
2078
|
const GenericRequestItemProcessor_1 = __webpack_require__(/*! ../GenericRequestItemProcessor */ "./dist/modules/requests/itemProcessors/GenericRequestItemProcessor.js");
|
|
2068
2079
|
const ValidationResult_1 = __webpack_require__(/*! ../ValidationResult */ "./dist/modules/requests/itemProcessors/ValidationResult.js");
|
|
2069
2080
|
class CreateAttributeRequestItemProcessor extends GenericRequestItemProcessor_1.GenericRequestItemProcessor {
|
|
2070
|
-
canCreateOutgoingRequestItem(requestItem, _request,
|
|
2081
|
+
canCreateOutgoingRequestItem(requestItem, _request, recipient) {
|
|
2082
|
+
const recipientIsOwnerOfTheAttribute = requestItem.attribute.owner.equals(recipient);
|
|
2083
|
+
// When the owner of the Attribute is not the recipient of the Request, this means that
|
|
2084
|
+
// we need to set the sourceAttributeId, because we have to set shareInfo as soon as the
|
|
2085
|
+
// RequestItem was accepted.
|
|
2086
|
+
if (!recipientIsOwnerOfTheAttribute && !requestItem.sourceAttributeId) {
|
|
2087
|
+
return ValidationResult_1.ValidationResult.error(consumption_1.ConsumptionErrors.requests.invalidRequestItem("'sourceAttributeId' cannot be undefined when sending an attribute that is not owned by the recipient."));
|
|
2088
|
+
}
|
|
2071
2089
|
if (requestItem.attribute instanceof content_1.IdentityAttribute) {
|
|
2072
2090
|
return this.canCreateRequestItemWithIdentityAttribute(requestItem);
|
|
2073
2091
|
}
|
|
@@ -2102,13 +2120,23 @@ class CreateAttributeRequestItemProcessor extends GenericRequestItemProcessor_1.
|
|
|
2102
2120
|
if (!(responseItem instanceof content_1.CreateAttributeAcceptResponseItem)) {
|
|
2103
2121
|
return;
|
|
2104
2122
|
}
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2123
|
+
if (requestItem.sourceAttributeId) {
|
|
2124
|
+
const sourceAttribute = await this.consumptionController.attributes.getLocalAttribute(requestItem.sourceAttributeId);
|
|
2125
|
+
await this.consumptionController.attributes.createSharedLocalAttributeCopy({
|
|
2126
|
+
attributeId: responseItem.attributeId,
|
|
2127
|
+
sourceAttributeId: sourceAttribute.id,
|
|
2128
|
+
peer: requestInfo.peer,
|
|
2129
|
+
requestReference: requestInfo.id
|
|
2130
|
+
});
|
|
2131
|
+
}
|
|
2132
|
+
else {
|
|
2133
|
+
await this.consumptionController.attributes.createPeerLocalAttribute({
|
|
2134
|
+
id: responseItem.attributeId,
|
|
2135
|
+
content: requestItem.attribute,
|
|
2136
|
+
peer: requestInfo.peer,
|
|
2137
|
+
requestReference: requestInfo.id
|
|
2138
|
+
});
|
|
2139
|
+
}
|
|
2112
2140
|
}
|
|
2113
2141
|
}
|
|
2114
2142
|
exports.CreateAttributeRequestItemProcessor = CreateAttributeRequestItemProcessor;
|
|
@@ -2232,7 +2260,7 @@ class ProposeAttributeRequestItemProcessor extends GenericRequestItemProcessor_1
|
|
|
2232
2260
|
}
|
|
2233
2261
|
async copyExistingAttribute(attributeId, requestInfo) {
|
|
2234
2262
|
return await this.consumptionController.attributes.createSharedLocalAttributeCopy({
|
|
2235
|
-
|
|
2263
|
+
sourceAttributeId: transport_1.CoreId.from(attributeId),
|
|
2236
2264
|
peer: transport_1.CoreAddress.from(requestInfo.peer),
|
|
2237
2265
|
requestReference: transport_1.CoreId.from(requestInfo.id)
|
|
2238
2266
|
});
|
|
@@ -2243,7 +2271,7 @@ class ProposeAttributeRequestItemProcessor extends GenericRequestItemProcessor_1
|
|
|
2243
2271
|
content: attribute
|
|
2244
2272
|
});
|
|
2245
2273
|
return await this.consumptionController.attributes.createSharedLocalAttributeCopy({
|
|
2246
|
-
|
|
2274
|
+
sourceAttributeId: transport_1.CoreId.from(repositoryLocalAttribute.id),
|
|
2247
2275
|
peer: transport_1.CoreAddress.from(requestInfo.peer),
|
|
2248
2276
|
requestReference: transport_1.CoreId.from(requestInfo.id)
|
|
2249
2277
|
});
|
|
@@ -2297,10 +2325,10 @@ const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transpor
|
|
|
2297
2325
|
const ts_simple_nameof_1 = __webpack_require__(/*! ts-simple-nameof */ "./node_modules/ts-simple-nameof/index.js");
|
|
2298
2326
|
let AcceptReadAttributeRequestItemParameters = AcceptReadAttributeRequestItemParameters_1 = class AcceptReadAttributeRequestItemParameters extends ts_serval_1.Serializable {
|
|
2299
2327
|
isWithExistingAttribute() {
|
|
2300
|
-
return this.
|
|
2328
|
+
return this.existingAttributeId !== undefined;
|
|
2301
2329
|
}
|
|
2302
2330
|
isWithNewAttribute() {
|
|
2303
|
-
return this.
|
|
2331
|
+
return this.newAttribute !== undefined;
|
|
2304
2332
|
}
|
|
2305
2333
|
static from(value) {
|
|
2306
2334
|
return this.fromAny(value);
|
|
@@ -2308,11 +2336,11 @@ let AcceptReadAttributeRequestItemParameters = AcceptReadAttributeRequestItemPar
|
|
|
2308
2336
|
static postFrom(value) {
|
|
2309
2337
|
if (!(value instanceof AcceptReadAttributeRequestItemParameters_1))
|
|
2310
2338
|
throw new Error("this should never happen");
|
|
2311
|
-
if (value.
|
|
2312
|
-
throw new ts_serval_1.ValidationError(AcceptReadAttributeRequestItemParameters_1.name, (0, ts_simple_nameof_1.nameof)((x) => x.
|
|
2339
|
+
if (value.existingAttributeId && value.newAttribute) {
|
|
2340
|
+
throw new ts_serval_1.ValidationError(AcceptReadAttributeRequestItemParameters_1.name, (0, ts_simple_nameof_1.nameof)((x) => x.newAttribute), `You cannot specify both ${(0, ts_simple_nameof_1.nameof)((x) => x.newAttribute)} and ${(0, ts_simple_nameof_1.nameof)((x) => x.existingAttributeId)}.`);
|
|
2313
2341
|
}
|
|
2314
|
-
if (!value.
|
|
2315
|
-
throw new ts_serval_1.ValidationError(AcceptReadAttributeRequestItemParameters_1.name, (0, ts_simple_nameof_1.nameof)((x) => x.
|
|
2342
|
+
if (!value.existingAttributeId && !value.newAttribute) {
|
|
2343
|
+
throw new ts_serval_1.ValidationError(AcceptReadAttributeRequestItemParameters_1.name, (0, ts_simple_nameof_1.nameof)((x) => x.newAttribute), `You have to specify either ${(0, ts_simple_nameof_1.nameof)((x) => x.newAttribute)} or ${(0, ts_simple_nameof_1.nameof)((x) => x.existingAttributeId)}.`);
|
|
2316
2344
|
}
|
|
2317
2345
|
return value;
|
|
2318
2346
|
}
|
|
@@ -2321,12 +2349,12 @@ __decorate([
|
|
|
2321
2349
|
(0, ts_serval_1.serialize)(),
|
|
2322
2350
|
(0, ts_serval_1.validate)({ nullable: true }),
|
|
2323
2351
|
__metadata("design:type", transport_1.CoreId)
|
|
2324
|
-
], AcceptReadAttributeRequestItemParameters.prototype, "
|
|
2352
|
+
], AcceptReadAttributeRequestItemParameters.prototype, "existingAttributeId", void 0);
|
|
2325
2353
|
__decorate([
|
|
2326
2354
|
(0, ts_serval_1.serialize)({ unionTypes: [content_1.IdentityAttribute, content_1.RelationshipAttribute] }),
|
|
2327
2355
|
(0, ts_serval_1.validate)({ nullable: true }),
|
|
2328
2356
|
__metadata("design:type", Object)
|
|
2329
|
-
], AcceptReadAttributeRequestItemParameters.prototype, "
|
|
2357
|
+
], AcceptReadAttributeRequestItemParameters.prototype, "newAttribute", void 0);
|
|
2330
2358
|
AcceptReadAttributeRequestItemParameters = AcceptReadAttributeRequestItemParameters_1 = __decorate([
|
|
2331
2359
|
(0, ts_serval_1.type)("AcceptReadAttributeRequestItemParameters")
|
|
2332
2360
|
], AcceptReadAttributeRequestItemParameters);
|
|
@@ -2367,7 +2395,7 @@ class ReadAttributeRequestItemProcessor extends GenericRequestItemProcessor_1.Ge
|
|
|
2367
2395
|
async canAccept(_requestItem, params, requestInfo) {
|
|
2368
2396
|
const parsedParams = AcceptReadAttributeRequestItemParameters_1.AcceptReadAttributeRequestItemParameters.from(params);
|
|
2369
2397
|
if (parsedParams.isWithExistingAttribute()) {
|
|
2370
|
-
const foundAttribute = await this.consumptionController.attributes.getLocalAttribute(parsedParams.
|
|
2398
|
+
const foundAttribute = await this.consumptionController.attributes.getLocalAttribute(parsedParams.existingAttributeId);
|
|
2371
2399
|
if (!foundAttribute) {
|
|
2372
2400
|
return ValidationResult_1.ValidationResult.error(transport_1.TransportErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, requestInfo.id.toString()));
|
|
2373
2401
|
}
|
|
@@ -2381,10 +2409,10 @@ class ReadAttributeRequestItemProcessor extends GenericRequestItemProcessor_1.Ge
|
|
|
2381
2409
|
const parsedParams = AcceptReadAttributeRequestItemParameters_1.AcceptReadAttributeRequestItemParameters.from(params);
|
|
2382
2410
|
let sharedLocalAttribute;
|
|
2383
2411
|
if (parsedParams.isWithExistingAttribute()) {
|
|
2384
|
-
sharedLocalAttribute = await this.copyExistingAttribute(parsedParams.
|
|
2412
|
+
sharedLocalAttribute = await this.copyExistingAttribute(parsedParams.existingAttributeId, requestInfo);
|
|
2385
2413
|
}
|
|
2386
2414
|
else {
|
|
2387
|
-
sharedLocalAttribute = await this.createNewAttribute(parsedParams.
|
|
2415
|
+
sharedLocalAttribute = await this.createNewAttribute(parsedParams.newAttribute, requestInfo);
|
|
2388
2416
|
}
|
|
2389
2417
|
return content_1.ReadAttributeAcceptResponseItem.from({
|
|
2390
2418
|
result: content_1.ResponseItemResult.Accepted,
|
|
@@ -2394,7 +2422,7 @@ class ReadAttributeRequestItemProcessor extends GenericRequestItemProcessor_1.Ge
|
|
|
2394
2422
|
}
|
|
2395
2423
|
async copyExistingAttribute(attributeId, requestInfo) {
|
|
2396
2424
|
return await this.consumptionController.attributes.createSharedLocalAttributeCopy({
|
|
2397
|
-
|
|
2425
|
+
sourceAttributeId: transport_1.CoreId.from(attributeId),
|
|
2398
2426
|
peer: transport_1.CoreAddress.from(requestInfo.peer),
|
|
2399
2427
|
requestReference: transport_1.CoreId.from(requestInfo.id)
|
|
2400
2428
|
});
|
|
@@ -2405,7 +2433,7 @@ class ReadAttributeRequestItemProcessor extends GenericRequestItemProcessor_1.Ge
|
|
|
2405
2433
|
content: attribute
|
|
2406
2434
|
});
|
|
2407
2435
|
return await this.consumptionController.attributes.createSharedLocalAttributeCopy({
|
|
2408
|
-
|
|
2436
|
+
sourceAttributeId: transport_1.CoreId.from(repositoryLocalAttribute.id),
|
|
2409
2437
|
peer: transport_1.CoreAddress.from(requestInfo.peer),
|
|
2410
2438
|
requestReference: transport_1.CoreId.from(requestInfo.id)
|
|
2411
2439
|
});
|
|
@@ -2522,7 +2550,7 @@ class ShareAttributeRequestItemProcessor extends GenericRequestItemProcessor_1.G
|
|
|
2522
2550
|
return ValidationResult_1.ValidationResult.success();
|
|
2523
2551
|
}
|
|
2524
2552
|
async accept(requestItem, _params, _requestInfo) {
|
|
2525
|
-
const attribute = await this.consumptionController.attributes.getLocalAttribute(requestItem.attributeId);
|
|
2553
|
+
const attribute = (await this.consumptionController.attributes.getLocalAttribute(requestItem.attributeId));
|
|
2526
2554
|
if (!(await this.isAttributeAlreadyShared(attribute, requestItem.shareWith))) {
|
|
2527
2555
|
await this.shareAttribute(attribute, requestItem.shareWith);
|
|
2528
2556
|
}
|
|
@@ -2543,7 +2571,8 @@ class ShareAttributeRequestItemProcessor extends GenericRequestItemProcessor_1.G
|
|
|
2543
2571
|
async shareAttribute(attribute, shareWith) {
|
|
2544
2572
|
const createAttributeRequestItem = content_1.CreateAttributeRequestItem.from({
|
|
2545
2573
|
attribute: attribute.content,
|
|
2546
|
-
mustBeAccepted: true
|
|
2574
|
+
mustBeAccepted: true,
|
|
2575
|
+
sourceAttributeId: attribute.id
|
|
2547
2576
|
});
|
|
2548
2577
|
const createAttributeRequest = await this.consumptionController.outgoingRequests.create({
|
|
2549
2578
|
peer: shareWith,
|