@nmshd/consumption 1.0.10 → 1.0.11
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/RelationshipInfoUtil.js +90 -62
- package/dist/modules/relationships/RelationshipInfoUtil.js.map +1 -1
- package/lib-web/nmshd.consumption.js +94 -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 +1 -1
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: "2021-12-
|
|
12
|
-
commit: "
|
|
9
|
+
version: "1.0.11",
|
|
10
|
+
build: "13",
|
|
11
|
+
date: "2021-12-29T14:32:15+00:00",
|
|
12
|
+
commit: "be407a6eedf0b92497314484fefd282be5ba6254",
|
|
13
13
|
dependencies: {},
|
|
14
14
|
libraries: {
|
|
15
15
|
transport: transport_1.buildInformation,
|
|
@@ -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
|
}
|
|
@@ -92,27 +87,24 @@ class RelationshipInfoUtil {
|
|
|
92
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
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
const body = template.cache.content;
|
|
96
|
+
const isTemplator = this.parent.accountController.identity.isMe(template.cache.createdBy);
|
|
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
|
-
const sharedAt = template.cache.createdAt;
|
|
105
|
-
const sharedBy = isTemplator
|
|
106
|
-
? this.parent.accountController.identity.address
|
|
107
|
-
: relationship.peer.address;
|
|
108
|
-
const sharedWith = isTemplator
|
|
109
|
-
? relationship.peer.address
|
|
110
|
-
: this.parent.accountController.identity.address;
|
|
111
|
-
const sharedItemsWithSameReference = await this.parent.sharedItems.getSharedItems({
|
|
112
|
-
reference: template.id.toString()
|
|
113
|
-
});
|
|
114
107
|
if (sharedItemsWithSameReference.length !== attributes.length) {
|
|
115
|
-
const missingItems = [];
|
|
116
108
|
attributes.forEach((attribute) => {
|
|
117
109
|
if (!sharedItemsWithSameReference.find(function (item) {
|
|
118
110
|
const content = item.content;
|
|
@@ -121,45 +113,60 @@ class RelationshipInfoUtil {
|
|
|
121
113
|
missingItems.push(attribute);
|
|
122
114
|
}
|
|
123
115
|
});
|
|
124
|
-
for (const attribute of missingItems) {
|
|
125
|
-
const sharedItem = await SharedItem_1.SharedItem.from({
|
|
126
|
-
id: await consumption_1.ConsumptionIds.sharedItem.generate(),
|
|
127
|
-
content: attribute,
|
|
128
|
-
sharedAt: sharedAt,
|
|
129
|
-
sharedBy: sharedBy,
|
|
130
|
-
sharedWith: sharedWith,
|
|
131
|
-
reference: template.id,
|
|
132
|
-
expiresAt: attribute.validTo
|
|
133
|
-
});
|
|
134
|
-
await this.parent.sharedItems.createSharedItem(sharedItem);
|
|
135
|
-
}
|
|
136
116
|
}
|
|
137
117
|
}
|
|
138
118
|
}
|
|
139
119
|
else {
|
|
140
|
-
//
|
|
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);
|
|
141
152
|
}
|
|
142
153
|
}
|
|
143
154
|
async parseCreationRequest(relationship) {
|
|
144
155
|
const change = relationship.cache.creationChange;
|
|
145
156
|
const request = change.request;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
157
|
+
const body = request.content;
|
|
158
|
+
const isRequestor = this.parent.accountController.identity.isMe(request.createdBy);
|
|
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) {
|
|
149
167
|
const attributes = body.sharedAttributes;
|
|
150
168
|
if (attributes && attributes.length > 0) {
|
|
151
|
-
const sharedAt = request.createdAt;
|
|
152
|
-
const sharedBy = isRequestor
|
|
153
|
-
? this.parent.accountController.identity.address
|
|
154
|
-
: relationship.peer.address;
|
|
155
|
-
const sharedWith = isRequestor
|
|
156
|
-
? relationship.peer.address
|
|
157
|
-
: this.parent.accountController.identity.address;
|
|
158
|
-
const sharedItemsWithSameReference = await this.parent.sharedItems.getSharedItems({
|
|
159
|
-
reference: change.id.toString()
|
|
160
|
-
});
|
|
161
169
|
if (sharedItemsWithSameReference.length !== attributes.length) {
|
|
162
|
-
const missingItems = [];
|
|
163
170
|
attributes.forEach((attribute) => {
|
|
164
171
|
if (!sharedItemsWithSameReference.find(function (item) {
|
|
165
172
|
const content = item.content;
|
|
@@ -168,23 +175,44 @@ class RelationshipInfoUtil {
|
|
|
168
175
|
missingItems.push(attribute);
|
|
169
176
|
}
|
|
170
177
|
});
|
|
171
|
-
for (const attribute of missingItems) {
|
|
172
|
-
const sharedItem = await SharedItem_1.SharedItem.from({
|
|
173
|
-
id: await consumption_1.ConsumptionIds.sharedItem.generate(),
|
|
174
|
-
content: attribute,
|
|
175
|
-
sharedAt: sharedAt,
|
|
176
|
-
sharedBy: sharedBy,
|
|
177
|
-
sharedWith: sharedWith,
|
|
178
|
-
reference: change.id,
|
|
179
|
-
expiresAt: attribute.validTo
|
|
180
|
-
});
|
|
181
|
-
await this.parent.sharedItems.createSharedItem(sharedItem);
|
|
182
|
-
}
|
|
183
178
|
}
|
|
184
179
|
}
|
|
185
180
|
}
|
|
186
181
|
else {
|
|
187
|
-
//
|
|
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);
|
|
188
216
|
}
|
|
189
217
|
}
|
|
190
218
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationshipInfoUtil.js","sourceRoot":"","sources":["../../../src/modules/relationships/RelationshipInfoUtil.ts"],"names":[],"mappings":";;;AACA,4CAA2G;AAC3G,gDAAsH;AACtH,mDAAkD;AAElD,gEAA4D;AAC5D,yEAAqE;AACrE,+DAA2D;AAE3D,MAAa,oBAAoB;IAM7B,YAAoC,MAA6B;QAA7B,WAAM,GAAN,MAAM,CAAuB;QAC7D,IAAI,CAAC,IAAI,GAAG,kCAAsB,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAA;IACtE,CAAC;IAND,IAAW,GAAG;QACV,OAAO,IAAI,CAAC,IAAI,CAAA;IACpB,CAAC;IAMM,KAAK,CAAC,6BAA6B,CAAC,EAAU;QACjD,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC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GAAG,CAAC,CAAA;wBAChD,IACI,CAAC,4BAA4B,CAAC,IAAI,CAAC,UAAU,IAAI;4BAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAoB,CAAA;4BACzC,OAAO,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAAA;wBAC1C,CAAC,CAAC,EACJ;4BACE,YAAY,CAAC,IAAI,CACb,mBAAS,CAAC,IAAI,CAAC;gCACX,IAAI,EAAE,SAAS,CAAC,IAAI;gCACpB,KAAK,EAAE,SAAS,CAAC,KAAK;6BACzB,CAAC,CACL,CAAA;yBACJ;oBACL,CAAC,CAAC,CAAA;iBACL;aACJ;SACJ;QAED,KAAK,MAAM,SAAS,IAAI,YAAY,EAAE;YAClC,MAAM,UAAU,GAAG,MAAM,uBAAU,CAAC,IAAI,CAAC;gBACrC,EAAE,EAAE,MAAM,4BAAc,CAAC,UAAU,CAAC,QAAQ,EAAE;gBAC9C,OAAO,EAAE,SAAS;gBAClB,QAAQ,EAAE,QAAQ;gBAClB,QAAQ,EAAE,QAAQ;gBAClB,UAAU,EAAE,UAAU;gBACtB,SAAS,EAAE,MAAM,CAAC,EAAE;gBACpB,SAAS,EAAE,SAAS,CAAC,OAAO;aAC/B,CAAC,CAAA;YACF,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAA;SAC7D;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: "2021-12-
|
|
23
|
-
commit: "
|
|
20
|
+
version: "1.0.11",
|
|
21
|
+
build: "13",
|
|
22
|
+
date: "2021-12-29T14:32:15+00:00",
|
|
23
|
+
commit: "be407a6eedf0b92497314484fefd282be5ba6254",
|
|
24
24
|
dependencies: {},
|
|
25
25
|
libraries: {
|
|
26
26
|
transport: transport_1.buildInformation,
|
|
@@ -753,6 +753,7 @@ exports.RelationshipInfoController = RelationshipInfoController;
|
|
|
753
753
|
|
|
754
754
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
755
755
|
exports.RelationshipInfoUtil = void 0;
|
|
756
|
+
const ts_serval_1 = __webpack_require__(/*! @js-soft/ts-serval */ "@js-soft/ts-serval");
|
|
756
757
|
const content_1 = __webpack_require__(/*! @nmshd/content */ "@nmshd/content");
|
|
757
758
|
const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
|
|
758
759
|
const consumption_1 = __webpack_require__(/*! ../../consumption */ "./dist/consumption/index.js");
|
|
@@ -772,13 +773,7 @@ class RelationshipInfoUtil {
|
|
|
772
773
|
if (!relationship) {
|
|
773
774
|
throw transport_1.TransportErrors.general.recordNotFound(transport_1.Relationship, id.toString()).logWith(this._log);
|
|
774
775
|
}
|
|
775
|
-
|
|
776
|
-
if (!template) {
|
|
777
|
-
throw transport_1.TransportErrors.general
|
|
778
|
-
.recordNotFound(transport_1.RelationshipTemplate, relationship.cache.template.id.toString())
|
|
779
|
-
.logWith(this._log);
|
|
780
|
-
}
|
|
781
|
-
await this.parseTemplateBody(relationship, template);
|
|
776
|
+
await this.parseTemplateBody(relationship);
|
|
782
777
|
await this.parseCreationRequest(relationship);
|
|
783
778
|
return await this.createRelationshipInfo(relationship);
|
|
784
779
|
}
|
|
@@ -844,27 +839,24 @@ class RelationshipInfoUtil {
|
|
|
844
839
|
// await this.parent.relationshipInfo.updateRelationshipInfo(info)
|
|
845
840
|
return info;
|
|
846
841
|
}
|
|
847
|
-
async parseTemplateBody(relationship
|
|
842
|
+
async parseTemplateBody(relationship) {
|
|
843
|
+
const template = relationship.cache.template;
|
|
848
844
|
if (!template.cache) {
|
|
849
845
|
throw transport_1.TransportErrors.general.cacheEmpty(transport_1.RelationshipTemplate, template.id.toString()).logWith(this._log);
|
|
850
846
|
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
847
|
+
const body = template.cache.content;
|
|
848
|
+
const isTemplator = this.parent.accountController.identity.isMe(template.cache.createdBy);
|
|
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) {
|
|
854
857
|
const attributes = body.sharedAttributes;
|
|
855
858
|
if (attributes) {
|
|
856
|
-
const sharedAt = template.cache.createdAt;
|
|
857
|
-
const sharedBy = isTemplator
|
|
858
|
-
? this.parent.accountController.identity.address
|
|
859
|
-
: relationship.peer.address;
|
|
860
|
-
const sharedWith = isTemplator
|
|
861
|
-
? relationship.peer.address
|
|
862
|
-
: this.parent.accountController.identity.address;
|
|
863
|
-
const sharedItemsWithSameReference = await this.parent.sharedItems.getSharedItems({
|
|
864
|
-
reference: template.id.toString()
|
|
865
|
-
});
|
|
866
859
|
if (sharedItemsWithSameReference.length !== attributes.length) {
|
|
867
|
-
const missingItems = [];
|
|
868
860
|
attributes.forEach((attribute) => {
|
|
869
861
|
if (!sharedItemsWithSameReference.find(function (item) {
|
|
870
862
|
const content = item.content;
|
|
@@ -873,45 +865,60 @@ class RelationshipInfoUtil {
|
|
|
873
865
|
missingItems.push(attribute);
|
|
874
866
|
}
|
|
875
867
|
});
|
|
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
|
-
}
|
|
888
868
|
}
|
|
889
869
|
}
|
|
890
870
|
}
|
|
891
871
|
else {
|
|
892
|
-
//
|
|
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);
|
|
893
904
|
}
|
|
894
905
|
}
|
|
895
906
|
async parseCreationRequest(relationship) {
|
|
896
907
|
const change = relationship.cache.creationChange;
|
|
897
908
|
const request = change.request;
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
909
|
+
const body = request.content;
|
|
910
|
+
const isRequestor = this.parent.accountController.identity.isMe(request.createdBy);
|
|
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) {
|
|
901
919
|
const attributes = body.sharedAttributes;
|
|
902
920
|
if (attributes && attributes.length > 0) {
|
|
903
|
-
const sharedAt = request.createdAt;
|
|
904
|
-
const sharedBy = isRequestor
|
|
905
|
-
? this.parent.accountController.identity.address
|
|
906
|
-
: relationship.peer.address;
|
|
907
|
-
const sharedWith = isRequestor
|
|
908
|
-
? relationship.peer.address
|
|
909
|
-
: this.parent.accountController.identity.address;
|
|
910
|
-
const sharedItemsWithSameReference = await this.parent.sharedItems.getSharedItems({
|
|
911
|
-
reference: change.id.toString()
|
|
912
|
-
});
|
|
913
921
|
if (sharedItemsWithSameReference.length !== attributes.length) {
|
|
914
|
-
const missingItems = [];
|
|
915
922
|
attributes.forEach((attribute) => {
|
|
916
923
|
if (!sharedItemsWithSameReference.find(function (item) {
|
|
917
924
|
const content = item.content;
|
|
@@ -920,23 +927,44 @@ class RelationshipInfoUtil {
|
|
|
920
927
|
missingItems.push(attribute);
|
|
921
928
|
}
|
|
922
929
|
});
|
|
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
|
-
}
|
|
935
930
|
}
|
|
936
931
|
}
|
|
937
932
|
}
|
|
938
933
|
else {
|
|
939
|
-
//
|
|
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);
|
|
940
968
|
}
|
|
941
969
|
}
|
|
942
970
|
}
|