@nmshd/consumption 1.0.6 → 1.0.10
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/index.d.ts +0 -1
- package/dist/modules/index.js +0 -1
- package/dist/modules/index.js.map +1 -1
- package/dist/modules/relationships/RelationshipInfoController.js +18 -4
- package/dist/modules/relationships/RelationshipInfoController.js.map +1 -1
- package/dist/modules/relationships/RelationshipInfoUtil.d.ts +15 -0
- package/dist/modules/relationships/RelationshipInfoUtil.js +192 -0
- package/dist/modules/relationships/RelationshipInfoUtil.js.map +1 -0
- package/dist/modules/relationships/local/RelationshipInfo.js +1 -1
- package/dist/modules/relationships/local/RelationshipInfo.js.map +1 -1
- package/lib-web/nmshd.consumption.js +135 -132
- 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 +8 -8
- package/dist/modules/relationships/SingleRelationshipController.d.ts +0 -21
- package/dist/modules/relationships/SingleRelationshipController.js +0 -202
- package/dist/modules/relationships/SingleRelationshipController.js.map +0 -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.10",
|
|
21
|
+
build: "12",
|
|
22
|
+
date: "2021-12-23T16:26:55+00:00",
|
|
23
|
+
commit: "d6f4641d66742bf72bc0399783a432af36ef8efc",
|
|
24
24
|
dependencies: {},
|
|
25
25
|
libraries: {
|
|
26
26
|
transport: transport_1.buildInformation,
|
|
@@ -662,7 +662,6 @@ __exportStar(__webpack_require__(/*! ./relationships/local/RelationshipAttribute
|
|
|
662
662
|
__exportStar(__webpack_require__(/*! ./relationships/local/RelationshipInfo */ "./dist/modules/relationships/local/RelationshipInfo.js"), exports);
|
|
663
663
|
__exportStar(__webpack_require__(/*! ./relationships/local/RelationshipTheme */ "./dist/modules/relationships/local/RelationshipTheme.js"), exports);
|
|
664
664
|
__exportStar(__webpack_require__(/*! ./relationships/RelationshipInfoController */ "./dist/modules/relationships/RelationshipInfoController.js"), exports);
|
|
665
|
-
__exportStar(__webpack_require__(/*! ./relationships/SingleRelationshipController */ "./dist/modules/relationships/SingleRelationshipController.js"), exports);
|
|
666
665
|
__exportStar(__webpack_require__(/*! ./requests/local/ConsumptionRequest */ "./dist/modules/requests/local/ConsumptionRequest.js"), exports);
|
|
667
666
|
__exportStar(__webpack_require__(/*! ./requests/RequestsController */ "./dist/modules/requests/RequestsController.js"), exports);
|
|
668
667
|
__exportStar(__webpack_require__(/*! ./settings/local/Setting */ "./dist/modules/settings/local/Setting.js"), exports);
|
|
@@ -686,6 +685,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
686
685
|
exports.RelationshipInfoController = void 0;
|
|
687
686
|
const consumption_1 = __webpack_require__(/*! ../../consumption */ "./dist/consumption/index.js");
|
|
688
687
|
const RelationshipInfo_1 = __webpack_require__(/*! ./local/RelationshipInfo */ "./dist/modules/relationships/local/RelationshipInfo.js");
|
|
688
|
+
const RelationshipInfoUtil_1 = __webpack_require__(/*! ./RelationshipInfoUtil */ "./dist/modules/relationships/RelationshipInfoUtil.js");
|
|
689
689
|
class RelationshipInfoController extends consumption_1.ConsumptionBaseController {
|
|
690
690
|
constructor(parent) {
|
|
691
691
|
super(consumption_1.ConsumptionControllerName.RelationshipInfoController, parent);
|
|
@@ -700,16 +700,29 @@ 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
|
|
704
|
-
return
|
|
703
|
+
const info = await new RelationshipInfoUtil_1.RelationshipInfoUtil(this.parent).createInitialRelationshipInfo(relationshipId);
|
|
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
|
+
*/
|
|
705
718
|
}
|
|
706
719
|
async getRelationshipInfos(query) {
|
|
707
720
|
const items = await this.relationshipInfo.find(query);
|
|
708
721
|
return await this.parseArray(items, RelationshipInfo_1.RelationshipInfo);
|
|
709
722
|
}
|
|
710
723
|
async createRelationshipInfo(relationshipInfo) {
|
|
711
|
-
const
|
|
712
|
-
if (
|
|
724
|
+
const exists = await this.relationshipInfo.exists({ relationshipId: relationshipInfo.relationshipId });
|
|
725
|
+
if (exists) {
|
|
713
726
|
throw consumption_1.ConsumptionErrors.relationshipInfo.relationshipInfoExists(relationshipInfo.relationshipId.toString());
|
|
714
727
|
}
|
|
715
728
|
await this.relationshipInfo.create(relationshipInfo);
|
|
@@ -731,119 +744,86 @@ exports.RelationshipInfoController = RelationshipInfoController;
|
|
|
731
744
|
|
|
732
745
|
/***/ }),
|
|
733
746
|
|
|
734
|
-
/***/ "./dist/modules/relationships/
|
|
735
|
-
|
|
736
|
-
!*** ./dist/modules/relationships/
|
|
737
|
-
|
|
747
|
+
/***/ "./dist/modules/relationships/RelationshipInfoUtil.js":
|
|
748
|
+
/*!************************************************************!*\
|
|
749
|
+
!*** ./dist/modules/relationships/RelationshipInfoUtil.js ***!
|
|
750
|
+
\************************************************************/
|
|
738
751
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
739
752
|
|
|
740
753
|
|
|
741
754
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
742
|
-
exports.
|
|
755
|
+
exports.RelationshipInfoUtil = void 0;
|
|
743
756
|
const content_1 = __webpack_require__(/*! @nmshd/content */ "@nmshd/content");
|
|
744
757
|
const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
|
|
745
758
|
const consumption_1 = __webpack_require__(/*! ../../consumption */ "./dist/consumption/index.js");
|
|
746
759
|
const SharedItem_1 = __webpack_require__(/*! ../sharedItems/local/SharedItem */ "./dist/modules/sharedItems/local/SharedItem.js");
|
|
747
760
|
const RelationshipAttribute_1 = __webpack_require__(/*! ./local/RelationshipAttribute */ "./dist/modules/relationships/local/RelationshipAttribute.js");
|
|
748
761
|
const RelationshipInfo_1 = __webpack_require__(/*! ./local/RelationshipInfo */ "./dist/modules/relationships/local/RelationshipInfo.js");
|
|
749
|
-
class
|
|
762
|
+
class RelationshipInfoUtil {
|
|
750
763
|
constructor(parent) {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
get relationship() {
|
|
754
|
-
return this._relationship;
|
|
764
|
+
this.parent = parent;
|
|
765
|
+
this._log = transport_1.TransportLoggerFactory.getLogger(RelationshipInfoUtil);
|
|
755
766
|
}
|
|
756
|
-
get
|
|
757
|
-
return this.
|
|
758
|
-
}
|
|
759
|
-
get attributeMap() {
|
|
760
|
-
return this._attributeMap;
|
|
767
|
+
get log() {
|
|
768
|
+
return this._log;
|
|
761
769
|
}
|
|
762
|
-
async
|
|
770
|
+
async createInitialRelationshipInfo(id) {
|
|
763
771
|
const relationship = await this.parent.accountController.relationships.getRelationship(id);
|
|
764
772
|
if (!relationship) {
|
|
765
773
|
throw transport_1.TransportErrors.general.recordNotFound(transport_1.Relationship, id.toString()).logWith(this._log);
|
|
766
774
|
}
|
|
767
|
-
return await this.initWithRelationship(relationship);
|
|
768
|
-
}
|
|
769
|
-
async initWithRelationship(relationship) {
|
|
770
|
-
await super.init();
|
|
771
|
-
this._relationship = relationship;
|
|
772
|
-
const info = await this.parent.relationshipInfo.getRelationshipInfoByRelationship(this.relationship.id);
|
|
773
|
-
if (!info) {
|
|
774
|
-
await this.initialFill();
|
|
775
|
-
}
|
|
776
|
-
else {
|
|
777
|
-
const attributeMap = new Map();
|
|
778
|
-
for (const item of info.attributes) {
|
|
779
|
-
attributeMap.set(item.name, item);
|
|
780
|
-
}
|
|
781
|
-
this._attributeMap = attributeMap;
|
|
782
|
-
this._info = info;
|
|
783
|
-
}
|
|
784
|
-
return this;
|
|
785
|
-
}
|
|
786
|
-
async initialFill() {
|
|
787
|
-
const relationship = await this.parent.accountController.relationships.getRelationship(this._relationship.id);
|
|
788
|
-
if (!relationship) {
|
|
789
|
-
throw transport_1.TransportErrors.general
|
|
790
|
-
.recordNotFound(transport_1.Relationship, this._relationship.id.toString())
|
|
791
|
-
.logWith(this._log);
|
|
792
|
-
}
|
|
793
|
-
this._relationship = relationship;
|
|
794
775
|
const template = await this.parent.accountController.relationshipTemplates.getRelationshipTemplate(relationship.cache.template.id);
|
|
795
776
|
if (!template) {
|
|
796
777
|
throw transport_1.TransportErrors.general
|
|
797
778
|
.recordNotFound(transport_1.RelationshipTemplate, relationship.cache.template.id.toString())
|
|
798
779
|
.logWith(this._log);
|
|
799
780
|
}
|
|
800
|
-
await this.parseTemplateBody(template);
|
|
801
|
-
await this.parseCreationRequest();
|
|
802
|
-
|
|
803
|
-
return this;
|
|
781
|
+
await this.parseTemplateBody(relationship, template);
|
|
782
|
+
await this.parseCreationRequest(relationship);
|
|
783
|
+
return await this.createRelationshipInfo(relationship);
|
|
804
784
|
}
|
|
805
|
-
getTitle() {
|
|
785
|
+
getTitle(relationship, attributeMap) {
|
|
806
786
|
var _a, _b, _c, _d, _e, _f;
|
|
807
|
-
let title =
|
|
808
|
-
const
|
|
809
|
-
const
|
|
810
|
-
const
|
|
811
|
-
const gender = (_d =
|
|
812
|
-
const orgname = (_e =
|
|
813
|
-
const
|
|
814
|
-
if (
|
|
815
|
-
title =
|
|
787
|
+
let title = relationship.peer.address.toString().substring(3, 9);
|
|
788
|
+
const thingName = (_a = attributeMap.get("Thing.name")) === null || _a === void 0 ? void 0 : _a.content.value;
|
|
789
|
+
const givenName = (_b = attributeMap.get("Person.givenName")) === null || _b === void 0 ? void 0 : _b.content.value;
|
|
790
|
+
const familyName = (_c = attributeMap.get("Person.familyName")) === null || _c === void 0 ? void 0 : _c.content.value;
|
|
791
|
+
const gender = (_d = attributeMap.get("Person.gender")) === null || _d === void 0 ? void 0 : _d.content.value;
|
|
792
|
+
const orgname = (_e = attributeMap.get("Organization.name")) === null || _e === void 0 ? void 0 : _e.content.value;
|
|
793
|
+
const legalName = (_f = attributeMap.get("Organization.legalname")) === null || _f === void 0 ? void 0 : _f.content.value;
|
|
794
|
+
if (thingName) {
|
|
795
|
+
title = thingName;
|
|
796
|
+
}
|
|
797
|
+
else if (givenName && familyName) {
|
|
798
|
+
title = `${givenName} ${familyName}`;
|
|
816
799
|
}
|
|
817
|
-
else if (
|
|
818
|
-
title =
|
|
800
|
+
else if (givenName) {
|
|
801
|
+
title = givenName;
|
|
819
802
|
}
|
|
820
|
-
else if (
|
|
821
|
-
title =
|
|
803
|
+
else if (familyName && gender) {
|
|
804
|
+
title = `i18n://salutation.gender.${gender} ${familyName}`;
|
|
822
805
|
}
|
|
823
806
|
else if (orgname) {
|
|
824
807
|
title = orgname;
|
|
825
808
|
}
|
|
826
|
-
else if (
|
|
827
|
-
title =
|
|
809
|
+
else if (legalName) {
|
|
810
|
+
title = legalName;
|
|
828
811
|
}
|
|
829
812
|
return title;
|
|
830
813
|
}
|
|
831
|
-
async
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
});
|
|
843
|
-
info = await this.parent.relationshipInfo.createRelationshipInfo(info);
|
|
844
|
-
}
|
|
814
|
+
async createRelationshipInfo(relationship) {
|
|
815
|
+
const peerAddress = relationship.peer.address;
|
|
816
|
+
const truncatedAddress = peerAddress.address.substring(3, 9);
|
|
817
|
+
const info = await RelationshipInfo_1.RelationshipInfo.from({
|
|
818
|
+
attributes: [],
|
|
819
|
+
id: await consumption_1.ConsumptionIds.relationshipInfo.generate(),
|
|
820
|
+
isPinned: false,
|
|
821
|
+
relationshipId: relationship.id,
|
|
822
|
+
title: truncatedAddress
|
|
823
|
+
});
|
|
824
|
+
// info = await this.parent.relationshipInfo.createRelationshipInfo(info)
|
|
845
825
|
const items = await this.parent.sharedItems.getSharedItems({
|
|
846
|
-
sharedBy:
|
|
826
|
+
sharedBy: relationship.peer.address.toString()
|
|
847
827
|
});
|
|
848
828
|
const attributes = [];
|
|
849
829
|
const attributeMap = new Map();
|
|
@@ -858,87 +838,110 @@ class SingleRelationshipController extends consumption_1.ConsumptionBaseControll
|
|
|
858
838
|
attributeMap.set(relAttr.name, relAttr);
|
|
859
839
|
}
|
|
860
840
|
}
|
|
861
|
-
this._attributeMap = attributeMap;
|
|
862
841
|
info.attributes = attributes;
|
|
863
|
-
const title = this.getTitle();
|
|
842
|
+
const title = this.getTitle(relationship, attributeMap);
|
|
864
843
|
info.title = title;
|
|
865
|
-
await this.parent.relationshipInfo.updateRelationshipInfo(info)
|
|
844
|
+
// await this.parent.relationshipInfo.updateRelationshipInfo(info)
|
|
866
845
|
return info;
|
|
867
846
|
}
|
|
868
|
-
async parseTemplateBody(template) {
|
|
847
|
+
async parseTemplateBody(relationship, template) {
|
|
869
848
|
if (!template.cache) {
|
|
870
849
|
throw transport_1.TransportErrors.general.cacheEmpty(transport_1.RelationshipTemplate, template.id.toString()).logWith(this._log);
|
|
871
850
|
}
|
|
872
|
-
const isTemplator = this.parent.accountController.identity.isMe(template.cache.createdBy);
|
|
873
851
|
if (template.cache.content instanceof content_1.RelationshipTemplateBody) {
|
|
852
|
+
const isTemplator = this.parent.accountController.identity.isMe(template.cache.createdBy);
|
|
874
853
|
const body = template.cache.content;
|
|
875
854
|
const attributes = body.sharedAttributes;
|
|
876
855
|
if (attributes) {
|
|
877
856
|
const sharedAt = template.cache.createdAt;
|
|
878
857
|
const sharedBy = isTemplator
|
|
879
858
|
? this.parent.accountController.identity.address
|
|
880
|
-
:
|
|
859
|
+
: relationship.peer.address;
|
|
881
860
|
const sharedWith = isTemplator
|
|
882
|
-
?
|
|
861
|
+
? relationship.peer.address
|
|
883
862
|
: this.parent.accountController.identity.address;
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
863
|
+
const sharedItemsWithSameReference = await this.parent.sharedItems.getSharedItems({
|
|
864
|
+
reference: template.id.toString()
|
|
865
|
+
});
|
|
866
|
+
if (sharedItemsWithSameReference.length !== attributes.length) {
|
|
867
|
+
const missingItems = [];
|
|
868
|
+
attributes.forEach((attribute) => {
|
|
869
|
+
if (!sharedItemsWithSameReference.find(function (item) {
|
|
870
|
+
const content = item.content;
|
|
871
|
+
return content.name === attribute.name;
|
|
872
|
+
})) {
|
|
873
|
+
missingItems.push(attribute);
|
|
874
|
+
}
|
|
893
875
|
});
|
|
894
|
-
|
|
876
|
+
for (const attribute of missingItems) {
|
|
877
|
+
const sharedItem = await SharedItem_1.SharedItem.from({
|
|
878
|
+
id: await consumption_1.ConsumptionIds.sharedItem.generate(),
|
|
879
|
+
content: attribute,
|
|
880
|
+
sharedAt: sharedAt,
|
|
881
|
+
sharedBy: sharedBy,
|
|
882
|
+
sharedWith: sharedWith,
|
|
883
|
+
reference: template.id,
|
|
884
|
+
expiresAt: attribute.validTo
|
|
885
|
+
});
|
|
886
|
+
await this.parent.sharedItems.createSharedItem(sharedItem);
|
|
887
|
+
}
|
|
895
888
|
}
|
|
896
889
|
}
|
|
897
890
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
const request = this.relationship.cache.creationChange.request;
|
|
901
|
-
if (!request.content) {
|
|
902
|
-
const error = new Error("error.consumption.noRequestContent");
|
|
903
|
-
this._log.error(error);
|
|
904
|
-
throw error;
|
|
905
|
-
}
|
|
906
|
-
let isRequestor = false;
|
|
907
|
-
if (this.parent.accountController.identity.isMe(request.createdBy)) {
|
|
908
|
-
isRequestor = true;
|
|
891
|
+
else {
|
|
892
|
+
// do nothing, we don't know the content
|
|
909
893
|
}
|
|
894
|
+
}
|
|
895
|
+
async parseCreationRequest(relationship) {
|
|
896
|
+
const change = relationship.cache.creationChange;
|
|
897
|
+
const request = change.request;
|
|
910
898
|
if (request.content instanceof content_1.RelationshipCreationChangeRequestBody) {
|
|
899
|
+
const isRequestor = this.parent.accountController.identity.isMe(request.createdBy);
|
|
911
900
|
const body = request.content;
|
|
912
901
|
const attributes = body.sharedAttributes;
|
|
913
|
-
if (attributes) {
|
|
902
|
+
if (attributes && attributes.length > 0) {
|
|
914
903
|
const sharedAt = request.createdAt;
|
|
915
904
|
const sharedBy = isRequestor
|
|
916
905
|
? this.parent.accountController.identity.address
|
|
917
|
-
:
|
|
906
|
+
: relationship.peer.address;
|
|
918
907
|
const sharedWith = isRequestor
|
|
919
|
-
?
|
|
908
|
+
? relationship.peer.address
|
|
920
909
|
: this.parent.accountController.identity.address;
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
910
|
+
const sharedItemsWithSameReference = await this.parent.sharedItems.getSharedItems({
|
|
911
|
+
reference: change.id.toString()
|
|
912
|
+
});
|
|
913
|
+
if (sharedItemsWithSameReference.length !== attributes.length) {
|
|
914
|
+
const missingItems = [];
|
|
915
|
+
attributes.forEach((attribute) => {
|
|
916
|
+
if (!sharedItemsWithSameReference.find(function (item) {
|
|
917
|
+
const content = item.content;
|
|
918
|
+
return content.name === attribute.name;
|
|
919
|
+
})) {
|
|
920
|
+
missingItems.push(attribute);
|
|
921
|
+
}
|
|
930
922
|
});
|
|
931
|
-
|
|
923
|
+
for (const attribute of missingItems) {
|
|
924
|
+
const sharedItem = await SharedItem_1.SharedItem.from({
|
|
925
|
+
id: await consumption_1.ConsumptionIds.sharedItem.generate(),
|
|
926
|
+
content: attribute,
|
|
927
|
+
sharedAt: sharedAt,
|
|
928
|
+
sharedBy: sharedBy,
|
|
929
|
+
sharedWith: sharedWith,
|
|
930
|
+
reference: change.id,
|
|
931
|
+
expiresAt: attribute.validTo
|
|
932
|
+
});
|
|
933
|
+
await this.parent.sharedItems.createSharedItem(sharedItem);
|
|
934
|
+
}
|
|
932
935
|
}
|
|
933
936
|
}
|
|
934
937
|
}
|
|
935
938
|
else {
|
|
936
|
-
|
|
939
|
+
// do nothing, we don't know the content
|
|
937
940
|
}
|
|
938
941
|
}
|
|
939
942
|
}
|
|
940
|
-
exports.
|
|
941
|
-
//# sourceMappingURL=
|
|
943
|
+
exports.RelationshipInfoUtil = RelationshipInfoUtil;
|
|
944
|
+
//# sourceMappingURL=RelationshipInfoUtil.js.map
|
|
942
945
|
|
|
943
946
|
/***/ }),
|
|
944
947
|
|
|
@@ -1041,7 +1044,7 @@ let RelationshipInfo = RelationshipInfo_1 = class RelationshipInfo extends trans
|
|
|
1041
1044
|
relationshipId: relationship.id,
|
|
1042
1045
|
attributes: [],
|
|
1043
1046
|
isPinned: false,
|
|
1044
|
-
title: relationship.peer.address.address.
|
|
1047
|
+
title: relationship.peer.address.address.substring(3, 9)
|
|
1045
1048
|
});
|
|
1046
1049
|
}
|
|
1047
1050
|
return await RelationshipInfo_1.from(relationship.metadata);
|