@nmshd/consumption 1.0.4 → 1.0.8

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.4",
21
- build: "6",
22
- date: "2021-10-06T06:30:32+00:00",
23
- commit: "286e36bf8f9b387c8af71750cd20651fd452a350",
20
+ version: "1.0.8",
21
+ build: "10",
22
+ date: "2021-12-21T11:35:37+00:00",
23
+ commit: "e189079c9274efcc9566b4bf154380e663c07ae8",
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,94 +736,64 @@ 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
  }
817
789
  else if (firstname && lastname) {
818
790
  title = `${firstname} ${lastname}`;
819
791
  }
792
+ else if (firstname) {
793
+ title = firstname;
794
+ }
820
795
  else if (lastname && gender) {
821
- title = `~~gender.salutation.${gender}~~ ${lastname}`;
796
+ title = `i18n://salutation.gender.${gender} ${lastname}`;
822
797
  }
823
798
  else if (orgname) {
824
799
  title = orgname;
@@ -828,22 +803,19 @@ class SingleRelationshipController extends consumption_1.ConsumptionBaseControll
828
803
  }
829
804
  return title;
830
805
  }
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
- }
806
+ async createRelationshipInfo(relationship) {
807
+ const peerAddress = relationship.peer.address;
808
+ const truncatedAddress = peerAddress.address.substring(3, 9);
809
+ let info = await RelationshipInfo_1.RelationshipInfo.from({
810
+ attributes: [],
811
+ id: await consumption_1.ConsumptionIds.relationshipInfo.generate(),
812
+ isPinned: false,
813
+ relationshipId: relationship.id,
814
+ title: truncatedAddress
815
+ });
816
+ info = await this.parent.relationshipInfo.createRelationshipInfo(info);
845
817
  const items = await this.parent.sharedItems.getSharedItems({
846
- sharedBy: this.relationship.peer.address.toString()
818
+ sharedBy: relationship.peer.address.toString()
847
819
  });
848
820
  const attributes = [];
849
821
  const attributeMap = new Map();
@@ -858,14 +830,13 @@ class SingleRelationshipController extends consumption_1.ConsumptionBaseControll
858
830
  attributeMap.set(relAttr.name, relAttr);
859
831
  }
860
832
  }
861
- this._attributeMap = attributeMap;
862
833
  info.attributes = attributes;
863
- const title = this.getTitle();
834
+ const title = this.getTitle(relationship, attributeMap);
864
835
  info.title = title;
865
836
  await this.parent.relationshipInfo.updateRelationshipInfo(info);
866
837
  return info;
867
838
  }
868
- async parseTemplateBody(template) {
839
+ async parseTemplateBody(relationship, template) {
869
840
  if (!template.cache) {
870
841
  throw transport_1.TransportErrors.general.cacheEmpty(transport_1.RelationshipTemplate, template.id.toString()).logWith(this._log);
871
842
  }
@@ -877,9 +848,9 @@ class SingleRelationshipController extends consumption_1.ConsumptionBaseControll
877
848
  const sharedAt = template.cache.createdAt;
878
849
  const sharedBy = isTemplator
879
850
  ? this.parent.accountController.identity.address
880
- : this.relationship.peer.address;
851
+ : relationship.peer.address;
881
852
  const sharedWith = isTemplator
882
- ? this.relationship.peer.address
853
+ ? relationship.peer.address
883
854
  : this.parent.accountController.identity.address;
884
855
  for (const attribute of attributes) {
885
856
  const sharedItem = await SharedItem_1.SharedItem.from({
@@ -896,17 +867,14 @@ class SingleRelationshipController extends consumption_1.ConsumptionBaseControll
896
867
  }
897
868
  }
898
869
  }
899
- async parseCreationRequest() {
900
- const request = this.relationship.cache.creationChange.request;
870
+ async parseCreationRequest(relationship) {
871
+ const request = relationship.cache.creationChange.request;
901
872
  if (!request.content) {
902
873
  const error = new Error("error.consumption.noRequestContent");
903
874
  this._log.error(error);
904
875
  throw error;
905
876
  }
906
- let isRequestor = false;
907
- if (this.parent.accountController.identity.isMe(request.createdBy)) {
908
- isRequestor = true;
909
- }
877
+ const isRequestor = this.parent.accountController.identity.isMe(request.createdBy);
910
878
  if (request.content instanceof content_1.RelationshipCreationChangeRequestBody) {
911
879
  const body = request.content;
912
880
  const attributes = body.sharedAttributes;
@@ -914,9 +882,9 @@ class SingleRelationshipController extends consumption_1.ConsumptionBaseControll
914
882
  const sharedAt = request.createdAt;
915
883
  const sharedBy = isRequestor
916
884
  ? this.parent.accountController.identity.address
917
- : this.relationship.peer.address;
885
+ : relationship.peer.address;
918
886
  const sharedWith = isRequestor
919
- ? this.relationship.peer.address
887
+ ? relationship.peer.address
920
888
  : this.parent.accountController.identity.address;
921
889
  for (const attribute of attributes) {
922
890
  const sharedItem = await SharedItem_1.SharedItem.from({
@@ -925,7 +893,7 @@ class SingleRelationshipController extends consumption_1.ConsumptionBaseControll
925
893
  sharedAt: sharedAt,
926
894
  sharedBy: sharedBy,
927
895
  sharedWith: sharedWith,
928
- reference: this.relationship.id,
896
+ reference: relationship.id,
929
897
  expiresAt: attribute.validTo
930
898
  });
931
899
  await this.parent.sharedItems.createSharedItem(sharedItem);
@@ -937,8 +905,8 @@ class SingleRelationshipController extends consumption_1.ConsumptionBaseControll
937
905
  }
938
906
  }
939
907
  }
940
- exports.SingleRelationshipController = SingleRelationshipController;
941
- //# sourceMappingURL=SingleRelationshipController.js.map
908
+ exports.RelationshipInfoUtil = RelationshipInfoUtil;
909
+ //# sourceMappingURL=RelationshipInfoUtil.js.map
942
910
 
943
911
  /***/ }),
944
912
 
@@ -1041,7 +1009,7 @@ let RelationshipInfo = RelationshipInfo_1 = class RelationshipInfo extends trans
1041
1009
  relationshipId: relationship.id,
1042
1010
  attributes: [],
1043
1011
  isPinned: false,
1044
- title: relationship.peer.address.address.substr(3, 6)
1012
+ title: relationship.peer.address.address.substring(3, 9)
1045
1013
  });
1046
1014
  }
1047
1015
  return await RelationshipInfo_1.from(relationship.metadata);