@nmshd/consumption 3.12.1 → 5.0.0-alpha.2
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/consumption/ConsumptionController.d.ts.map +1 -1
- package/dist/consumption/ConsumptionController.js +1 -1
- package/dist/consumption/ConsumptionController.js.map +1 -1
- package/dist/consumption/CoreErrors.d.ts +3 -0
- package/dist/consumption/CoreErrors.d.ts.map +1 -1
- package/dist/consumption/CoreErrors.js +9 -0
- package/dist/consumption/CoreErrors.js.map +1 -1
- package/dist/modules/attributes/AttributesController.d.ts.map +1 -1
- package/dist/modules/attributes/AttributesController.js +25 -1
- package/dist/modules/attributes/AttributesController.js.map +1 -1
- package/dist/modules/attributes/local/CreateSharedLocalAttributeCopyParams.d.ts +1 -1
- package/dist/modules/attributes/local/CreateSharedLocalAttributeCopyParams.d.ts.map +1 -1
- package/dist/modules/requests/incoming/IncomingRequestsController.d.ts +4 -1
- package/dist/modules/requests/incoming/IncomingRequestsController.d.ts.map +1 -1
- package/dist/modules/requests/incoming/IncomingRequestsController.js +8 -2
- package/dist/modules/requests/incoming/IncomingRequestsController.js.map +1 -1
- package/dist/modules/requests/incoming/complete/CompleteIncomingRequestParameters.d.ts +3 -3
- package/dist/modules/requests/incoming/complete/CompleteIncomingRequestParameters.d.ts.map +1 -1
- package/dist/modules/requests/incoming/complete/CompleteIncomingRequestParameters.js +1 -1
- package/dist/modules/requests/incoming/complete/CompleteIncomingRequestParameters.js.map +1 -1
- package/dist/modules/requests/itemProcessors/createAttribute/CreateAttributeRequestItemProcessor.d.ts.map +1 -1
- package/dist/modules/requests/itemProcessors/createAttribute/CreateAttributeRequestItemProcessor.js +14 -6
- package/dist/modules/requests/itemProcessors/createAttribute/CreateAttributeRequestItemProcessor.js.map +1 -1
- package/dist/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.d.ts +2 -2
- package/dist/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.d.ts.map +1 -1
- package/dist/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.js +74 -52
- package/dist/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.js.map +1 -1
- package/dist/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.d.ts +2 -1
- package/dist/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.d.ts.map +1 -1
- package/dist/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.js +105 -52
- package/dist/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.js.map +1 -1
- package/dist/modules/requests/itemProcessors/shareAttribute/ShareAttributeRequestItemProcessor.d.ts +1 -1
- package/dist/modules/requests/itemProcessors/shareAttribute/ShareAttributeRequestItemProcessor.d.ts.map +1 -1
- package/dist/modules/requests/itemProcessors/shareAttribute/ShareAttributeRequestItemProcessor.js +45 -12
- package/dist/modules/requests/itemProcessors/shareAttribute/ShareAttributeRequestItemProcessor.js.map +1 -1
- package/dist/modules/requests/itemProcessors/utility/validateAttributeMatchesWithQuery.d.ts +5 -0
- package/dist/modules/requests/itemProcessors/utility/validateAttributeMatchesWithQuery.d.ts.map +1 -0
- package/dist/modules/requests/itemProcessors/utility/validateAttributeMatchesWithQuery.js +124 -0
- package/dist/modules/requests/itemProcessors/utility/validateAttributeMatchesWithQuery.js.map +1 -0
- package/dist/modules/requests/itemProcessors/utility/validateQuery.d.ts.map +1 -1
- package/dist/modules/requests/itemProcessors/utility/validateQuery.js +0 -3
- package/dist/modules/requests/itemProcessors/utility/validateQuery.js.map +1 -1
- package/dist/modules/requests/local/LocalResponse.d.ts +2 -2
- package/dist/modules/requests/local/LocalResponse.d.ts.map +1 -1
- package/dist/modules/requests/local/LocalResponse.js.map +1 -1
- package/dist/modules/requests/outgoing/OutgoingRequestsController.d.ts +2 -2
- package/dist/modules/requests/outgoing/OutgoingRequestsController.d.ts.map +1 -1
- package/dist/modules/requests/outgoing/OutgoingRequestsController.js +15 -5
- package/dist/modules/requests/outgoing/OutgoingRequestsController.js.map +1 -1
- package/dist/modules/requests/outgoing/createAndCompleteFromRelationshipTemplateResponse/CreateAndCompleteOutgoingRequestFromRelationshipTemplateResponseParameters.d.ts +4 -3
- package/dist/modules/requests/outgoing/createAndCompleteFromRelationshipTemplateResponse/CreateAndCompleteOutgoingRequestFromRelationshipTemplateResponseParameters.d.ts.map +1 -1
- package/dist/modules/requests/outgoing/createAndCompleteFromRelationshipTemplateResponse/CreateAndCompleteOutgoingRequestFromRelationshipTemplateResponseParameters.js +7 -2
- package/dist/modules/requests/outgoing/createAndCompleteFromRelationshipTemplateResponse/CreateAndCompleteOutgoingRequestFromRelationshipTemplateResponseParameters.js.map +1 -1
- package/package.json +1 -1
package/dist/modules/requests/itemProcessors/createAttribute/CreateAttributeRequestItemProcessor.js
CHANGED
|
@@ -11,16 +11,24 @@ class CreateAttributeRequestItemProcessor extends GenericRequestItemProcessor_1.
|
|
|
11
11
|
const senderIsAttributeOwner = requestItem.attribute.owner.equals(this.currentIdentityAddress);
|
|
12
12
|
const ownerIsEmptyString = requestItem.attribute.owner.toString() === "";
|
|
13
13
|
if (requestItem.attribute instanceof content_1.IdentityAttribute) {
|
|
14
|
+
if (recipientIsAttributeOwner || ownerIsEmptyString) {
|
|
15
|
+
return ValidationResult_1.ValidationResult.success();
|
|
16
|
+
}
|
|
14
17
|
if (senderIsAttributeOwner) {
|
|
15
|
-
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidRequestItem("Cannot create own
|
|
18
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidRequestItem("Cannot create own IdentityAttributes with a CreateAttributeRequestItem. Use a ShareAttributeRequestItem instead."));
|
|
16
19
|
}
|
|
17
|
-
if (
|
|
18
|
-
return ValidationResult_1.ValidationResult.
|
|
19
|
-
|
|
20
|
+
if (typeof recipient !== "undefined") {
|
|
21
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidRequestItem("The owner of the provided IdentityAttribute for the `attribute` property can only be the Recipient's Address or an empty string. The latter will default to the Recipient's Address."));
|
|
22
|
+
}
|
|
23
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidRequestItem("The owner of the provided IdentityAttribute for the `attribute` property can only be an empty string. It will default to the Recipient's Address."));
|
|
20
24
|
}
|
|
21
|
-
if (recipientIsAttributeOwner || senderIsAttributeOwner || ownerIsEmptyString
|
|
25
|
+
if (recipientIsAttributeOwner || senderIsAttributeOwner || ownerIsEmptyString) {
|
|
22
26
|
return ValidationResult_1.ValidationResult.success();
|
|
23
|
-
|
|
27
|
+
}
|
|
28
|
+
if (typeof recipient !== "undefined") {
|
|
29
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidRequestItem("The owner of the provided RelationshipAttribute for the `attribute` property can only be the Sender's Address, the Recipient's Address or an empty string. The latter will default to the Recipient's Address."));
|
|
30
|
+
}
|
|
31
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidRequestItem("The owner of the provided RelationshipAttribute for the `attribute` property can only be the Sender's Address or an empty string. The latter will default to the Recipient's Address."));
|
|
24
32
|
}
|
|
25
33
|
async accept(requestItem, _params, requestInfo) {
|
|
26
34
|
if (requestItem.attribute.owner.toString() === "") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CreateAttributeRequestItemProcessor.js","sourceRoot":"","sources":["../../../../../src/modules/requests/itemProcessors/createAttribute/CreateAttributeRequestItemProcessor.ts"],"names":[],"mappings":";;;AAAA,4CAAmK;AAEnK,mEAAgE;AAEhE,uEAAoE;AAEpE,gFAA6E;AAG7E,MAAa,mCAAoC,SAAQ,yDAAuD;IAC5F,4BAA4B,CACxC,WAAuC,EACvC,QAAkB,EAClB,SAAuB;QAEvB,MAAM,yBAAyB,GAAG,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAChF,MAAM,sBAAsB,GAAG,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAC/F,MAAM,kBAAkB,GAAG,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC;QAEzE,IAAI,WAAW,CAAC,SAAS,YAAY,2BAAiB,EAAE,CAAC;YACrD,IAAI,sBAAsB,EAAE,CAAC;gBACzB,OAAO,mCAAgB,CAAC,KAAK,CACzB,uBAAU,CAAC,QAAQ,CAAC,kBAAkB,CAAC,
|
|
1
|
+
{"version":3,"file":"CreateAttributeRequestItemProcessor.js","sourceRoot":"","sources":["../../../../../src/modules/requests/itemProcessors/createAttribute/CreateAttributeRequestItemProcessor.ts"],"names":[],"mappings":";;;AAAA,4CAAmK;AAEnK,mEAAgE;AAEhE,uEAAoE;AAEpE,gFAA6E;AAG7E,MAAa,mCAAoC,SAAQ,yDAAuD;IAC5F,4BAA4B,CACxC,WAAuC,EACvC,QAAkB,EAClB,SAAuB;QAEvB,MAAM,yBAAyB,GAAG,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAChF,MAAM,sBAAsB,GAAG,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAC/F,MAAM,kBAAkB,GAAG,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC;QAEzE,IAAI,WAAW,CAAC,SAAS,YAAY,2BAAiB,EAAE,CAAC;YACrD,IAAI,yBAAyB,IAAI,kBAAkB,EAAE,CAAC;gBAClD,OAAO,mCAAgB,CAAC,OAAO,EAAE,CAAC;YACtC,CAAC;YAED,IAAI,sBAAsB,EAAE,CAAC;gBACzB,O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equestInfo } from "../IRequestItemProcessor";
|
|
|
7
7
|
import { AcceptProposeAttributeRequestItemParametersJSON } from "./AcceptProposeAttributeRequestItemParameters";
|
|
8
8
|
export declare class ProposeAttributeRequestItemProcessor extends GenericRequestItemProcessor<ProposeAttributeRequestItem, AcceptProposeAttributeRequestItemParametersJSON> {
|
|
9
9
|
canCreateOutgoingRequestItem(requestItem: ProposeAttributeRequestItem, _request: Request, recipient?: CoreAddress): ValidationResult;
|
|
10
|
-
private validateAttribute;
|
|
10
|
+
private static validateAttribute;
|
|
11
11
|
private validateQuery;
|
|
12
|
-
canAccept(
|
|
12
|
+
canAccept(requestItem: ProposeAttributeRequestItem, params: AcceptProposeAttributeRequestItemParametersJSON, requestInfo: LocalRequestInfo): Promise<ValidationResult>;
|
|
13
13
|
accept(_requestItem: ProposeAttributeRequestItem, params: AcceptProposeAttributeRequestItemParametersJSON, requestInfo: LocalRequestInfo): Promise<ProposeAttributeAcceptResponseItem | AttributeSuccessionAcceptResponseItem | AttributeAlreadySharedAcceptResponseItem>;
|
|
14
14
|
private performOwnSharedIdentityAttributeSuccession;
|
|
15
15
|
private createNewAttribute;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProposeAttributeRequestItemProcessor.d.ts","sourceRoot":"","sources":["../../../../../src/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,wCAAwC,EACxC,qCAAqC,
|
|
1
|
+
{"version":3,"file":"ProposeAttributeRequestItemProcessor.d.ts","sourceRoot":"","sources":["../../../../../src/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,wCAAwC,EACxC,qCAAqC,EAGrC,kCAAkC,EAClC,2BAA2B,EAC3B,kBAAkB,EAGlB,OAAO,EAEV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAA6C,MAAM,kBAAkB,CAAC;AAG1F,OAAO,EAAqD,iCAAiC,EAAE,MAAM,qBAAqB,CAAC;AAE3H,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAG5D,OAAO,EAA+C,+CAA+C,EAAE,MAAM,+CAA+C,CAAC;AAE7J,qBAAa,oCAAqC,SAAQ,2BAA2B,CAAC,2BAA2B,EAAE,+CAA+C,CAAC;IAC/I,4BAA4B,CAAC,WAAW,EAAE,2BAA2B,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,WAAW,GAAG,gBAAgB;IAwBpJ,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAYhC,OAAO,CAAC,aAAa;IAiBC,SAAS,CAC3B,WAAW,EAAE,2BAA2B,EACxC,MAAM,EAAE,+CAA+C,EACvD,WAAW,EAAE,gBAAgB,GAC9B,OAAO,CAAC,gBAAgB,CAAC;IA8EN,MAAM,CACxB,YAAY,EAAE,2BAA2B,EACzC,MAAM,EAAE,+CAA+C,EACvD,WAAW,EAAE,gBAAgB,GAC9B,OAAO,CAAC,kCAAkC,GAAG,qCAAqC,GAAG,wCAAwC,CAAC;YAyEnH,2CAA2C;YAa3C,kBAAkB;IAoBV,yBAAyB,CAC3C,YAAY,EAAE,kCAAkC,GAAG,qCAAqC,GAAG,wCAAwC,GAAG,kBAAkB,EACxJ,YAAY,EAAE,2BAA2B,EACzC,WAAW,EAAE,gBAAgB,GAC9B,OAAO,CAAC,iCAAiC,GAAG,IAAI,CAAC;CAwBvD"}
|
|
@@ -6,11 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ProposeAttributeRequestItemProcessor = void 0;
|
|
7
7
|
const content_1 = require("@nmshd/content");
|
|
8
8
|
const transport_1 = require("@nmshd/transport");
|
|
9
|
+
const ts_simple_nameof_1 = require("ts-simple-nameof");
|
|
9
10
|
const CoreErrors_1 = require("../../../../consumption/CoreErrors");
|
|
10
11
|
const attributes_1 = require("../../../attributes");
|
|
11
12
|
const LocalAttribute_1 = require("../../../attributes/local/LocalAttribute");
|
|
12
13
|
const ValidationResult_1 = require("../../../common/ValidationResult");
|
|
13
14
|
const GenericRequestItemProcessor_1 = require("../GenericRequestItemProcessor");
|
|
15
|
+
const validateAttributeMatchesWithQuery_1 = __importDefault(require("../utility/validateAttributeMatchesWithQuery"));
|
|
14
16
|
const validateQuery_1 = __importDefault(require("../utility/validateQuery"));
|
|
15
17
|
const AcceptProposeAttributeRequestItemParameters_1 = require("./AcceptProposeAttributeRequestItemParameters");
|
|
16
18
|
class ProposeAttributeRequestItemProcessor extends GenericRequestItemProcessor_1.GenericRequestItemProcessor {
|
|
@@ -19,15 +21,19 @@ class ProposeAttributeRequestItemProcessor extends GenericRequestItemProcessor_1
|
|
|
19
21
|
if (queryValidationResult.isError()) {
|
|
20
22
|
return queryValidationResult;
|
|
21
23
|
}
|
|
22
|
-
const attributeValidationResult =
|
|
24
|
+
const attributeValidationResult = ProposeAttributeRequestItemProcessor.validateAttribute(requestItem.attribute);
|
|
23
25
|
if (attributeValidationResult.isError()) {
|
|
24
26
|
return attributeValidationResult;
|
|
25
27
|
}
|
|
28
|
+
const proposedAttributeMatchesWithQueryValidationResult = (0, validateAttributeMatchesWithQuery_1.default)(requestItem.query, requestItem.attribute, transport_1.CoreAddress.from(""), this.currentIdentityAddress);
|
|
29
|
+
if (proposedAttributeMatchesWithQueryValidationResult.isError()) {
|
|
30
|
+
return proposedAttributeMatchesWithQueryValidationResult;
|
|
31
|
+
}
|
|
26
32
|
return ValidationResult_1.ValidationResult.success();
|
|
27
33
|
}
|
|
28
|
-
validateAttribute(attribute) {
|
|
34
|
+
static validateAttribute(attribute) {
|
|
29
35
|
if (attribute.owner.toString() !== "") {
|
|
30
|
-
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidRequestItem("The owner of the given `attribute` can only be an empty string. This is because you can only propose Attributes where the
|
|
36
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidRequestItem("The owner of the given `attribute` can only be an empty string. This is because you can only propose Attributes where the Recipient of the Request is the owner anyway. And in order to avoid mistakes, the owner will be automatically filled for you."));
|
|
31
37
|
}
|
|
32
38
|
return ValidationResult_1.ValidationResult.success();
|
|
33
39
|
}
|
|
@@ -37,36 +43,54 @@ class ProposeAttributeRequestItemProcessor extends GenericRequestItemProcessor_1
|
|
|
37
43
|
return commonQueryValidationResult;
|
|
38
44
|
}
|
|
39
45
|
if (requestItem.query instanceof content_1.RelationshipAttributeQuery && requestItem.query.owner.toString() !== "") {
|
|
40
|
-
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidRequestItem("The owner of the given `query` can only be an empty string. This is because you can only propose Attributes where the
|
|
46
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidRequestItem("The owner of the given `query` can only be an empty string. This is because you can only propose Attributes where the Recipient of the Request is the owner anyway. And in order to avoid mistakes, the owner will be automatically filled for you."));
|
|
41
47
|
}
|
|
42
48
|
return ValidationResult_1.ValidationResult.success();
|
|
43
49
|
}
|
|
44
|
-
async canAccept(
|
|
50
|
+
async canAccept(requestItem, params, requestInfo) {
|
|
45
51
|
const parsedParams = AcceptProposeAttributeRequestItemParameters_1.AcceptProposeAttributeRequestItemParameters.from(params);
|
|
46
|
-
let attribute
|
|
52
|
+
let attribute;
|
|
47
53
|
if (parsedParams.isWithExistingAttribute()) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
if (requestItem.query instanceof content_1.RelationshipAttributeQuery) {
|
|
55
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidAcceptParameters("When responding to a RelationshipAttributeQuery, only new RelationshipAttributes may be provided."));
|
|
56
|
+
}
|
|
57
|
+
const foundLocalAttribute = await this.consumptionController.attributes.getLocalAttribute(parsedParams.attributeId);
|
|
58
|
+
if (!foundLocalAttribute) {
|
|
59
|
+
return ValidationResult_1.ValidationResult.error(transport_1.CoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, requestInfo.id.toString()));
|
|
60
|
+
}
|
|
61
|
+
attribute = foundLocalAttribute.content;
|
|
62
|
+
if (requestItem.query instanceof content_1.IdentityAttributeQuery && attribute instanceof content_1.IdentityAttribute && this.accountController.identity.isMe(attribute.owner)) {
|
|
63
|
+
if (foundLocalAttribute.isShared()) {
|
|
64
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.attributeQueryMismatch("The provided IdentityAttribute is a shared copy of a RepositoryAttribute. You can only share RepositoryAttributes."));
|
|
55
65
|
}
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (
|
|
60
|
-
|
|
66
|
+
const ownSharedIdentityAttributeSuccessors = await this.consumptionController.attributes.getSharedSuccessorsOfAttribute(foundLocalAttribute, {
|
|
67
|
+
"shareInfo.peer": requestInfo.peer.toString()
|
|
68
|
+
});
|
|
69
|
+
if (ownSharedIdentityAttributeSuccessors.length > 0) {
|
|
70
|
+
if (!ownSharedIdentityAttributeSuccessors[0].shareInfo?.sourceAttribute) {
|
|
71
|
+
throw new Error(`The LocalAttribute ${ownSharedIdentityAttributeSuccessors[0].id} does not have a 'shareInfo.sourceAttribute', even though it was found as a shared version of a LocalAttribute.`);
|
|
72
|
+
}
|
|
73
|
+
const successorRepositorySourceAttribute = await this.consumptionController.attributes.getLocalAttribute(ownSharedIdentityAttributeSuccessors[0].shareInfo.sourceAttribute);
|
|
74
|
+
if (!successorRepositorySourceAttribute) {
|
|
75
|
+
throw new Error(`The RepositoryAttribute ${ownSharedIdentityAttributeSuccessors[0].shareInfo.sourceAttribute} was not found.`);
|
|
76
|
+
}
|
|
77
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.attributeQueryMismatch(`The provided IdentityAttribute is outdated. You have already shared the successor '${ownSharedIdentityAttributeSuccessors[0].shareInfo.sourceAttribute}' of it.`));
|
|
61
78
|
}
|
|
62
79
|
}
|
|
63
|
-
attribute = foundAttribute.content;
|
|
64
80
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
81
|
+
else if (parsedParams.isWithNewAttribute()) {
|
|
82
|
+
attribute = parsedParams.attribute;
|
|
83
|
+
const ownerIsEmpty = attribute.owner.equals("");
|
|
84
|
+
if (ownerIsEmpty) {
|
|
85
|
+
attribute.owner = this.currentIdentityAddress;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (typeof attribute === "undefined") {
|
|
89
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidAcceptParameters(`You have to specify either ${(0, ts_simple_nameof_1.nameof)((x) => x.attribute)} or ${(0, ts_simple_nameof_1.nameof)((x) => x.attributeId)}.`));
|
|
69
90
|
}
|
|
91
|
+
const answerToQueryValidationResult = (0, validateAttributeMatchesWithQuery_1.default)(requestItem.query, attribute, this.currentIdentityAddress, requestInfo.peer);
|
|
92
|
+
if (answerToQueryValidationResult.isError())
|
|
93
|
+
return answerToQueryValidationResult;
|
|
70
94
|
return ValidationResult_1.ValidationResult.success();
|
|
71
95
|
}
|
|
72
96
|
async accept(_requestItem, params, requestInfo) {
|
|
@@ -77,12 +101,7 @@ class ProposeAttributeRequestItemProcessor extends GenericRequestItemProcessor_1
|
|
|
77
101
|
if (!existingSourceAttribute)
|
|
78
102
|
throw transport_1.CoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, parsedParams.attributeId.toString());
|
|
79
103
|
const latestSharedVersion = await this.consumptionController.attributes.getSharedVersionsOfAttribute(parsedParams.attributeId, [requestInfo.peer], true);
|
|
80
|
-
|
|
81
|
-
const wasDeletedByPeerOrOwner = latestSharedVersion[0]?.deletionInfo?.deletionStatus === attributes_1.DeletionStatus.DeletedByPeer ||
|
|
82
|
-
latestSharedVersion[0]?.deletionInfo?.deletionStatus === attributes_1.DeletionStatus.DeletedByOwner;
|
|
83
|
-
const isLatestSharedVersion = latestSharedVersion[0]?.shareInfo?.sourceAttribute?.toString() === existingSourceAttribute.id.toString();
|
|
84
|
-
const predecessorWasSharedBefore = wasSharedBefore && !isLatestSharedVersion;
|
|
85
|
-
if (!wasSharedBefore || wasDeletedByPeerOrOwner) {
|
|
104
|
+
if (latestSharedVersion.length === 0) {
|
|
86
105
|
sharedLocalAttribute = await this.consumptionController.attributes.createSharedLocalAttributeCopy({
|
|
87
106
|
sourceAttributeId: transport_1.CoreId.from(existingSourceAttribute.id),
|
|
88
107
|
peer: transport_1.CoreAddress.from(requestInfo.peer),
|
|
@@ -94,37 +113,40 @@ class ProposeAttributeRequestItemProcessor extends GenericRequestItemProcessor_1
|
|
|
94
113
|
attribute: sharedLocalAttribute.content
|
|
95
114
|
});
|
|
96
115
|
}
|
|
97
|
-
|
|
116
|
+
const latestSharedAttribute = latestSharedVersion[0];
|
|
117
|
+
if (!latestSharedAttribute.shareInfo?.sourceAttribute) {
|
|
118
|
+
throw new Error(`The Attribute ${latestSharedAttribute.id} doesn't have a 'shareInfo.sourceAttribute', even though it was found as shared version of an Attribute.`);
|
|
119
|
+
}
|
|
120
|
+
if (latestSharedAttribute.shareInfo.sourceAttribute.toString() === existingSourceAttribute.id.toString()) {
|
|
98
121
|
return content_1.AttributeAlreadySharedAcceptResponseItem.from({
|
|
99
122
|
result: content_1.ResponseItemResult.Accepted,
|
|
100
|
-
attributeId:
|
|
123
|
+
attributeId: latestSharedAttribute.id
|
|
101
124
|
});
|
|
102
125
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
result: content_1.ResponseItemResult.Accepted,
|
|
116
|
-
successorId: successorSharedAttribute.id,
|
|
117
|
-
successorContent: successorSharedAttribute.content,
|
|
118
|
-
predecessorId: sharedPredecessor.id
|
|
119
|
-
});
|
|
120
|
-
}
|
|
126
|
+
const predecessorSourceAttribute = await this.consumptionController.attributes.getLocalAttribute(latestSharedAttribute.shareInfo.sourceAttribute);
|
|
127
|
+
if (!predecessorSourceAttribute)
|
|
128
|
+
throw transport_1.CoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, latestSharedAttribute.shareInfo.sourceAttribute.toString());
|
|
129
|
+
if (await this.consumptionController.attributes.isSubsequentInSuccession(predecessorSourceAttribute, existingSourceAttribute)) {
|
|
130
|
+
if (existingSourceAttribute.isRepositoryAttribute(this.currentIdentityAddress)) {
|
|
131
|
+
const successorSharedAttribute = await this.performOwnSharedIdentityAttributeSuccession(latestSharedAttribute.id, existingSourceAttribute, requestInfo);
|
|
132
|
+
return content_1.AttributeSuccessionAcceptResponseItem.from({
|
|
133
|
+
result: content_1.ResponseItemResult.Accepted,
|
|
134
|
+
successorId: successorSharedAttribute.id,
|
|
135
|
+
successorContent: successorSharedAttribute.content,
|
|
136
|
+
predecessorId: latestSharedAttribute.id
|
|
137
|
+
});
|
|
121
138
|
}
|
|
122
139
|
}
|
|
123
140
|
}
|
|
124
|
-
if (
|
|
125
|
-
|
|
141
|
+
else if (parsedParams.isWithNewAttribute()) {
|
|
142
|
+
if (parsedParams.attribute.owner.equals("")) {
|
|
143
|
+
parsedParams.attribute.owner = this.currentIdentityAddress;
|
|
144
|
+
}
|
|
145
|
+
sharedLocalAttribute = await this.createNewAttribute(parsedParams.attribute, requestInfo);
|
|
146
|
+
}
|
|
147
|
+
if (!sharedLocalAttribute) {
|
|
148
|
+
throw new Error(`You have to specify either ${(0, ts_simple_nameof_1.nameof)((x) => x.attribute)} or ${(0, ts_simple_nameof_1.nameof)((x) => x.attributeId)}.`);
|
|
126
149
|
}
|
|
127
|
-
sharedLocalAttribute = await this.createNewAttribute(parsedParams.attribute, requestInfo);
|
|
128
150
|
return content_1.ProposeAttributeAcceptResponseItem.from({
|
|
129
151
|
result: content_1.ResponseItemResult.Accepted,
|
|
130
152
|
attributeId: sharedLocalAttribute.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProposeAttributeRequestItemProcessor.js","sourceRoot":"","sources":["../../../../../src/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"ProposeAttributeRequestItemProcessor.js","sourceRoot":"","sources":["../../../../../src/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.ts"],"names":[],"mappings":";;;;;;AAAA,4CAYwB;AACxB,gDAA0F;AAC1F,uDAA0C;AAC1C,mEAAgE;AAChE,oDAA2H;AAC3H,6EAA0E;AAC1E,uEAAoE;AACpE,gFAA6E;AAE7E,qHAA6F;AAC7F,6EAAqD;AACrD,+GAA6J;AAE7J,MAAa,oCAAqC,SAAQ,yDAAyG;IAC/I,4BAA4B,CAAC,WAAwC,EAAE,QAAiB,EAAE,SAAuB;QAC7H,MAAM,qBAAqB,GAAG,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QACzE,IAAI,qBAAqB,CAAC,OAAO,EAAE,EAAE,CAAC;YAClC,OAAO,qBAAqB,CAAC;QACjC,CAAC;QAED,MAAM,yBAAyB,GAAG,oCAAoC,CAAC,iBAAiB,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAChH,IAAI,yBAAyB,CAAC,OAAO,EAAE,EAAE,CAAC;YACtC,OAAO,yBAAyB,CAAC;QACrC,CAAC;QAED,MAAM,iDAAiD,GAAG,IAAA,2CAAiC,EACvF,WAAW,CAAC,KAAK,EACjB,WAAW,CAAC,SAAS,EACrB,uBAAW,CAAC,IAAI,CAAC,EAAE,CAAC,EACpB,IAAI,CAAC,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,EAAE,YAAY,CAAC,WAAW;gBAC5B,OAAO,EAAE,YAAY,CAAC,SAAS;gBAC/B,IAAI,EAAE,WAAW,CAAC,IAAI;gBACtB,gBAAgB,EAAE,WAAW,CAAC,EAAE;aACnC,CAAC,CAAC;QACP,CAAC;QAED,IAAI,YAAY,YAAY,+CAAqC,IAAI,YAAY,CAAC,gBAAgB,YAAY,2BAAiB,EAAE,CAAC;YAC9H,MAAM,eAAe,GAAG,qCAAwB,CAAC,IAAI,CAAC;gBAClD,EAAE,EAAE,YAAY,CAAC,WAAW;gBAC5B,OAAO,EAAE,YAAY,CAAC,gBAAgB;gBACtC,SAAS,EAAE,oCAAuB,CAAC,IAAI,CAAC;oBACpC,IAAI,EAAE,WAAW,CAAC,IAAI;oBACtB,gBAAgB,EAAE,WAAW,CAAC,EAAE;iBACnC,CAAC;aACL,CAAC,CAAC;YACH,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC,kCAAkC,CAAC,YAAY,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;YAC/J,OAAO,IAAI,8CAAiC,CAAC,IAAI,CAAC,sBAAsB,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;QACjH,CAAC;QACD,OAAO;IACX,CAAC;CACJ;AAlRD,oFAkRC"}
|
package/dist/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ import { LocalRequestInfo } from "../IRequestItemProcessor";
|
|
|
7
7
|
import { AcceptReadAttributeRequestItemParametersJSON } from "./AcceptReadAttributeRequestItemParameters";
|
|
8
8
|
export declare class ReadAttributeRequestItemProcessor extends GenericRequestItemProcessor<ReadAttributeRequestItem, AcceptReadAttributeRequestItemParametersJSON> {
|
|
9
9
|
canCreateOutgoingRequestItem(requestItem: ReadAttributeRequestItem, _request: Request, recipient?: CoreAddress): ValidationResult;
|
|
10
|
-
|
|
10
|
+
private validateQuery;
|
|
11
|
+
canAccept(requestItem: ReadAttributeRequestItem, params: AcceptReadAttributeRequestItemParametersJSON, requestInfo: LocalRequestInfo): Promise<ValidationResult>;
|
|
11
12
|
accept(_requestItem: ReadAttributeRequestItem, params: AcceptReadAttributeRequestItemParametersJSON, requestInfo: LocalRequestInfo): Promise<ReadAttributeAcceptResponseItem | AttributeSuccessionAcceptResponseItem | AttributeAlreadySharedAcceptResponseItem>;
|
|
12
13
|
private performOwnSharedIdentityAttributeSuccession;
|
|
13
14
|
private performOwnSharedThirdPartyRelationshipAttributeSuccession;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReadAttributeRequestItemProcessor.d.ts","sourceRoot":"","sources":["../../../../../src/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,wCAAwC,EACxC,qCAAqC,
|
|
1
|
+
{"version":3,"file":"ReadAttributeRequestItemProcessor.d.ts","sourceRoot":"","sources":["../../../../../src/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,wCAAwC,EACxC,qCAAqC,EAGrC,+BAA+B,EAC/B,wBAAwB,EACxB,kBAAkB,EAIlB,OAAO,EAGV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAA6C,MAAM,kBAAkB,CAAC;AAG1F,OAAO,EAAqD,iCAAiC,EAAE,MAAM,qBAAqB,CAAC;AAE3H,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAG5D,OAAO,EAA4C,4CAA4C,EAAE,MAAM,4CAA4C,CAAC;AAEpJ,qBAAa,iCAAkC,SAAQ,2BAA2B,CAAC,wBAAwB,EAAE,4CAA4C,CAAC;IACtI,4BAA4B,CAAC,WAAW,EAAE,wBAAwB,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,WAAW,GAAG,gBAAgB;IASjJ,OAAO,CAAC,aAAa;IAiBC,SAAS,CAC3B,WAAW,EAAE,wBAAwB,EACrC,MAAM,EAAE,4CAA4C,EACpD,WAAW,EAAE,gBAAgB,GAC9B,OAAO,CAAC,gBAAgB,CAAC;IA8HN,MAAM,CACxB,YAAY,EAAE,wBAAwB,EACtC,MAAM,EAAE,4CAA4C,EACpD,WAAW,EAAE,gBAAgB,GAC9B,OAAO,CAAC,+BAA+B,GAAG,qCAAqC,GAAG,wCAAwC,CAAC;YAiFhH,2CAA2C;YAa3C,yDAAyD;YAazD,qDAAqD;YAarD,kBAAkB;IAoBV,yBAAyB,CAC3C,YAAY,EAAE,+BAA+B,GAAG,qCAAqC,GAAG,wCAAwC,GAAG,kBAAkB,EACrJ,YAAY,EAAE,wBAAwB,EACtC,WAAW,EAAE,gBAAgB,GAC9B,OAAO,CAAC,iCAAiC,GAAG,IAAI,CAAC;CAgCvD"}
|
package/dist/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.js
CHANGED
|
@@ -6,44 +6,99 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ReadAttributeRequestItemProcessor = void 0;
|
|
7
7
|
const content_1 = require("@nmshd/content");
|
|
8
8
|
const transport_1 = require("@nmshd/transport");
|
|
9
|
+
const ts_simple_nameof_1 = require("ts-simple-nameof");
|
|
9
10
|
const CoreErrors_1 = require("../../../../consumption/CoreErrors");
|
|
10
11
|
const attributes_1 = require("../../../attributes");
|
|
11
12
|
const LocalAttribute_1 = require("../../../attributes/local/LocalAttribute");
|
|
12
13
|
const ValidationResult_1 = require("../../../common/ValidationResult");
|
|
13
14
|
const GenericRequestItemProcessor_1 = require("../GenericRequestItemProcessor");
|
|
15
|
+
const validateAttributeMatchesWithQuery_1 = __importDefault(require("../utility/validateAttributeMatchesWithQuery"));
|
|
14
16
|
const validateQuery_1 = __importDefault(require("../utility/validateQuery"));
|
|
15
17
|
const AcceptReadAttributeRequestItemParameters_1 = require("./AcceptReadAttributeRequestItemParameters");
|
|
16
18
|
class ReadAttributeRequestItemProcessor extends GenericRequestItemProcessor_1.GenericRequestItemProcessor {
|
|
17
19
|
canCreateOutgoingRequestItem(requestItem, _request, recipient) {
|
|
18
|
-
const queryValidationResult =
|
|
20
|
+
const queryValidationResult = this.validateQuery(requestItem, recipient);
|
|
19
21
|
if (queryValidationResult.isError()) {
|
|
20
22
|
return queryValidationResult;
|
|
21
23
|
}
|
|
22
24
|
return ValidationResult_1.ValidationResult.success();
|
|
23
25
|
}
|
|
24
|
-
|
|
26
|
+
validateQuery(requestItem, recipient) {
|
|
27
|
+
const commonQueryValidationResult = (0, validateQuery_1.default)(requestItem.query, this.currentIdentityAddress, recipient);
|
|
28
|
+
if (commonQueryValidationResult.isError()) {
|
|
29
|
+
return commonQueryValidationResult;
|
|
30
|
+
}
|
|
31
|
+
if (requestItem.query instanceof content_1.RelationshipAttributeQuery && !["", this.currentIdentityAddress.toString()].includes(requestItem.query.owner.toString())) {
|
|
32
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidRequestItem("The owner of the given `query` can only be an empty string or yourself. This is because you can only request RelationshipAttributes using a ReadAttributeRequestitem with a RelationshipAttributeQuery where the Recipient of the Request or yourself is the owner. And in order to avoid mistakes, the Recipient automatically will become the owner of the RelationshipAttribute later on if the owner of the `query` is an empty string."));
|
|
33
|
+
}
|
|
34
|
+
return ValidationResult_1.ValidationResult.success();
|
|
35
|
+
}
|
|
36
|
+
async canAccept(requestItem, params, requestInfo) {
|
|
25
37
|
const parsedParams = AcceptReadAttributeRequestItemParameters_1.AcceptReadAttributeRequestItemParameters.from(params);
|
|
38
|
+
let attribute;
|
|
26
39
|
if (parsedParams.isWithExistingAttribute()) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return ValidationResult_1.ValidationResult.error(transport_1.CoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, parsedParams.existingAttributeId.toString()));
|
|
30
|
-
const ownerIsCurrentIdentity = this.accountController.identity.isMe(foundAttribute.content.owner);
|
|
31
|
-
if (!ownerIsCurrentIdentity && foundAttribute.content instanceof content_1.IdentityAttribute) {
|
|
32
|
-
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidAcceptParameters("The given Attribute belongs to someone else. You can only share own Attributes."));
|
|
40
|
+
if (requestItem.query instanceof content_1.RelationshipAttributeQuery) {
|
|
41
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidAcceptParameters("When responding to a RelationshipAttributeQuery, only new RelationshipAttributes may be provided."));
|
|
33
42
|
}
|
|
34
|
-
const
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
const foundLocalAttribute = await this.consumptionController.attributes.getLocalAttribute(parsedParams.existingAttributeId);
|
|
44
|
+
if (!foundLocalAttribute) {
|
|
45
|
+
return ValidationResult_1.ValidationResult.error(transport_1.CoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, requestInfo.id.toString()));
|
|
46
|
+
}
|
|
47
|
+
attribute = foundLocalAttribute.content;
|
|
48
|
+
if (requestItem.query instanceof content_1.IdentityAttributeQuery && attribute instanceof content_1.IdentityAttribute && this.accountController.identity.isMe(attribute.owner)) {
|
|
49
|
+
if (foundLocalAttribute.isShared()) {
|
|
50
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.attributeQueryMismatch("The provided IdentityAttribute is a shared copy of a RepositoryAttribute. You can only share RepositoryAttributes."));
|
|
51
|
+
}
|
|
52
|
+
const ownSharedIdentityAttributeSuccessors = await this.consumptionController.attributes.getSharedSuccessorsOfAttribute(foundLocalAttribute, {
|
|
53
|
+
"shareInfo.peer": requestInfo.peer.toString()
|
|
54
|
+
});
|
|
55
|
+
if (ownSharedIdentityAttributeSuccessors.length > 0) {
|
|
56
|
+
if (!ownSharedIdentityAttributeSuccessors[0].shareInfo?.sourceAttribute) {
|
|
57
|
+
throw new Error(`The LocalAttribute ${ownSharedIdentityAttributeSuccessors[0].id} does not have a 'shareInfo.sourceAttribute', even though it was found as a shared version of a LocalAttribute.`);
|
|
58
|
+
}
|
|
59
|
+
const successorSourceRepositoryAttribute = await this.consumptionController.attributes.getLocalAttribute(ownSharedIdentityAttributeSuccessors[0].shareInfo.sourceAttribute);
|
|
60
|
+
if (!successorSourceRepositoryAttribute) {
|
|
61
|
+
throw new Error(`The RepositoryAttribute ${ownSharedIdentityAttributeSuccessors[0].shareInfo.sourceAttribute} was not found.`);
|
|
62
|
+
}
|
|
63
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.attributeQueryMismatch(`The provided IdentityAttribute is outdated. You have already shared the successor '${ownSharedIdentityAttributeSuccessors[0].shareInfo.sourceAttribute}' of it.`));
|
|
38
64
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
65
|
+
}
|
|
66
|
+
if (requestItem.query instanceof content_1.ThirdPartyRelationshipAttributeQuery && attribute instanceof content_1.RelationshipAttribute) {
|
|
67
|
+
if (!foundLocalAttribute.isShared()) {
|
|
68
|
+
throw new Error("The LocalAttribute found is faulty because its shareInfo is undefined, although its content is given by a RelationshipAttribute. Since RelationshipAttributes only make sense in the context of Relationships, they must always be shared.");
|
|
69
|
+
}
|
|
70
|
+
if (typeof foundLocalAttribute.shareInfo.sourceAttribute !== "undefined") {
|
|
71
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.attributeQueryMismatch("When responding to a ThirdPartyRelationshipAttributeQuery, only RelationshipAttributes that are not a copy of a sourceAttribute may be provided."));
|
|
72
|
+
}
|
|
73
|
+
const queriedThirdParties = requestItem.query.thirdParty.map((aThirdParty) => aThirdParty.toString());
|
|
74
|
+
if ((this.accountController.identity.isMe(attribute.owner) || queriedThirdParties.includes(attribute.owner.toString())) &&
|
|
75
|
+
!queriedThirdParties.includes("") &&
|
|
76
|
+
!queriedThirdParties.includes(foundLocalAttribute.shareInfo.peer.toString())) {
|
|
77
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.attributeQueryMismatch("The provided RelationshipAttribute exists in the context of a Relationship with a third party that should not be involved."));
|
|
44
78
|
}
|
|
45
79
|
}
|
|
46
80
|
}
|
|
81
|
+
else if (parsedParams.isWithNewAttribute()) {
|
|
82
|
+
if (requestItem.query instanceof content_1.ThirdPartyRelationshipAttributeQuery) {
|
|
83
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidAcceptParameters("When responding to a ThirdPartyRelationshipAttributeQuery, only RelationshipAttributes that already exist may be provided."));
|
|
84
|
+
}
|
|
85
|
+
attribute = parsedParams.newAttribute;
|
|
86
|
+
const ownerIsEmpty = attribute.owner.equals("");
|
|
87
|
+
if (ownerIsEmpty) {
|
|
88
|
+
attribute.owner = this.currentIdentityAddress;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (typeof attribute === "undefined") {
|
|
92
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.invalidAcceptParameters(`You have to specify either ${(0, ts_simple_nameof_1.nameof)((x) => x.newAttribute)} or ${(0, ts_simple_nameof_1.nameof)((x) => x.existingAttributeId)}.`));
|
|
93
|
+
}
|
|
94
|
+
const answerToQueryValidationResult = (0, validateAttributeMatchesWithQuery_1.default)(requestItem.query, attribute, this.currentIdentityAddress, requestInfo.peer);
|
|
95
|
+
if (answerToQueryValidationResult.isError())
|
|
96
|
+
return answerToQueryValidationResult;
|
|
97
|
+
if (requestItem.query instanceof content_1.ThirdPartyRelationshipAttributeQuery &&
|
|
98
|
+
attribute instanceof content_1.RelationshipAttribute &&
|
|
99
|
+
attribute.confidentiality === content_1.RelationshipAttributeConfidentiality.Private) {
|
|
100
|
+
return ValidationResult_1.ValidationResult.error(CoreErrors_1.CoreErrors.requests.attributeQueryMismatch("The confidentiality of the provided RelationshipAttribute is private. Therefore you are not allowed to share it."));
|
|
101
|
+
}
|
|
47
102
|
return ValidationResult_1.ValidationResult.success();
|
|
48
103
|
}
|
|
49
104
|
async accept(_requestItem, params, requestInfo) {
|
|
@@ -55,12 +110,7 @@ class ReadAttributeRequestItemProcessor extends GenericRequestItemProcessor_1.Ge
|
|
|
55
110
|
throw transport_1.CoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, parsedParams.existingAttributeId.toString());
|
|
56
111
|
}
|
|
57
112
|
const latestSharedVersion = await this.consumptionController.attributes.getSharedVersionsOfAttribute(parsedParams.existingAttributeId, [requestInfo.peer], true);
|
|
58
|
-
|
|
59
|
-
const wasDeletedByPeerOrOwner = latestSharedVersion[0]?.deletionInfo?.deletionStatus === attributes_1.DeletionStatus.DeletedByPeer ||
|
|
60
|
-
latestSharedVersion[0]?.deletionInfo?.deletionStatus === attributes_1.DeletionStatus.DeletedByOwner;
|
|
61
|
-
const isLatestSharedVersion = latestSharedVersion[0]?.shareInfo?.sourceAttribute?.toString() === existingSourceAttribute.id.toString();
|
|
62
|
-
const predecessorWasSharedBefore = wasSharedBefore && !isLatestSharedVersion;
|
|
63
|
-
if (!wasSharedBefore || wasDeletedByPeerOrOwner) {
|
|
113
|
+
if (latestSharedVersion.length === 0) {
|
|
64
114
|
sharedLocalAttribute = await this.consumptionController.attributes.createSharedLocalAttributeCopy({
|
|
65
115
|
sourceAttributeId: transport_1.CoreId.from(existingSourceAttribute.id),
|
|
66
116
|
peer: transport_1.CoreAddress.from(requestInfo.peer),
|
|
@@ -72,44 +122,47 @@ class ReadAttributeRequestItemProcessor extends GenericRequestItemProcessor_1.Ge
|
|
|
72
122
|
attribute: sharedLocalAttribute.content
|
|
73
123
|
});
|
|
74
124
|
}
|
|
75
|
-
|
|
125
|
+
const latestSharedAttribute = latestSharedVersion[0];
|
|
126
|
+
if (!latestSharedAttribute.shareInfo?.sourceAttribute) {
|
|
127
|
+
throw new Error(`The Attribute ${latestSharedAttribute.id} doesn't have a 'shareInfo.sourceAttribute', even though it was found as shared version of an Attribute.`);
|
|
128
|
+
}
|
|
129
|
+
if (latestSharedAttribute.shareInfo.sourceAttribute.toString() === existingSourceAttribute.id.toString()) {
|
|
76
130
|
return content_1.AttributeAlreadySharedAcceptResponseItem.from({
|
|
77
131
|
result: content_1.ResponseItemResult.Accepted,
|
|
78
|
-
attributeId:
|
|
132
|
+
attributeId: latestSharedAttribute.id
|
|
79
133
|
});
|
|
80
134
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
135
|
+
const predecessorSourceAttribute = await this.consumptionController.attributes.getLocalAttribute(latestSharedAttribute.shareInfo.sourceAttribute);
|
|
136
|
+
if (!predecessorSourceAttribute)
|
|
137
|
+
throw transport_1.CoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, latestSharedAttribute.shareInfo.sourceAttribute.toString());
|
|
138
|
+
if (await this.consumptionController.attributes.isSubsequentInSuccession(predecessorSourceAttribute, existingSourceAttribute)) {
|
|
139
|
+
let successorSharedAttribute;
|
|
140
|
+
if (existingSourceAttribute.isRepositoryAttribute(this.currentIdentityAddress)) {
|
|
141
|
+
successorSharedAttribute = await this.performOwnSharedIdentityAttributeSuccession(latestSharedAttribute.id, existingSourceAttribute, requestInfo);
|
|
85
142
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (existingSourceAttribute.isRepositoryAttribute(this.currentIdentityAddress)) {
|
|
92
|
-
successorSharedAttribute = await this.performOwnSharedIdentityAttributeSuccession(sharedPredecessor.id, existingSourceAttribute, requestInfo);
|
|
93
|
-
}
|
|
94
|
-
else if (existingSourceAttribute.isOwnedBy(this.accountController.identity.address)) {
|
|
95
|
-
successorSharedAttribute = await this.performOwnSharedThirdPartyRelationshipAttributeSuccession(sharedPredecessor.id, existingSourceAttribute, requestInfo);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
successorSharedAttribute = await this.performThirdPartyOwnedRelationshipAttributeSuccession(sharedPredecessor.id, existingSourceAttribute, requestInfo);
|
|
99
|
-
}
|
|
100
|
-
return content_1.AttributeSuccessionAcceptResponseItem.from({
|
|
101
|
-
result: content_1.ResponseItemResult.Accepted,
|
|
102
|
-
successorId: successorSharedAttribute.id,
|
|
103
|
-
successorContent: successorSharedAttribute.content,
|
|
104
|
-
predecessorId: sharedPredecessor.id
|
|
105
|
-
});
|
|
143
|
+
else if (existingSourceAttribute.isOwnedBy(this.accountController.identity.address)) {
|
|
144
|
+
successorSharedAttribute = await this.performOwnSharedThirdPartyRelationshipAttributeSuccession(latestSharedAttribute.id, existingSourceAttribute, requestInfo);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
successorSharedAttribute = await this.performThirdPartyOwnedRelationshipAttributeSuccession(latestSharedAttribute.id, existingSourceAttribute, requestInfo);
|
|
106
148
|
}
|
|
149
|
+
return content_1.AttributeSuccessionAcceptResponseItem.from({
|
|
150
|
+
result: content_1.ResponseItemResult.Accepted,
|
|
151
|
+
successorId: successorSharedAttribute.id,
|
|
152
|
+
successorContent: successorSharedAttribute.content,
|
|
153
|
+
predecessorId: latestSharedAttribute.id
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else if (parsedParams.isWithNewAttribute()) {
|
|
158
|
+
if (parsedParams.newAttribute.owner.equals("")) {
|
|
159
|
+
parsedParams.newAttribute.owner = this.currentIdentityAddress;
|
|
107
160
|
}
|
|
161
|
+
sharedLocalAttribute = await this.createNewAttribute(parsedParams.newAttribute, requestInfo);
|
|
108
162
|
}
|
|
109
|
-
if (!
|
|
110
|
-
throw new Error(
|
|
163
|
+
if (!sharedLocalAttribute) {
|
|
164
|
+
throw new Error(`You have to specify either ${(0, ts_simple_nameof_1.nameof)((x) => x.newAttribute)} or ${(0, ts_simple_nameof_1.nameof)((x) => x.existingAttributeId)}.`);
|
|
111
165
|
}
|
|
112
|
-
sharedLocalAttribute = await this.createNewAttribute(parsedParams.newAttribute, requestInfo);
|
|
113
166
|
return content_1.ReadAttributeAcceptResponseItem.from({
|
|
114
167
|
result: content_1.ResponseItemResult.Accepted,
|
|
115
168
|
attributeId: sharedLocalAttribute.id,
|