@nmshd/consumption 1.0.6 → 1.0.7

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.
@@ -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.6",
21
- build: "8",
22
- date: "2021-12-16T08:02:38+00:00",
23
- commit: "e2e727f2a3dfde6caf4e61184236a297e82f4784",
20
+ version: "1.0.7",
21
+ build: "9",
22
+ date: "2021-12-21T11:15:38+00:00",
23
+ commit: "e78278e1413f85e42e794e13e6d65b9c51906bc1",
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);
@@ -701,15 +701,20 @@ class RelationshipInfoController extends consumption_1.ConsumptionBaseController
701
701
  }
702
702
  async getRelationshipInfoByRelationship(relationshipId) {
703
703
  const result = await this.relationshipInfo.findOne({ relationshipId: relationshipId.toString() });
704
- return result ? await RelationshipInfo_1.RelationshipInfo.from(result) : undefined;
704
+ if (result) {
705
+ return await RelationshipInfo_1.RelationshipInfo.from(result);
706
+ }
707
+ const info = await new RelationshipInfoUtil_1.RelationshipInfoUtil(this.parent).createInitialRelationshipInfo(relationshipId);
708
+ await this.relationshipInfo.create(info);
709
+ return info;
705
710
  }
706
711
  async getRelationshipInfos(query) {
707
712
  const items = await this.relationshipInfo.find(query);
708
713
  return await this.parseArray(items, RelationshipInfo_1.RelationshipInfo);
709
714
  }
710
715
  async createRelationshipInfo(relationshipInfo) {
711
- const current = await this.getRelationshipInfoByRelationship(relationshipInfo.relationshipId);
712
- if (current) {
716
+ const exists = await this.relationshipInfo.exists({ relationshipId: relationshipInfo.relationshipId });
717
+ if (exists) {
713
718
  throw consumption_1.ConsumptionErrors.relationshipInfo.relationshipInfoExists(relationshipInfo.relationshipId.toString());
714
719
  }
715
720
  await this.relationshipInfo.create(relationshipInfo);
@@ -731,86 +736,53 @@ exports.RelationshipInfoController = RelationshipInfoController;
731
736
 
732
737
  /***/ }),
733
738
 
734
- /***/ "./dist/modules/relationships/SingleRelationshipController.js":
735
- /*!********************************************************************!*\
736
- !*** ./dist/modules/relationships/SingleRelationshipController.js ***!
737
- \********************************************************************/
739
+ /***/ "./dist/modules/relationships/RelationshipInfoUtil.js":
740
+ /*!************************************************************!*\
741
+ !*** ./dist/modules/relationships/RelationshipInfoUtil.js ***!
742
+ \************************************************************/
738
743
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
739
744
 
740
745
 
741
746
  Object.defineProperty(exports, "__esModule", ({ value: true }));
742
- exports.SingleRelationshipController = void 0;
747
+ exports.RelationshipInfoUtil = void 0;
743
748
  const content_1 = __webpack_require__(/*! @nmshd/content */ "@nmshd/content");
744
749
  const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
745
750
  const consumption_1 = __webpack_require__(/*! ../../consumption */ "./dist/consumption/index.js");
746
751
  const SharedItem_1 = __webpack_require__(/*! ../sharedItems/local/SharedItem */ "./dist/modules/sharedItems/local/SharedItem.js");
747
752
  const RelationshipAttribute_1 = __webpack_require__(/*! ./local/RelationshipAttribute */ "./dist/modules/relationships/local/RelationshipAttribute.js");
748
753
  const RelationshipInfo_1 = __webpack_require__(/*! ./local/RelationshipInfo */ "./dist/modules/relationships/local/RelationshipInfo.js");
749
- class SingleRelationshipController extends consumption_1.ConsumptionBaseController {
754
+ class RelationshipInfoUtil {
750
755
  constructor(parent) {
751
- super(consumption_1.ConsumptionControllerName.SingleRelationshipController, parent);
752
- }
753
- get relationship() {
754
- return this._relationship;
755
- }
756
- get info() {
757
- return this._info;
756
+ this.parent = parent;
757
+ this._log = transport_1.TransportLoggerFactory.getLogger(RelationshipInfoUtil);
758
758
  }
759
- get attributeMap() {
760
- return this._attributeMap;
759
+ get log() {
760
+ return this._log;
761
761
  }
762
- async initWithRelationshipId(id) {
762
+ async createInitialRelationshipInfo(id) {
763
763
  const relationship = await this.parent.accountController.relationships.getRelationship(id);
764
764
  if (!relationship) {
765
765
  throw transport_1.TransportErrors.general.recordNotFound(transport_1.Relationship, id.toString()).logWith(this._log);
766
766
  }
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
767
  const template = await this.parent.accountController.relationshipTemplates.getRelationshipTemplate(relationship.cache.template.id);
795
768
  if (!template) {
796
769
  throw transport_1.TransportErrors.general
797
770
  .recordNotFound(transport_1.RelationshipTemplate, relationship.cache.template.id.toString())
798
771
  .logWith(this._log);
799
772
  }
800
- await this.parseTemplateBody(template);
801
- await this.parseCreationRequest();
802
- this._info = await this.updateRelationshipInfo();
803
- return this;
773
+ await this.parseTemplateBody(relationship, template);
774
+ await this.parseCreationRequest(relationship);
775
+ return await this.createRelationshipInfo(relationship);
804
776
  }
805
- getTitle() {
777
+ getTitle(relationship, attributeMap) {
806
778
  var _a, _b, _c, _d, _e, _f;
807
- let title = this.relationship.peer.address.toString().substr(3, 6);
808
- const thingname = (_a = this.attributeMap.get("Thing.name")) === null || _a === void 0 ? void 0 : _a.content.value;
809
- const firstname = (_b = this.attributeMap.get("Person.firstname")) === null || _b === void 0 ? void 0 : _b.content.value;
810
- const lastname = (_c = this.attributeMap.get("Person.lastname")) === null || _c === void 0 ? void 0 : _c.content.value;
811
- const gender = (_d = this.attributeMap.get("Person.gender")) === null || _d === void 0 ? void 0 : _d.content.value;
812
- const orgname = (_e = this.attributeMap.get("Organization.name")) === null || _e === void 0 ? void 0 : _e.content.value;
813
- const legalname = (_f = this.attributeMap.get("Organization.legalname")) === null || _f === void 0 ? void 0 : _f.content.value;
779
+ let title = relationship.peer.address.toString().substring(3, 9);
780
+ const thingname = (_a = attributeMap.get("Thing.name")) === null || _a === void 0 ? void 0 : _a.content.value;
781
+ const firstname = (_b = attributeMap.get("Person.firstname")) === null || _b === void 0 ? void 0 : _b.content.value;
782
+ const lastname = (_c = attributeMap.get("Person.lastname")) === null || _c === void 0 ? void 0 : _c.content.value;
783
+ const gender = (_d = attributeMap.get("Person.gender")) === null || _d === void 0 ? void 0 : _d.content.value;
784
+ const orgname = (_e = attributeMap.get("Organization.name")) === null || _e === void 0 ? void 0 : _e.content.value;
785
+ const legalname = (_f = attributeMap.get("Organization.legalname")) === null || _f === void 0 ? void 0 : _f.content.value;
814
786
  if (thingname) {
815
787
  title = thingname;
816
788
  }
@@ -828,22 +800,19 @@ class SingleRelationshipController extends consumption_1.ConsumptionBaseControll
828
800
  }
829
801
  return title;
830
802
  }
831
- async updateRelationshipInfo() {
832
- let info = await this.parent.relationshipInfo.getRelationshipInfoByRelationship(this.relationship.id);
833
- if (!info) {
834
- const peerAddress = this.relationship.peer.address;
835
- const truncatedAddress = peerAddress.address.substr(3, 6);
836
- info = await RelationshipInfo_1.RelationshipInfo.from({
837
- attributes: [],
838
- id: await consumption_1.ConsumptionIds.relationshipInfo.generate(),
839
- isPinned: false,
840
- relationshipId: this.relationship.id,
841
- title: truncatedAddress
842
- });
843
- info = await this.parent.relationshipInfo.createRelationshipInfo(info);
844
- }
803
+ async createRelationshipInfo(relationship) {
804
+ const peerAddress = relationship.peer.address;
805
+ const truncatedAddress = peerAddress.address.substring(3, 9);
806
+ let info = await RelationshipInfo_1.RelationshipInfo.from({
807
+ attributes: [],
808
+ id: await consumption_1.ConsumptionIds.relationshipInfo.generate(),
809
+ isPinned: false,
810
+ relationshipId: relationship.id,
811
+ title: truncatedAddress
812
+ });
813
+ info = await this.parent.relationshipInfo.createRelationshipInfo(info);
845
814
  const items = await this.parent.sharedItems.getSharedItems({
846
- sharedBy: this.relationship.peer.address.toString()
815
+ sharedBy: relationship.peer.address.toString()
847
816
  });
848
817
  const attributes = [];
849
818
  const attributeMap = new Map();
@@ -858,14 +827,13 @@ class SingleRelationshipController extends consumption_1.ConsumptionBaseControll
858
827
  attributeMap.set(relAttr.name, relAttr);
859
828
  }
860
829
  }
861
- this._attributeMap = attributeMap;
862
830
  info.attributes = attributes;
863
- const title = this.getTitle();
831
+ const title = this.getTitle(relationship, attributeMap);
864
832
  info.title = title;
865
833
  await this.parent.relationshipInfo.updateRelationshipInfo(info);
866
834
  return info;
867
835
  }
868
- async parseTemplateBody(template) {
836
+ async parseTemplateBody(relationship, template) {
869
837
  if (!template.cache) {
870
838
  throw transport_1.TransportErrors.general.cacheEmpty(transport_1.RelationshipTemplate, template.id.toString()).logWith(this._log);
871
839
  }
@@ -877,9 +845,9 @@ class SingleRelationshipController extends consumption_1.ConsumptionBaseControll
877
845
  const sharedAt = template.cache.createdAt;
878
846
  const sharedBy = isTemplator
879
847
  ? this.parent.accountController.identity.address
880
- : this.relationship.peer.address;
848
+ : relationship.peer.address;
881
849
  const sharedWith = isTemplator
882
- ? this.relationship.peer.address
850
+ ? relationship.peer.address
883
851
  : this.parent.accountController.identity.address;
884
852
  for (const attribute of attributes) {
885
853
  const sharedItem = await SharedItem_1.SharedItem.from({
@@ -896,17 +864,14 @@ class SingleRelationshipController extends consumption_1.ConsumptionBaseControll
896
864
  }
897
865
  }
898
866
  }
899
- async parseCreationRequest() {
900
- const request = this.relationship.cache.creationChange.request;
867
+ async parseCreationRequest(relationship) {
868
+ const request = relationship.cache.creationChange.request;
901
869
  if (!request.content) {
902
870
  const error = new Error("error.consumption.noRequestContent");
903
871
  this._log.error(error);
904
872
  throw error;
905
873
  }
906
- let isRequestor = false;
907
- if (this.parent.accountController.identity.isMe(request.createdBy)) {
908
- isRequestor = true;
909
- }
874
+ const isRequestor = this.parent.accountController.identity.isMe(request.createdBy);
910
875
  if (request.content instanceof content_1.RelationshipCreationChangeRequestBody) {
911
876
  const body = request.content;
912
877
  const attributes = body.sharedAttributes;
@@ -914,9 +879,9 @@ class SingleRelationshipController extends consumption_1.ConsumptionBaseControll
914
879
  const sharedAt = request.createdAt;
915
880
  const sharedBy = isRequestor
916
881
  ? this.parent.accountController.identity.address
917
- : this.relationship.peer.address;
882
+ : relationship.peer.address;
918
883
  const sharedWith = isRequestor
919
- ? this.relationship.peer.address
884
+ ? relationship.peer.address
920
885
  : this.parent.accountController.identity.address;
921
886
  for (const attribute of attributes) {
922
887
  const sharedItem = await SharedItem_1.SharedItem.from({
@@ -925,7 +890,7 @@ class SingleRelationshipController extends consumption_1.ConsumptionBaseControll
925
890
  sharedAt: sharedAt,
926
891
  sharedBy: sharedBy,
927
892
  sharedWith: sharedWith,
928
- reference: this.relationship.id,
893
+ reference: relationship.id,
929
894
  expiresAt: attribute.validTo
930
895
  });
931
896
  await this.parent.sharedItems.createSharedItem(sharedItem);
@@ -937,8 +902,8 @@ class SingleRelationshipController extends consumption_1.ConsumptionBaseControll
937
902
  }
938
903
  }
939
904
  }
940
- exports.SingleRelationshipController = SingleRelationshipController;
941
- //# sourceMappingURL=SingleRelationshipController.js.map
905
+ exports.RelationshipInfoUtil = RelationshipInfoUtil;
906
+ //# sourceMappingURL=RelationshipInfoUtil.js.map
942
907
 
943
908
  /***/ }),
944
909
 
@@ -1041,7 +1006,7 @@ let RelationshipInfo = RelationshipInfo_1 = class RelationshipInfo extends trans
1041
1006
  relationshipId: relationship.id,
1042
1007
  attributes: [],
1043
1008
  isPinned: false,
1044
- title: relationship.peer.address.address.substr(3, 6)
1009
+ title: relationship.peer.address.address.substring(3, 9)
1045
1010
  });
1046
1011
  }
1047
1012
  return await RelationshipInfo_1.from(relationship.metadata);