@nmshd/consumption 1.0.9 → 1.0.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.
- 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 +112 -57
- package/dist/modules/relationships/RelationshipInfoUtil.js.map +1 -1
- package/lib-web/nmshd.consumption.js +129 -66
- 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 +18 -18
package/dist/buildInformation.js
CHANGED
|
@@ -6,10 +6,10 @@ const content_1 = require("@nmshd/content");
|
|
|
6
6
|
const crypto_1 = require("@nmshd/crypto");
|
|
7
7
|
const transport_1 = require("@nmshd/transport");
|
|
8
8
|
exports.buildInformation = {
|
|
9
|
-
version: "1.0.
|
|
10
|
-
build: "
|
|
11
|
-
date: "
|
|
12
|
-
commit: "
|
|
9
|
+
version: "1.0.13",
|
|
10
|
+
build: "15",
|
|
11
|
+
date: "2022-01-25T16:43:54+00:00",
|
|
12
|
+
commit: "156f0241ed8ffd6909131950abd43936f263fa62",
|
|
13
13
|
dependencies: {},
|
|
14
14
|
libraries: {
|
|
15
15
|
transport: transport_1.buildInformation,
|
|
@@ -18,13 +18,21 @@ class RelationshipInfoController extends consumption_1.ConsumptionBaseController
|
|
|
18
18
|
return result ? await RelationshipInfo_1.RelationshipInfo.from(result) : undefined;
|
|
19
19
|
}
|
|
20
20
|
async getRelationshipInfoByRelationship(relationshipId) {
|
|
21
|
-
const result = await this.relationshipInfo.findOne({ relationshipId: relationshipId.toString() });
|
|
22
|
-
if (result) {
|
|
23
|
-
return await RelationshipInfo_1.RelationshipInfo.from(result);
|
|
24
|
-
}
|
|
25
21
|
const info = await new RelationshipInfoUtil_1.RelationshipInfoUtil(this.parent).createInitialRelationshipInfo(relationshipId);
|
|
26
|
-
await this.relationshipInfo.create(info);
|
|
27
22
|
return info;
|
|
23
|
+
/*
|
|
24
|
+
// So far, do not store the relationshipInfo, as they wouldn't be updated correctly
|
|
25
|
+
|
|
26
|
+
const result = await this.relationshipInfo.findOne({ relationshipId: relationshipId.toString() })
|
|
27
|
+
|
|
28
|
+
if (result) {
|
|
29
|
+
return await RelationshipInfo.from(result)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const info = await new RelationshipInfoUtil(this.parent).createInitialRelationshipInfo(relationshipId)
|
|
33
|
+
await this.relationshipInfo.create(info)
|
|
34
|
+
return info
|
|
35
|
+
*/
|
|
28
36
|
}
|
|
29
37
|
async getRelationshipInfos(query) {
|
|
30
38
|
const items = await this.relationshipInfo.find(query);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationshipInfoController.js","sourceRoot":"","sources":["../../../src/modules/relationships/RelationshipInfoController.ts"],"names":[],"mappings":";;;AACA,mDAA2G;AAE3G,+DAA2D;AAC3D,iEAA6D;AAE7D,MAAa,0BAA2B,SAAQ,uCAAyB;IAGrE,YAAmB,MAA6B;QAC5C,KAAK,CAAC,uCAAyB,CAAC,0BAA0B,EAAE,MAAM,CAAC,CAAA;IACvE,CAAC;IAEM,KAAK,CAAC,IAAI;QACb,MAAM,KAAK,CAAC,IAAI,EAAE,CAAA;QAElB,IAAI,CAAC,gBAAgB,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,yBAAyB,CAAC,kBAAkB,CAAC,CAAA;QACzG,OAAO,IAAI,CAAA;IACf,CAAC;IAEM,KAAK,CAAC,mBAAmB,CAAC,EAAU;QACvC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC9D,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,mCAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IACnE,CAAC;IAEM,KAAK,CAAC,iCAAiC,CAAC,cAAsB;QACjE,MAAM,
|
|
1
|
+
{"version":3,"file":"RelationshipInfoController.js","sourceRoot":"","sources":["../../../src/modules/relationships/RelationshipInfoController.ts"],"names":[],"mappings":";;;AACA,mDAA2G;AAE3G,+DAA2D;AAC3D,iEAA6D;AAE7D,MAAa,0BAA2B,SAAQ,uCAAyB;IAGrE,YAAmB,MAA6B;QAC5C,KAAK,CAAC,uCAAyB,CAAC,0BAA0B,EAAE,MAAM,CAAC,CAAA;IACvE,CAAC;IAEM,KAAK,CAAC,IAAI;QACb,MAAM,KAAK,CAAC,IAAI,EAAE,CAAA;QAElB,IAAI,CAAC,gBAAgB,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,yBAAyB,CAAC,kBAAkB,CAAC,CAAA;QACzG,OAAO,IAAI,CAAA;IACf,CAAC;IAEM,KAAK,CAAC,mBAAmB,CAAC,EAAU;QACvC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC9D,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,mCAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IACnE,CAAC;IAEM,KAAK,CAAC,iCAAiC,CAAC,cAAsB;QACjE,MAAM,IAAI,GAAG,MAAM,IAAI,2CAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,6BAA6B,CAAC,cAAc,CAAC,CAAA;QACtG,OAAO,IAAI,CAAA;QACX;;;;;;;;;;;;UAYE;IACN,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAAC,KAAW;QACzC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACrD,OAAO,MAAM,IAAI,CAAC,UAAU,CAAmB,KAAK,EAAE,mCAAgB,CAAC,CAAA;IAC3E,CAAC;IAEM,KAAK,CAAC,sBAAsB,CAAC,gBAAkC;QAClE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,gBAAgB,CAAC,cAAc,EAAE,CAAC,CAAA;QACtG,IAAI,MAAM,EAAE;YACR,MAAM,+BAAiB,CAAC,gBAAgB,CAAC,sBAAsB,CAAC,gBAAgB,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAA;SAC9G;QAED,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;QACpD,OAAO,gBAAgB,CAAA;IAC3B,CAAC;IAEM,KAAK,CAAC,sBAAsB,CAAC,gBAAkC;QAClE,MAAM,mBAAmB,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC5F,IAAI,CAAC,mBAAmB,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;SAChD;QACD,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,CAAA;IAC7E,CAAC;IAEM,KAAK,CAAC,sBAAsB,CAAC,gBAAkC;QAClE,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;IACxD,CAAC;CACJ;AA/DD,gEA+DC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RelationshipInfoUtil = void 0;
|
|
4
|
+
const ts_serval_1 = require("@js-soft/ts-serval");
|
|
4
5
|
const content_1 = require("@nmshd/content");
|
|
5
6
|
const transport_1 = require("@nmshd/transport");
|
|
6
7
|
const consumption_1 = require("../../consumption");
|
|
@@ -20,13 +21,7 @@ class RelationshipInfoUtil {
|
|
|
20
21
|
if (!relationship) {
|
|
21
22
|
throw transport_1.TransportErrors.general.recordNotFound(transport_1.Relationship, id.toString()).logWith(this._log);
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
if (!template) {
|
|
25
|
-
throw transport_1.TransportErrors.general
|
|
26
|
-
.recordNotFound(transport_1.RelationshipTemplate, relationship.cache.template.id.toString())
|
|
27
|
-
.logWith(this._log);
|
|
28
|
-
}
|
|
29
|
-
await this.parseTemplateBody(relationship, template);
|
|
24
|
+
await this.parseTemplateBody(relationship);
|
|
30
25
|
await this.parseCreationRequest(relationship);
|
|
31
26
|
return await this.createRelationshipInfo(relationship);
|
|
32
27
|
}
|
|
@@ -62,14 +57,14 @@ class RelationshipInfoUtil {
|
|
|
62
57
|
async createRelationshipInfo(relationship) {
|
|
63
58
|
const peerAddress = relationship.peer.address;
|
|
64
59
|
const truncatedAddress = peerAddress.address.substring(3, 9);
|
|
65
|
-
|
|
60
|
+
const info = await RelationshipInfo_1.RelationshipInfo.from({
|
|
66
61
|
attributes: [],
|
|
67
62
|
id: await consumption_1.ConsumptionIds.relationshipInfo.generate(),
|
|
68
63
|
isPinned: false,
|
|
69
64
|
relationshipId: relationship.id,
|
|
70
65
|
title: truncatedAddress
|
|
71
66
|
});
|
|
72
|
-
info = await this.parent.relationshipInfo.createRelationshipInfo(info)
|
|
67
|
+
// info = await this.parent.relationshipInfo.createRelationshipInfo(info)
|
|
73
68
|
const items = await this.parent.sharedItems.getSharedItems({
|
|
74
69
|
sharedBy: relationship.peer.address.toString()
|
|
75
70
|
});
|
|
@@ -89,75 +84,135 @@ class RelationshipInfoUtil {
|
|
|
89
84
|
info.attributes = attributes;
|
|
90
85
|
const title = this.getTitle(relationship, attributeMap);
|
|
91
86
|
info.title = title;
|
|
92
|
-
await this.parent.relationshipInfo.updateRelationshipInfo(info)
|
|
87
|
+
// await this.parent.relationshipInfo.updateRelationshipInfo(info)
|
|
93
88
|
return info;
|
|
94
89
|
}
|
|
95
|
-
async parseTemplateBody(relationship
|
|
90
|
+
async parseTemplateBody(relationship) {
|
|
91
|
+
const template = relationship.cache.template;
|
|
96
92
|
if (!template.cache) {
|
|
97
93
|
throw transport_1.TransportErrors.general.cacheEmpty(transport_1.RelationshipTemplate, template.id.toString()).logWith(this._log);
|
|
98
94
|
}
|
|
95
|
+
const body = template.cache.content;
|
|
99
96
|
const isTemplator = this.parent.accountController.identity.isMe(template.cache.createdBy);
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
const sharedAt = template.cache.createdAt;
|
|
98
|
+
const sharedBy = isTemplator ? this.parent.accountController.identity.address : relationship.peer.address;
|
|
99
|
+
const sharedWith = isTemplator ? relationship.peer.address : this.parent.accountController.identity.address;
|
|
100
|
+
const sharedItemsWithSameReference = await this.parent.sharedItems.getSharedItems({
|
|
101
|
+
reference: template.id.toString()
|
|
102
|
+
});
|
|
103
|
+
const missingItems = [];
|
|
104
|
+
if (body instanceof content_1.RelationshipTemplateBody) {
|
|
102
105
|
const attributes = body.sharedAttributes;
|
|
103
106
|
if (attributes) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const sharedItem = await SharedItem_1.SharedItem.from({
|
|
113
|
-
id: await consumption_1.ConsumptionIds.sharedItem.generate(),
|
|
114
|
-
content: attribute,
|
|
115
|
-
sharedAt: sharedAt,
|
|
116
|
-
sharedBy: sharedBy,
|
|
117
|
-
sharedWith: sharedWith,
|
|
118
|
-
reference: template.id,
|
|
119
|
-
expiresAt: attribute.validTo
|
|
107
|
+
if (sharedItemsWithSameReference.length !== attributes.length) {
|
|
108
|
+
attributes.forEach((attribute) => {
|
|
109
|
+
if (!sharedItemsWithSameReference.find(function (item) {
|
|
110
|
+
const content = item.content;
|
|
111
|
+
return content.name === attribute.name;
|
|
112
|
+
})) {
|
|
113
|
+
missingItems.push(attribute);
|
|
114
|
+
}
|
|
120
115
|
});
|
|
121
|
-
await this.parent.sharedItems.createSharedItem(sharedItem);
|
|
122
116
|
}
|
|
123
117
|
}
|
|
124
118
|
}
|
|
119
|
+
else {
|
|
120
|
+
// Try to parse the old template format (without types)
|
|
121
|
+
let oldTemplateBody = body;
|
|
122
|
+
if (body instanceof ts_serval_1.JSONWrapper || body instanceof ts_serval_1.JSONWrapperAsync) {
|
|
123
|
+
oldTemplateBody = oldTemplateBody.value;
|
|
124
|
+
}
|
|
125
|
+
if ((oldTemplateBody === null || oldTemplateBody === void 0 ? void 0 : oldTemplateBody.attributes) && Array.isArray(oldTemplateBody.attributes)) {
|
|
126
|
+
if (sharedItemsWithSameReference.length !== oldTemplateBody.attributes.length) {
|
|
127
|
+
oldTemplateBody.attributes.forEach((attribute) => {
|
|
128
|
+
if (!sharedItemsWithSameReference.find(function (item) {
|
|
129
|
+
const content = item.content;
|
|
130
|
+
return content.name === attribute.name;
|
|
131
|
+
})) {
|
|
132
|
+
missingItems.push(content_1.Attribute.from({
|
|
133
|
+
name: attribute.name,
|
|
134
|
+
value: attribute.value
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
for (const attribute of missingItems) {
|
|
142
|
+
const sharedItem = await SharedItem_1.SharedItem.from({
|
|
143
|
+
id: await consumption_1.ConsumptionIds.sharedItem.generate(),
|
|
144
|
+
content: attribute,
|
|
145
|
+
sharedAt: sharedAt,
|
|
146
|
+
sharedBy: sharedBy,
|
|
147
|
+
sharedWith: sharedWith,
|
|
148
|
+
reference: template.id,
|
|
149
|
+
expiresAt: attribute.validTo
|
|
150
|
+
});
|
|
151
|
+
await this.parent.sharedItems.createSharedItem(sharedItem);
|
|
152
|
+
}
|
|
125
153
|
}
|
|
126
154
|
async parseCreationRequest(relationship) {
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
this._log.error(error);
|
|
131
|
-
throw error;
|
|
132
|
-
}
|
|
155
|
+
const change = relationship.cache.creationChange;
|
|
156
|
+
const request = change.request;
|
|
157
|
+
const body = request.content;
|
|
133
158
|
const isRequestor = this.parent.accountController.identity.isMe(request.createdBy);
|
|
134
|
-
|
|
135
|
-
|
|
159
|
+
const sharedAt = request.createdAt;
|
|
160
|
+
const sharedBy = isRequestor ? this.parent.accountController.identity.address : relationship.peer.address;
|
|
161
|
+
const sharedWith = isRequestor ? relationship.peer.address : this.parent.accountController.identity.address;
|
|
162
|
+
const sharedItemsWithSameReference = await this.parent.sharedItems.getSharedItems({
|
|
163
|
+
reference: change.id.toString()
|
|
164
|
+
});
|
|
165
|
+
const missingItems = [];
|
|
166
|
+
if (body instanceof content_1.RelationshipCreationChangeRequestBody) {
|
|
136
167
|
const attributes = body.sharedAttributes;
|
|
137
|
-
if (attributes) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const sharedItem = await SharedItem_1.SharedItem.from({
|
|
147
|
-
id: await consumption_1.ConsumptionIds.sharedItem.generate(),
|
|
148
|
-
content: attribute,
|
|
149
|
-
sharedAt: sharedAt,
|
|
150
|
-
sharedBy: sharedBy,
|
|
151
|
-
sharedWith: sharedWith,
|
|
152
|
-
reference: relationship.id,
|
|
153
|
-
expiresAt: attribute.validTo
|
|
168
|
+
if (attributes && attributes.length > 0) {
|
|
169
|
+
if (sharedItemsWithSameReference.length !== attributes.length) {
|
|
170
|
+
attributes.forEach((attribute) => {
|
|
171
|
+
if (!sharedItemsWithSameReference.find(function (item) {
|
|
172
|
+
const content = item.content;
|
|
173
|
+
return content.name === attribute.name;
|
|
174
|
+
})) {
|
|
175
|
+
missingItems.push(attribute);
|
|
176
|
+
}
|
|
154
177
|
});
|
|
155
|
-
await this.parent.sharedItems.createSharedItem(sharedItem);
|
|
156
178
|
}
|
|
157
179
|
}
|
|
158
180
|
}
|
|
159
181
|
else {
|
|
160
|
-
|
|
182
|
+
// Try to parse the old request format (without types)
|
|
183
|
+
let oldRequestBody = body;
|
|
184
|
+
if (body instanceof ts_serval_1.JSONWrapper || body instanceof ts_serval_1.JSONWrapperAsync) {
|
|
185
|
+
oldRequestBody = oldRequestBody.value;
|
|
186
|
+
}
|
|
187
|
+
if (oldRequestBody === null || oldRequestBody === void 0 ? void 0 : oldRequestBody.attributes) {
|
|
188
|
+
const keys = Object.keys(oldRequestBody.attributes);
|
|
189
|
+
if (sharedItemsWithSameReference.length !== keys.length) {
|
|
190
|
+
keys.forEach((key) => {
|
|
191
|
+
const attribute = oldRequestBody.attributes[key];
|
|
192
|
+
if (!sharedItemsWithSameReference.find(function (item) {
|
|
193
|
+
const content = item.content;
|
|
194
|
+
return content.name === attribute.name;
|
|
195
|
+
})) {
|
|
196
|
+
missingItems.push(content_1.Attribute.from({
|
|
197
|
+
name: attribute.name,
|
|
198
|
+
value: attribute.value
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
for (const attribute of missingItems) {
|
|
206
|
+
const sharedItem = await SharedItem_1.SharedItem.from({
|
|
207
|
+
id: await consumption_1.ConsumptionIds.sharedItem.generate(),
|
|
208
|
+
content: attribute,
|
|
209
|
+
sharedAt: sharedAt,
|
|
210
|
+
sharedBy: sharedBy,
|
|
211
|
+
sharedWith: sharedWith,
|
|
212
|
+
reference: change.id,
|
|
213
|
+
expiresAt: attribute.validTo
|
|
214
|
+
});
|
|
215
|
+
await this.parent.sharedItems.createSharedItem(sharedItem);
|
|
161
216
|
}
|
|
162
217
|
}
|
|
163
218
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationshipInfoUtil.js","sourceRoot":"","sources":["../../../src/modules/relationships/RelationshipInfoUtil.ts"],"names":[],"mappings":";;;AACA,4CAA2G;AAC3G,gDAAsH;AACtH,m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7D;IACL,CAAC;CACJ;AAvOD,oDAuOC"}
|
|
@@ -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.13",
|
|
21
|
+
build: "15",
|
|
22
|
+
date: "2022-01-25T16:43:54+00:00",
|
|
23
|
+
commit: "156f0241ed8ffd6909131950abd43936f263fa62",
|
|
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,13 +773,7 @@ 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
|
}
|
|
@@ -806,14 +809,14 @@ class RelationshipInfoUtil {
|
|
|
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
|
}
|