@nmshd/consumption 1.0.8 → 1.0.12
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 +126 -71
- package/dist/modules/relationships/RelationshipInfoUtil.js.map +1 -1
- package/lib-web/nmshd.consumption.js +143 -80
- 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 +11 -11
|
@@ -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: "
|
|
23
|
-
commit: "
|
|
20
|
+
version: "1.0.12",
|
|
21
|
+
build: "14",
|
|
22
|
+
date: "2022-01-18T14:27:09+00:00",
|
|
23
|
+
commit: "1ee413f06c1d4e3b6d09a8bc70e2951d51453196",
|
|
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,56 +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;
|
|
794
797
|
}
|
|
795
|
-
else if (
|
|
796
|
-
title = `i18n://salutation.gender.${gender} ${
|
|
798
|
+
else if (familyName && gender) {
|
|
799
|
+
title = `i18n://salutation.gender.${gender} ${familyName}`;
|
|
797
800
|
}
|
|
798
801
|
else if (orgname) {
|
|
799
802
|
title = orgname;
|
|
800
803
|
}
|
|
801
|
-
else if (
|
|
802
|
-
title =
|
|
804
|
+
else if (legalName) {
|
|
805
|
+
title = legalName;
|
|
803
806
|
}
|
|
804
807
|
return title;
|
|
805
808
|
}
|
|
806
809
|
async createRelationshipInfo(relationship) {
|
|
807
810
|
const peerAddress = relationship.peer.address;
|
|
808
811
|
const truncatedAddress = peerAddress.address.substring(3, 9);
|
|
809
|
-
|
|
812
|
+
const info = await RelationshipInfo_1.RelationshipInfo.from({
|
|
810
813
|
attributes: [],
|
|
811
814
|
id: await consumption_1.ConsumptionIds.relationshipInfo.generate(),
|
|
812
815
|
isPinned: false,
|
|
813
816
|
relationshipId: relationship.id,
|
|
814
817
|
title: truncatedAddress
|
|
815
818
|
});
|
|
816
|
-
info = await this.parent.relationshipInfo.createRelationshipInfo(info)
|
|
819
|
+
// info = await this.parent.relationshipInfo.createRelationshipInfo(info)
|
|
817
820
|
const items = await this.parent.sharedItems.getSharedItems({
|
|
818
821
|
sharedBy: relationship.peer.address.toString()
|
|
819
822
|
});
|
|
@@ -833,75 +836,135 @@ class RelationshipInfoUtil {
|
|
|
833
836
|
info.attributes = attributes;
|
|
834
837
|
const title = this.getTitle(relationship, attributeMap);
|
|
835
838
|
info.title = title;
|
|
836
|
-
await this.parent.relationshipInfo.updateRelationshipInfo(info)
|
|
839
|
+
// await this.parent.relationshipInfo.updateRelationshipInfo(info)
|
|
837
840
|
return info;
|
|
838
841
|
}
|
|
839
|
-
async parseTemplateBody(relationship
|
|
842
|
+
async parseTemplateBody(relationship) {
|
|
843
|
+
const template = relationship.cache.template;
|
|
840
844
|
if (!template.cache) {
|
|
841
845
|
throw transport_1.TransportErrors.general.cacheEmpty(transport_1.RelationshipTemplate, template.id.toString()).logWith(this._log);
|
|
842
846
|
}
|
|
847
|
+
const body = template.cache.content;
|
|
843
848
|
const isTemplator = this.parent.accountController.identity.isMe(template.cache.createdBy);
|
|
844
|
-
|
|
845
|
-
|
|
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) {
|
|
846
857
|
const attributes = body.sharedAttributes;
|
|
847
858
|
if (attributes) {
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
const sharedItem = await SharedItem_1.SharedItem.from({
|
|
857
|
-
id: await consumption_1.ConsumptionIds.sharedItem.generate(),
|
|
858
|
-
content: attribute,
|
|
859
|
-
sharedAt: sharedAt,
|
|
860
|
-
sharedBy: sharedBy,
|
|
861
|
-
sharedWith: sharedWith,
|
|
862
|
-
reference: template.id,
|
|
863
|
-
expiresAt: attribute.validTo
|
|
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
|
+
}
|
|
864
867
|
});
|
|
865
|
-
await this.parent.sharedItems.createSharedItem(sharedItem);
|
|
866
868
|
}
|
|
867
869
|
}
|
|
868
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
|
+
}
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
}
|
|
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
|
+
}
|
|
869
905
|
}
|
|
870
906
|
async parseCreationRequest(relationship) {
|
|
871
|
-
const
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
this._log.error(error);
|
|
875
|
-
throw error;
|
|
876
|
-
}
|
|
907
|
+
const change = relationship.cache.creationChange;
|
|
908
|
+
const request = change.request;
|
|
909
|
+
const body = request.content;
|
|
877
910
|
const isRequestor = this.parent.accountController.identity.isMe(request.createdBy);
|
|
878
|
-
|
|
879
|
-
|
|
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) {
|
|
880
919
|
const attributes = body.sharedAttributes;
|
|
881
|
-
if (attributes) {
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
const sharedItem = await SharedItem_1.SharedItem.from({
|
|
891
|
-
id: await consumption_1.ConsumptionIds.sharedItem.generate(),
|
|
892
|
-
content: attribute,
|
|
893
|
-
sharedAt: sharedAt,
|
|
894
|
-
sharedBy: sharedBy,
|
|
895
|
-
sharedWith: sharedWith,
|
|
896
|
-
reference: relationship.id,
|
|
897
|
-
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
|
+
}
|
|
898
929
|
});
|
|
899
|
-
await this.parent.sharedItems.createSharedItem(sharedItem);
|
|
900
930
|
}
|
|
901
931
|
}
|
|
902
932
|
}
|
|
903
933
|
else {
|
|
904
|
-
|
|
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);
|
|
905
968
|
}
|
|
906
969
|
}
|
|
907
970
|
}
|