@nmshd/runtime 1.2.12 → 1.2.13

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.
@@ -1,9 +1,18 @@
1
+ import { RelationshipChangeStatus, RelationshipChangeType } from "@nmshd/transport";
1
2
  import { DataViewObject } from "../DataViewObject";
3
+ export declare enum RelationshipDirection {
4
+ Outgoing = "Outgoing",
5
+ Incoming = "Incoming"
6
+ }
2
7
  export interface RelationshipDVO extends DataViewObject {
3
8
  type: "RelationshipDVO";
4
9
  status: string;
10
+ direction: string;
11
+ statusText: string;
5
12
  isPinned: boolean;
6
13
  theme: RelationshipTheme;
14
+ changes: RelationshipChangeDVO[];
15
+ changeCount: number;
7
16
  }
8
17
  export interface RelationshipTheme {
9
18
  image?: string;
@@ -11,3 +20,27 @@ export interface RelationshipTheme {
11
20
  backgroundColor?: string;
12
21
  foregroundColor?: string;
13
22
  }
23
+ export interface RelationshipChangeDVO extends DataViewObject {
24
+ type: "RelationshipChangeDVO";
25
+ request: RelationshipChangeRequestDVO;
26
+ response?: RelationshipChangeResponseDVO;
27
+ status: RelationshipChangeStatus;
28
+ statusText: string;
29
+ changeType: RelationshipChangeType;
30
+ changeTypeText: string;
31
+ isOwn: boolean;
32
+ }
33
+ export interface RelationshipChangeRequestDVO extends DataViewObject {
34
+ type: "RelationshipChangeRequestDVO";
35
+ createdBy: string;
36
+ createdByDevice: string;
37
+ createdAt: string;
38
+ content?: any;
39
+ }
40
+ export interface RelationshipChangeResponseDVO extends DataViewObject {
41
+ type: "RelationshipChangeResponseDVO";
42
+ createdBy: string;
43
+ createdByDevice: string;
44
+ createdAt: string;
45
+ content?: any;
46
+ }
@@ -1,3 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RelationshipDirection = void 0;
4
+ var RelationshipDirection;
5
+ (function (RelationshipDirection) {
6
+ RelationshipDirection["Outgoing"] = "Outgoing";
7
+ RelationshipDirection["Incoming"] = "Incoming";
8
+ })(RelationshipDirection = exports.RelationshipDirection || (exports.RelationshipDirection = {}));
3
9
  //# sourceMappingURL=RelationshipDVO.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RelationshipDVO.js","sourceRoot":"","sources":["../../../src/dataViews/transport/RelationshipDVO.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"RelationshipDVO.js","sourceRoot":"","sources":["../../../src/dataViews/transport/RelationshipDVO.ts"],"names":[],"mappings":";;;AAGA,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC7B,8CAAqB,CAAA;IACrB,8CAAqB,CAAA;AACzB,CAAC,EAHW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAGhC"}
@@ -327,10 +327,10 @@ const content_1 = __webpack_require__(/*! @nmshd/content */ "@nmshd/content");
327
327
  const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
328
328
  const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
329
329
  exports.buildInformation = {
330
- version: "1.2.12",
331
- build: "27",
332
- date: "2022-01-11T08:20:35+00:00",
333
- commit: "1d2fdee12e0673b3e7dfbed11a83f6f500a5b313",
330
+ version: "1.2.13",
331
+ build: "28",
332
+ date: "2022-01-12T08:46:15+00:00",
333
+ commit: "a0ed72318e8869b87437d358cc1dd94685fa1644",
334
334
  dependencies: {"@js-soft/docdb-querytranslator":"1.0.1","@js-soft/logging-abstractions":"1.0.0","@js-soft/ts-serval":"1.0.2","@js-soft/ts-utils":"^1.1.1","@nmshd/consumption":"1.0.11","@nmshd/content":"1.1.2","@nmshd/crypto":"1.0.6","@nmshd/transport":"1.1.5","ajv":"^8.8.2","ajv-errors":"^3.0.0","ajv-formats":"^2.1.1","fluent-ts-validator":"3.0.2","json-stringify-safe":"^5.0.1","luxon":"^2.3.0","qrcode":"1.5.0","reflect-metadata":"0.1.13","ts-simple-nameof":"1.3.1","typescript-ioc":"3.2.2"},
335
335
  libraries: {
336
336
  serval: ts_serval_1.buildInformation,
@@ -373,6 +373,7 @@ const ConsumptionServices_1 = __webpack_require__(/*! ../extensibility/Consumpti
373
373
  const useCases_1 = __webpack_require__(/*! ../useCases */ "./dist/useCases/index.js");
374
374
  const DataViewTranslateable_1 = __webpack_require__(/*! ./DataViewTranslateable */ "./dist/dataViews/DataViewTranslateable.js");
375
375
  const MessageDVO_1 = __webpack_require__(/*! ./transport/MessageDVO */ "./dist/dataViews/transport/MessageDVO.js");
376
+ const RelationshipDVO_1 = __webpack_require__(/*! ./transport/RelationshipDVO */ "./dist/dataViews/transport/RelationshipDVO.js");
376
377
  let DataViewExpander = class DataViewExpander {
377
378
  constructor(transport, consumption, identityController) {
378
379
  this.transport = transport;
@@ -461,6 +462,8 @@ let DataViewExpander = class DataViewExpander {
461
462
  }
462
463
  async expandMessageDTO(message) {
463
464
  const recipientRelationships = await this.expandRecipients(message.recipients);
465
+ const addressMap = {};
466
+ recipientRelationships.forEach((value) => (addressMap[value.id] = value));
464
467
  const createdByRelationship = await this.expandAddress(message.createdBy);
465
468
  const fileIds = [];
466
469
  const filePromises = [];
@@ -476,13 +479,19 @@ let DataViewExpander = class DataViewExpander {
476
479
  }
477
480
  const files = await Promise.all(filePromises);
478
481
  const isOwn = this.identityController.isMe(transport_1.CoreAddress.from(message.createdBy));
482
+ let peer;
479
483
  let status = MessageDVO_1.MessageStatus.Received;
480
484
  if (isOwn) {
481
485
  const receivedByEveryone = message.recipients.every((r) => !!r.receivedAt);
482
486
  status = receivedByEveryone ? MessageDVO_1.MessageStatus.Delivered : MessageDVO_1.MessageStatus.Delivering;
487
+ // Overwrite the RecipientDVO to be a IdentityDVO for this special case
488
+ peer = { ...recipientRelationships[0], type: "IdentityDVO" };
489
+ }
490
+ else {
491
+ peer = createdByRelationship;
483
492
  }
484
493
  const name = DataViewTranslateable_1.DataViewTranslateable.transport.messageName;
485
- const value = {
494
+ const messageDVO = {
486
495
  id: message.id,
487
496
  name: name,
488
497
  date: message.createdAt,
@@ -496,38 +505,42 @@ let DataViewExpander = class DataViewExpander {
496
505
  recipientCount: message.recipients.length,
497
506
  attachmentCount: message.attachments.length,
498
507
  status,
499
- image: ""
508
+ statusText: `i18n://dvo.message.${status}`,
509
+ image: "",
510
+ peer: peer
500
511
  };
501
512
  if (message.content["@type"] === "Mail" || message.content["@type"] === "RequestMail") {
502
- value.name = DataViewTranslateable_1.DataViewTranslateable.consumption.mails.mailSubjectFallback;
503
- value.type = "MailDVO";
504
513
  const mailContent = message.content;
505
- if (mailContent.subject) {
506
- value.name = mailContent.subject;
507
- }
508
- value.to = await this.expandAddresses(mailContent.to);
509
- value.toCount = mailContent.to.length;
510
- value.ccCount = 0;
514
+ const to = mailContent.to.map((value) => addressMap[value]);
515
+ let cc = [];
511
516
  if (mailContent.cc) {
512
- value.cc = await this.expandAddresses(mailContent.cc);
513
- value.ccCount = mailContent.cc.length;
517
+ cc = mailContent.cc.map((value) => addressMap[value]);
514
518
  }
515
- value.subject = mailContent.subject;
516
- value.body = mailContent.body;
519
+ const mailDVO = {
520
+ ...messageDVO,
521
+ type: "MailDVO",
522
+ name: mailContent.subject ? mailContent.subject : DataViewTranslateable_1.DataViewTranslateable.consumption.mails.mailSubjectFallback,
523
+ subject: mailContent.subject,
524
+ body: mailContent.body,
525
+ to: to,
526
+ toCount: mailContent.to.length,
527
+ cc: cc,
528
+ ccCount: cc.length
529
+ };
517
530
  if (mailContent["@type"] === "RequestMail") {
518
531
  const requestMailContent = message.content;
519
- value.name = DataViewTranslateable_1.DataViewTranslateable.consumption.mails.requestMailSubjectFallback;
520
- if (requestMailContent.subject) {
521
- value.name = requestMailContent.subject;
522
- }
523
- value.type = "RequestMailDVO";
524
- value.requests = await this.expandUnknownRequests(requestMailContent.requests);
525
- value.requestCount = requestMailContent.requests.length;
526
- return value;
532
+ const requestMailDVO = {
533
+ ...mailDVO,
534
+ type: "RequestMailDVO",
535
+ name: requestMailContent.subject ? requestMailContent.subject : DataViewTranslateable_1.DataViewTranslateable.consumption.mails.requestMailSubjectFallback,
536
+ requests: await this.expandUnknownRequests(requestMailContent.requests),
537
+ requestCount: requestMailContent.requests.length
538
+ };
539
+ return requestMailDVO;
527
540
  }
528
- return value;
541
+ return mailDVO;
529
542
  }
530
- return value;
543
+ return messageDVO;
531
544
  }
532
545
  async expandMessageDTOs(messages) {
533
546
  const messagePromises = messages.map((message) => this.expandMessageDTO(message));
@@ -632,7 +645,8 @@ let DataViewExpander = class DataViewExpander {
632
645
  value: attribute.content.value,
633
646
  date: attribute.createdAt,
634
647
  isOwn: true,
635
- sharedItems: []
648
+ sharedItems: [],
649
+ sharedItemCount: 0
636
650
  };
637
651
  }
638
652
  async expandConsumptionAttributes(attributes) {
@@ -654,6 +668,7 @@ let DataViewExpander = class DataViewExpander {
654
668
  id: name,
655
669
  name: name,
656
670
  matches: matchedAttributes,
671
+ matchCount: matchedAttributes.length,
657
672
  bestMatch: bestMatch
658
673
  };
659
674
  }
@@ -696,13 +711,24 @@ let DataViewExpander = class DataViewExpander {
696
711
  else {
697
712
  name = DataViewTranslateable_1.DataViewTranslateable.consumption.requests.attributesChangeRequestName;
698
713
  }
714
+ const changes = [];
715
+ attributesObjects.forEach((attribute, index) => {
716
+ changes.push({
717
+ oldAttribute: oldAttributesObjects[index],
718
+ newAttribute: attribute
719
+ });
720
+ });
699
721
  return {
700
722
  ...request,
701
723
  type: "AttributesChangeRequestDVO",
702
724
  name: name,
703
725
  newAttributes: attributesObjects,
726
+ newAttributeCount: attributesObjects.length,
704
727
  oldAttributes: oldAttributesObjects,
705
- applyTo: applyToObject
728
+ oldAttributeCount: oldAttributesObjects.length,
729
+ applyTo: applyToObject,
730
+ changes: changes,
731
+ changeCount: changes.length
706
732
  };
707
733
  }
708
734
  async expandAttributesRequest(attributesRequest) {
@@ -719,8 +745,10 @@ let DataViewExpander = class DataViewExpander {
719
745
  ...request,
720
746
  type: "AttributesRequestDVO",
721
747
  names: attributesRequest.names,
748
+ nameCount: attributesRequest.names.length,
722
749
  name: name,
723
750
  attributes: attributesObjects,
751
+ attributeCount: attributesObjects.length,
724
752
  required: attributesRequest.required
725
753
  };
726
754
  }
@@ -775,18 +803,69 @@ let DataViewExpander = class DataViewExpander {
775
803
  const relationshipPromises = addresses.map((address) => this.expandAddress(address));
776
804
  return await Promise.all(relationshipPromises);
777
805
  }
806
+ async expandRecipient(recipient) {
807
+ const identity = await this.expandAddress(recipient.address);
808
+ return {
809
+ ...identity,
810
+ type: "RecipientDVO",
811
+ receivedAt: recipient.receivedAt,
812
+ receivedByDevice: recipient.receivedByDevice
813
+ };
814
+ }
778
815
  async expandRecipients(recipients) {
779
- const relationshipPromises = recipients.map((recipient) => this.expandAddress(recipient.address));
816
+ const relationshipPromises = recipients.map((recipient) => this.expandRecipient(recipient));
780
817
  return await Promise.all(relationshipPromises);
781
818
  }
819
+ expandRelationshipChange(relationship, change) {
820
+ const date = change.response ? change.response.createdAt : change.request.createdAt;
821
+ let isOwn = false;
822
+ if (this.identityController.isMe(transport_1.CoreAddress.from(change.request.createdBy))) {
823
+ isOwn = true;
824
+ }
825
+ let response;
826
+ if (change.response) {
827
+ response = {
828
+ ...change.response,
829
+ id: `${change.id}_response`,
830
+ name: "i18n://dvo.relationshipChange.response.name",
831
+ type: "RelationshipChangeResponseDVO"
832
+ };
833
+ }
834
+ return Promise.resolve({
835
+ type: "RelationshipChangeDVO",
836
+ id: change.id,
837
+ name: "",
838
+ date: date,
839
+ status: change.status,
840
+ statusText: `i18n://dvo.relationshipChange.${change.status}`,
841
+ changeType: change.type,
842
+ changeTypeText: `i18n://dvo.relationshipChange.${change.type}`,
843
+ isOwn: isOwn,
844
+ request: {
845
+ ...change.request,
846
+ id: `${change.id}_request`,
847
+ name: "i18n://dvo.relationshipChange.request.name",
848
+ type: "RelationshipChangeRequestDVO"
849
+ },
850
+ response: response
851
+ });
852
+ }
853
+ async expandRelationshipChanges(relationship) {
854
+ const changePromises = relationship.changes.map((change) => this.expandRelationshipChange(relationship, change));
855
+ return await Promise.all(changePromises);
856
+ }
782
857
  async createRelationshipDVO(relationship, relationshipInfo) {
783
858
  var _a, _b, _c, _d;
784
859
  if (!relationshipInfo) {
785
860
  const relationshipInfoResult = await this.consumption.relationshipInfo.getRelationshipInfoByRelationship({ relationshipId: relationship.id });
786
861
  relationshipInfo = relationshipInfoResult.value;
787
862
  }
863
+ let direction = RelationshipDVO_1.RelationshipDirection.Incoming;
864
+ if (this.identityController.isMe(transport_1.CoreAddress.from(relationship.changes[0].request.createdBy))) {
865
+ direction = RelationshipDVO_1.RelationshipDirection.Outgoing;
866
+ }
788
867
  let statusText = "";
789
- if (relationship.status === transport_1.RelationshipStatus.Pending && this.identityController.isMe(transport_1.CoreAddress.from(relationship.changes[0].request.createdBy))) {
868
+ if (relationship.status === transport_1.RelationshipStatus.Pending && direction === RelationshipDVO_1.RelationshipDirection.Outgoing) {
790
869
  statusText = DataViewTranslateable_1.DataViewTranslateable.transport.relationshipOutgoing;
791
870
  }
792
871
  else if (relationship.status === transport_1.RelationshipStatus.Pending) {
@@ -801,6 +880,7 @@ let DataViewExpander = class DataViewExpander {
801
880
  else if (relationship.status === transport_1.RelationshipStatus.Active) {
802
881
  statusText = DataViewTranslateable_1.DataViewTranslateable.transport.relationshipActive;
803
882
  }
883
+ const changes = await this.expandRelationshipChanges(relationship);
804
884
  return {
805
885
  id: relationship.id,
806
886
  name: relationshipInfo.userTitle ? relationshipInfo.userTitle : relationshipInfo.title,
@@ -808,14 +888,18 @@ let DataViewExpander = class DataViewExpander {
808
888
  date: relationship.changes[0].request.createdAt,
809
889
  image: "",
810
890
  type: "RelationshipDVO",
811
- status: statusText,
891
+ status: relationship.status,
892
+ statusText: statusText,
893
+ direction: direction,
812
894
  isPinned: relationshipInfo.isPinned,
813
895
  theme: {
814
896
  image: (_a = relationshipInfo.theme) === null || _a === void 0 ? void 0 : _a.image,
815
897
  headerImage: (_b = relationshipInfo.theme) === null || _b === void 0 ? void 0 : _b.imageBar,
816
898
  backgroundColor: (_c = relationshipInfo.theme) === null || _c === void 0 ? void 0 : _c.backgroundColor,
817
899
  foregroundColor: (_d = relationshipInfo.theme) === null || _d === void 0 ? void 0 : _d.foregroundColor
818
- }
900
+ },
901
+ changes: changes,
902
+ changeCount: changes.length
819
903
  };
820
904
  }
821
905
  async expandRelationshipDTO(relationship) {
@@ -827,7 +911,7 @@ let DataViewExpander = class DataViewExpander {
827
911
  const initials = ((_a = name.match(/\b\w/g)) !== null && _a !== void 0 ? _a : []).join("");
828
912
  const relationshipDVO = await this.createRelationshipDVO(relationship, relationshipInfo);
829
913
  if (!description) {
830
- description = relationshipDVO.status;
914
+ description = relationshipDVO.statusText;
831
915
  }
832
916
  return {
833
917
  type: "IdentityDVO",
@@ -950,11 +1034,11 @@ exports.DataViewTranslateable = DataViewTranslateable;
950
1034
  DataViewTranslateable.prefix = "i18n://dvo.";
951
1035
  DataViewTranslateable.transport = {
952
1036
  messageName: `${DataViewTranslateable.prefix}message.name`,
953
- relationshipOutgoing: `${DataViewTranslateable.prefix}relationship.outgoing`,
954
- relationshipIncoming: `${DataViewTranslateable.prefix}relationship.incoming`,
955
- relationshipRejected: `${DataViewTranslateable.prefix}relationship.rejected`,
956
- relationshipRevoked: `${DataViewTranslateable.prefix}relationship.revoked`,
957
- relationshipActive: `${DataViewTranslateable.prefix}relationship.active`,
1037
+ relationshipOutgoing: `${DataViewTranslateable.prefix}relationship.Outgoing`,
1038
+ relationshipIncoming: `${DataViewTranslateable.prefix}relationship.Incoming`,
1039
+ relationshipRejected: `${DataViewTranslateable.prefix}relationship.Rejected`,
1040
+ relationshipRevoked: `${DataViewTranslateable.prefix}relationship.Revoked`,
1041
+ relationshipActive: `${DataViewTranslateable.prefix}relationship.Active`,
958
1042
  fileName: `${DataViewTranslateable.prefix}file.name`
959
1043
  };
960
1044
  DataViewTranslateable.consumption = {
@@ -1208,10 +1292,18 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
1208
1292
  exports.MessageStatus = void 0;
1209
1293
  var MessageStatus;
1210
1294
  (function (MessageStatus) {
1211
- MessageStatus["Received"] = "received";
1212
- MessageStatus["Delivering"] = "delivering";
1213
- MessageStatus["Delivered"] = "delivered";
1214
- MessageStatus["Errorneous"] = "errorneous";
1295
+ /**
1296
+ * Message was received
1297
+ */
1298
+ MessageStatus["Received"] = "Received";
1299
+ /**
1300
+ * Message was sent but is not yet received by every recipient
1301
+ */
1302
+ MessageStatus["Delivering"] = "Delivering";
1303
+ /**
1304
+ * Message was sent and was received by every recipient
1305
+ */
1306
+ MessageStatus["Delivered"] = "Delivered";
1215
1307
  })(MessageStatus = exports.MessageStatus || (exports.MessageStatus = {}));
1216
1308
  //# sourceMappingURL=MessageDVO.js.map
1217
1309
 
@@ -1226,6 +1318,12 @@ var MessageStatus;
1226
1318
  "use strict";
1227
1319
 
1228
1320
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1321
+ exports.RelationshipDirection = void 0;
1322
+ var RelationshipDirection;
1323
+ (function (RelationshipDirection) {
1324
+ RelationshipDirection["Outgoing"] = "Outgoing";
1325
+ RelationshipDirection["Incoming"] = "Incoming";
1326
+ })(RelationshipDirection = exports.RelationshipDirection || (exports.RelationshipDirection = {}));
1229
1327
  //# sourceMappingURL=RelationshipDVO.js.map
1230
1328
 
1231
1329
  /***/ }),