@nmshd/consumption 1.0.7 → 1.0.11
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/relationships/RelationshipInfoController.js +13 -5
- package/dist/modules/relationships/RelationshipInfoController.js.map +1 -1
- package/dist/modules/relationships/RelationshipInfoUtil.js +127 -69
- package/dist/modules/relationships/RelationshipInfoUtil.js.map +1 -1
- package/lib-web/nmshd.consumption.js +144 -78
- 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: "1.0.
|
|
21
|
-
build: "
|
|
22
|
-
date: "2021-12-
|
|
23
|
-
commit: "
|
|
20
|
+
version: "1.0.11",
|
|
21
|
+
build: "13",
|
|
22
|
+
date: "2021-12-29T14:32:15+00:00",
|
|
23
|
+
commit: "be407a6eedf0b92497314484fefd282be5ba6254",
|
|
24
24
|
dependencies: {},
|
|
25
25
|
libraries: {
|
|
26
26
|
transport: transport_1.buildInformation,
|
|
@@ -700,13 +700,21 @@ class RelationshipInfoController extends consumption_1.ConsumptionBaseController
|
|
|
700
700
|
return result ? await RelationshipInfo_1.RelationshipInfo.from(result) : undefined;
|
|
701
701
|
}
|
|
702
702
|
async getRelationshipInfoByRelationship(relationshipId) {
|
|
703
|
-
const result = await this.relationshipInfo.findOne({ relationshipId: relationshipId.toString() });
|
|
704
|
-
if (result) {
|
|
705
|
-
return await RelationshipInfo_1.RelationshipInfo.from(result);
|
|
706
|
-
}
|
|
707
703
|
const info = await new RelationshipInfoUtil_1.RelationshipInfoUtil(this.parent).createInitialRelationshipInfo(relationshipId);
|
|
708
|
-
await this.relationshipInfo.create(info);
|
|
709
704
|
return info;
|
|
705
|
+
/*
|
|
706
|
+
// So far, do not store the relationshipInfo, as they wouldn't be updated correctly
|
|
707
|
+
|
|
708
|
+
const result = await this.relationshipInfo.findOne({ relationshipId: relationshipId.toString() })
|
|
709
|
+
|
|
710
|
+
if (result) {
|
|
711
|
+
return await RelationshipInfo.from(result)
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
const info = await new RelationshipInfoUtil(this.parent).createInitialRelationshipInfo(relationshipId)
|
|
715
|
+
await this.relationshipInfo.create(info)
|
|
716
|
+
return info
|
|
717
|
+
*/
|
|
710
718
|
}
|
|
711
719
|
async getRelationshipInfos(query) {
|
|
712
720
|
const items = await this.relationshipInfo.find(query);
|
|
@@ -745,6 +753,7 @@ exports.RelationshipInfoController = RelationshipInfoController;
|
|
|
745
753
|
|
|
746
754
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
747
755
|
exports.RelationshipInfoUtil = void 0;
|
|
756
|
+
const ts_serval_1 = __webpack_require__(/*! @js-soft/ts-serval */ "@js-soft/ts-serval");
|
|
748
757
|
const content_1 = __webpack_require__(/*! @nmshd/content */ "@nmshd/content");
|
|
749
758
|
const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
|
|
750
759
|
const consumption_1 = __webpack_require__(/*! ../../consumption */ "./dist/consumption/index.js");
|
|
@@ -764,53 +773,50 @@ class RelationshipInfoUtil {
|
|
|
764
773
|
if (!relationship) {
|
|
765
774
|
throw transport_1.TransportErrors.general.recordNotFound(transport_1.Relationship, id.toString()).logWith(this._log);
|
|
766
775
|
}
|
|
767
|
-
|
|
768
|
-
if (!template) {
|
|
769
|
-
throw transport_1.TransportErrors.general
|
|
770
|
-
.recordNotFound(transport_1.RelationshipTemplate, relationship.cache.template.id.toString())
|
|
771
|
-
.logWith(this._log);
|
|
772
|
-
}
|
|
773
|
-
await this.parseTemplateBody(relationship, template);
|
|
776
|
+
await this.parseTemplateBody(relationship);
|
|
774
777
|
await this.parseCreationRequest(relationship);
|
|
775
778
|
return await this.createRelationshipInfo(relationship);
|
|
776
779
|
}
|
|
777
780
|
getTitle(relationship, attributeMap) {
|
|
778
781
|
var _a, _b, _c, _d, _e, _f;
|
|
779
782
|
let title = relationship.peer.address.toString().substring(3, 9);
|
|
780
|
-
const
|
|
781
|
-
const
|
|
782
|
-
const
|
|
783
|
+
const thingName = (_a = attributeMap.get("Thing.name")) === null || _a === void 0 ? void 0 : _a.content.value;
|
|
784
|
+
const givenName = (_b = attributeMap.get("Person.givenName")) === null || _b === void 0 ? void 0 : _b.content.value;
|
|
785
|
+
const familyName = (_c = attributeMap.get("Person.familyName")) === null || _c === void 0 ? void 0 : _c.content.value;
|
|
783
786
|
const gender = (_d = attributeMap.get("Person.gender")) === null || _d === void 0 ? void 0 : _d.content.value;
|
|
784
787
|
const orgname = (_e = attributeMap.get("Organization.name")) === null || _e === void 0 ? void 0 : _e.content.value;
|
|
785
|
-
const
|
|
786
|
-
if (
|
|
787
|
-
title =
|
|
788
|
+
const legalName = (_f = attributeMap.get("Organization.legalname")) === null || _f === void 0 ? void 0 : _f.content.value;
|
|
789
|
+
if (thingName) {
|
|
790
|
+
title = thingName;
|
|
788
791
|
}
|
|
789
|
-
else if (
|
|
790
|
-
title = `${
|
|
792
|
+
else if (givenName && familyName) {
|
|
793
|
+
title = `${givenName} ${familyName}`;
|
|
791
794
|
}
|
|
792
|
-
else if (
|
|
793
|
-
title =
|
|
795
|
+
else if (givenName) {
|
|
796
|
+
title = givenName;
|
|
797
|
+
}
|
|
798
|
+
else if (familyName && gender) {
|
|
799
|
+
title = `i18n://salutation.gender.${gender} ${familyName}`;
|
|
794
800
|
}
|
|
795
801
|
else if (orgname) {
|
|
796
802
|
title = orgname;
|
|
797
803
|
}
|
|
798
|
-
else if (
|
|
799
|
-
title =
|
|
804
|
+
else if (legalName) {
|
|
805
|
+
title = legalName;
|
|
800
806
|
}
|
|
801
807
|
return title;
|
|
802
808
|
}
|
|
803
809
|
async createRelationshipInfo(relationship) {
|
|
804
810
|
const peerAddress = relationship.peer.address;
|
|
805
811
|
const truncatedAddress = peerAddress.address.substring(3, 9);
|
|
806
|
-
|
|
812
|
+
const info = await RelationshipInfo_1.RelationshipInfo.from({
|
|
807
813
|
attributes: [],
|
|
808
814
|
id: await consumption_1.ConsumptionIds.relationshipInfo.generate(),
|
|
809
815
|
isPinned: false,
|
|
810
816
|
relationshipId: relationship.id,
|
|
811
817
|
title: truncatedAddress
|
|
812
818
|
});
|
|
813
|
-
info = await this.parent.relationshipInfo.createRelationshipInfo(info)
|
|
819
|
+
// info = await this.parent.relationshipInfo.createRelationshipInfo(info)
|
|
814
820
|
const items = await this.parent.sharedItems.getSharedItems({
|
|
815
821
|
sharedBy: relationship.peer.address.toString()
|
|
816
822
|
});
|
|
@@ -830,75 +836,135 @@ class RelationshipInfoUtil {
|
|
|
830
836
|
info.attributes = attributes;
|
|
831
837
|
const title = this.getTitle(relationship, attributeMap);
|
|
832
838
|
info.title = title;
|
|
833
|
-
await this.parent.relationshipInfo.updateRelationshipInfo(info)
|
|
839
|
+
// await this.parent.relationshipInfo.updateRelationshipInfo(info)
|
|
834
840
|
return info;
|
|
835
841
|
}
|
|
836
|
-
async parseTemplateBody(relationship
|
|
842
|
+
async parseTemplateBody(relationship) {
|
|
843
|
+
const template = relationship.cache.template;
|
|
837
844
|
if (!template.cache) {
|
|
838
845
|
throw transport_1.TransportErrors.general.cacheEmpty(transport_1.RelationshipTemplate, template.id.toString()).logWith(this._log);
|
|
839
846
|
}
|
|
847
|
+
const body = template.cache.content;
|
|
840
848
|
const isTemplator = this.parent.accountController.identity.isMe(template.cache.createdBy);
|
|
841
|
-
|
|
842
|
-
|
|
849
|
+
const sharedAt = template.cache.createdAt;
|
|
850
|
+
const sharedBy = isTemplator ? this.parent.accountController.identity.address : relationship.peer.address;
|
|
851
|
+
const sharedWith = isTemplator ? relationship.peer.address : this.parent.accountController.identity.address;
|
|
852
|
+
const sharedItemsWithSameReference = await this.parent.sharedItems.getSharedItems({
|
|
853
|
+
reference: template.id.toString()
|
|
854
|
+
});
|
|
855
|
+
const missingItems = [];
|
|
856
|
+
if (body instanceof content_1.RelationshipTemplateBody) {
|
|
843
857
|
const attributes = body.sharedAttributes;
|
|
844
858
|
if (attributes) {
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
859
|
+
if (sharedItemsWithSameReference.length !== attributes.length) {
|
|
860
|
+
attributes.forEach((attribute) => {
|
|
861
|
+
if (!sharedItemsWithSameReference.find(function (item) {
|
|
862
|
+
const content = item.content;
|
|
863
|
+
return content.name === attribute.name;
|
|
864
|
+
})) {
|
|
865
|
+
missingItems.push(attribute);
|
|
866
|
+
}
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
else {
|
|
872
|
+
// Try to parse the old template format (without types)
|
|
873
|
+
let oldTemplateBody = body;
|
|
874
|
+
if (body instanceof ts_serval_1.JSONWrapper || body instanceof ts_serval_1.JSONWrapperAsync) {
|
|
875
|
+
oldTemplateBody = oldTemplateBody.value;
|
|
876
|
+
}
|
|
877
|
+
if ((oldTemplateBody === null || oldTemplateBody === void 0 ? void 0 : oldTemplateBody.attributes) && Array.isArray(oldTemplateBody.attributes)) {
|
|
878
|
+
if (sharedItemsWithSameReference.length !== oldTemplateBody.attributes.length) {
|
|
879
|
+
oldTemplateBody.attributes.forEach((attribute) => {
|
|
880
|
+
if (!sharedItemsWithSameReference.find(function (item) {
|
|
881
|
+
const content = item.content;
|
|
882
|
+
return content.name === attribute.name;
|
|
883
|
+
})) {
|
|
884
|
+
missingItems.push(content_1.Attribute.from({
|
|
885
|
+
name: attribute.name,
|
|
886
|
+
value: attribute.value
|
|
887
|
+
}));
|
|
888
|
+
}
|
|
861
889
|
});
|
|
862
|
-
await this.parent.sharedItems.createSharedItem(sharedItem);
|
|
863
890
|
}
|
|
864
891
|
}
|
|
865
892
|
}
|
|
893
|
+
for (const attribute of missingItems) {
|
|
894
|
+
const sharedItem = await SharedItem_1.SharedItem.from({
|
|
895
|
+
id: await consumption_1.ConsumptionIds.sharedItem.generate(),
|
|
896
|
+
content: attribute,
|
|
897
|
+
sharedAt: sharedAt,
|
|
898
|
+
sharedBy: sharedBy,
|
|
899
|
+
sharedWith: sharedWith,
|
|
900
|
+
reference: template.id,
|
|
901
|
+
expiresAt: attribute.validTo
|
|
902
|
+
});
|
|
903
|
+
await this.parent.sharedItems.createSharedItem(sharedItem);
|
|
904
|
+
}
|
|
866
905
|
}
|
|
867
906
|
async parseCreationRequest(relationship) {
|
|
868
|
-
const
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
this._log.error(error);
|
|
872
|
-
throw error;
|
|
873
|
-
}
|
|
907
|
+
const change = relationship.cache.creationChange;
|
|
908
|
+
const request = change.request;
|
|
909
|
+
const body = request.content;
|
|
874
910
|
const isRequestor = this.parent.accountController.identity.isMe(request.createdBy);
|
|
875
|
-
|
|
876
|
-
|
|
911
|
+
const sharedAt = request.createdAt;
|
|
912
|
+
const sharedBy = isRequestor ? this.parent.accountController.identity.address : relationship.peer.address;
|
|
913
|
+
const sharedWith = isRequestor ? relationship.peer.address : this.parent.accountController.identity.address;
|
|
914
|
+
const sharedItemsWithSameReference = await this.parent.sharedItems.getSharedItems({
|
|
915
|
+
reference: change.id.toString()
|
|
916
|
+
});
|
|
917
|
+
const missingItems = [];
|
|
918
|
+
if (body instanceof content_1.RelationshipCreationChangeRequestBody) {
|
|
877
919
|
const attributes = body.sharedAttributes;
|
|
878
|
-
if (attributes) {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
const sharedItem = await SharedItem_1.SharedItem.from({
|
|
888
|
-
id: await consumption_1.ConsumptionIds.sharedItem.generate(),
|
|
889
|
-
content: attribute,
|
|
890
|
-
sharedAt: sharedAt,
|
|
891
|
-
sharedBy: sharedBy,
|
|
892
|
-
sharedWith: sharedWith,
|
|
893
|
-
reference: relationship.id,
|
|
894
|
-
expiresAt: attribute.validTo
|
|
920
|
+
if (attributes && attributes.length > 0) {
|
|
921
|
+
if (sharedItemsWithSameReference.length !== attributes.length) {
|
|
922
|
+
attributes.forEach((attribute) => {
|
|
923
|
+
if (!sharedItemsWithSameReference.find(function (item) {
|
|
924
|
+
const content = item.content;
|
|
925
|
+
return content.name === attribute.name;
|
|
926
|
+
})) {
|
|
927
|
+
missingItems.push(attribute);
|
|
928
|
+
}
|
|
895
929
|
});
|
|
896
|
-
await this.parent.sharedItems.createSharedItem(sharedItem);
|
|
897
930
|
}
|
|
898
931
|
}
|
|
899
932
|
}
|
|
900
933
|
else {
|
|
901
|
-
|
|
934
|
+
// Try to parse the old request format (without types)
|
|
935
|
+
let oldRequestBody = body;
|
|
936
|
+
if (body instanceof ts_serval_1.JSONWrapper || body instanceof ts_serval_1.JSONWrapperAsync) {
|
|
937
|
+
oldRequestBody = oldRequestBody.value;
|
|
938
|
+
}
|
|
939
|
+
if (oldRequestBody === null || oldRequestBody === void 0 ? void 0 : oldRequestBody.attributes) {
|
|
940
|
+
const keys = Object.keys(oldRequestBody.attributes);
|
|
941
|
+
if (sharedItemsWithSameReference.length !== keys.length) {
|
|
942
|
+
keys.forEach((key) => {
|
|
943
|
+
const attribute = oldRequestBody.attributes[key];
|
|
944
|
+
if (!sharedItemsWithSameReference.find(function (item) {
|
|
945
|
+
const content = item.content;
|
|
946
|
+
return content.name === attribute.name;
|
|
947
|
+
})) {
|
|
948
|
+
missingItems.push(content_1.Attribute.from({
|
|
949
|
+
name: attribute.name,
|
|
950
|
+
value: attribute.value
|
|
951
|
+
}));
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
for (const attribute of missingItems) {
|
|
958
|
+
const sharedItem = await SharedItem_1.SharedItem.from({
|
|
959
|
+
id: await consumption_1.ConsumptionIds.sharedItem.generate(),
|
|
960
|
+
content: attribute,
|
|
961
|
+
sharedAt: sharedAt,
|
|
962
|
+
sharedBy: sharedBy,
|
|
963
|
+
sharedWith: sharedWith,
|
|
964
|
+
reference: change.id,
|
|
965
|
+
expiresAt: attribute.validTo
|
|
966
|
+
});
|
|
967
|
+
await this.parent.sharedItems.createSharedItem(sharedItem);
|
|
902
968
|
}
|
|
903
969
|
}
|
|
904
970
|
}
|