Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ export class AttributesController extends ConsumptionBaseController {
throw ConsumptionCoreErrors.attributes.wrongRelationshipStatusToSetDeletionInfo();
}

const deletionDate = relationship.cache!.auditLog[relationship.cache!.auditLog.length - 1].createdAt;
const deletionDate = relationship.auditLog[relationship.auditLog.length - 1].createdAt;

await this.setDeletionInfoOfOwnSharedAttributes(relationship.peer.address.toString(), deletionDate);
await this.setDeletionInfoOfPeerSharedAttributes(relationship.peer.address.toString(), deletionDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class OutgoingRequestsController extends ConsumptionBaseController {
}

// checking for an active relationship is not secure as in the meantime the relationship could have been accepted
const isFromNewRelationship = parsedParams.responseSource instanceof Relationship && parsedParams.responseSource.cache!.auditLog.length === 1;
const isFromNewRelationship = parsedParams.responseSource instanceof Relationship && parsedParams.responseSource.auditLog.length === 1;

const requestContent = isFromNewRelationship ? templateContent.onNewRelationship : templateContent.onExistingRelationship;

Expand Down Expand Up @@ -305,7 +305,7 @@ export class OutgoingRequestsController extends ConsumptionBaseController {

this.assertRequestStatus(request, LocalRequestStatus.Open, LocalRequestStatus.Expired);

const responseSourceObjectCreationDate = responseSourceObject instanceof Message ? responseSourceObject.createdAt : responseSourceObject.cache!.auditLog[0].createdAt;
const responseSourceObjectCreationDate = responseSourceObject instanceof Message ? responseSourceObject.createdAt : responseSourceObject.auditLog[0].createdAt;
if (request.status === LocalRequestStatus.Expired && request.isExpired(responseSourceObjectCreationDate)) {
throw new ConsumptionError("Cannot complete an expired request with a response that was created before the expiration date");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe("End2End Request/Response via Relationship Template", function () {
template: rTemplate,
creationContent: RelationshipCreationContent.from({ response: rLocalRequest.response!.content })
});
rCreationContent = rRelationship.cache?.creationContent as RelationshipCreationContent;
rCreationContent = rRelationship.creationContent as RelationshipCreationContent;
});

test("recipient: complete Local Request", async function () {
Expand All @@ -111,7 +111,7 @@ describe("End2End Request/Response via Relationship Template", function () {
});

test("sender: create Local Request and Response from Relationship Change", async function () {
sCreationContent = sRelationship.cache!.creationContent as RelationshipCreationContent;
sCreationContent = sRelationship.creationContent as RelationshipCreationContent;
const response = sCreationContent.response;

sLocalRequest = await sConsumptionController.outgoingRequests.createAndCompleteFromRelationshipTemplateResponse({
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export class AcceptRelationshipUseCase extends UseCase<AcceptRelationshipRequest
return Result.fail(RuntimeErrors.general.recordNotFound(Relationship));
}

if (!relationship.cache) {
return Result.fail(RuntimeErrors.general.cacheEmpty(Relationship, relationship.id.toString()));
}

const updatedRelationship = await this.relationshipsController.accept(relationship.id);

await this.accountController.syncDatawallet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export class AcceptRelationshipReactivationUseCase extends UseCase<AcceptRelatio
return Result.fail(RuntimeErrors.general.recordNotFound(Relationship));
}

if (!relationship.cache) {
return Result.fail(RuntimeErrors.general.cacheEmpty(Relationship, relationship.id.toString()));
}

const updatedRelationship = await this.relationshipsController.acceptReactivation(relationship.id);

await this.accountController.syncDatawallet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export class DecomposeRelationshipUseCase extends UseCase<DecomposeRelationshipR
return Result.fail(RuntimeErrors.general.recordNotFound(Relationship));
}

if (!relationship.cache) {
return Result.fail(RuntimeErrors.general.cacheEmpty(Relationship, relationship.id.toString()));
}

// Backbone call first so nothing is deleted in case it goes wrong
await this.relationshipsController.decompose(relationship.id);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { QueryTranslator } from "@js-soft/docdb-querytranslator";
import { Result } from "@js-soft/ts-utils";
import { RelationshipDTO } from "@nmshd/runtime-types";
import { CachedRelationship, Identity, Relationship, RelationshipsController } from "@nmshd/transport";
import { Identity, Relationship, RelationshipsController } from "@nmshd/transport";
import { Inject } from "@nmshd/typescript-ioc";
import { nameof } from "ts-simple-nameof";
import { SchemaRepository, SchemaValidator, UseCase } from "../../common";
Expand All @@ -28,10 +28,10 @@ export class GetRelationshipsUseCase extends UseCase<GetRelationshipsRequest, Re
whitelist: {
[nameof<RelationshipDTO>((r) => r.peer)]: true,
[nameof<RelationshipDTO>((r) => r.status)]: true,
[`${nameof<RelationshipDTO>((r) => r.templateId)}`]: true
[nameof<RelationshipDTO>((r) => r.templateId)]: true
},
alias: {
[`${nameof<RelationshipDTO>((r) => r.templateId)}`]: `${nameof<Relationship>((r) => r.cache)}.${nameof<CachedRelationship>((r) => r.templateId)}`,
[nameof<RelationshipDTO>((r) => r.templateId)]: `${nameof<Relationship>((r) => r.templateId)}`,
[nameof<RelationshipDTO>((r) => r.status)]: nameof<Relationship>((r) => r.status),
[nameof<RelationshipDTO>((r) => r.peer)]: `${nameof<Relationship>((r) => r.peer)}.${nameof<Identity>((r) => r.address)}`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export class RejectRelationshipUseCase extends UseCase<RejectRelationshipRequest
return Result.fail(RuntimeErrors.general.recordNotFound(Relationship));
}

if (!relationship.cache) {
return Result.fail(RuntimeErrors.general.cacheEmpty(Relationship, relationship.id.toString()));
}

const updatedRelationship = await this.relationshipsController.reject(relationship.id);

await this.accountController.syncDatawallet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export class RejectRelationshipReactivationUseCase extends UseCase<RejectRelatio
return Result.fail(RuntimeErrors.general.recordNotFound(Relationship));
}

if (!relationship.cache) {
return Result.fail(RuntimeErrors.general.cacheEmpty(Relationship, relationship.id.toString()));
}

const updatedRelationship = await this.relationshipsController.rejectReactivation(relationship.id);

await this.accountController.syncDatawallet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,21 @@ import { Serializable } from "@js-soft/ts-serval";
import { ArbitraryRelationshipCreationContent, RelationshipCreationContent } from "@nmshd/content";
import { RelationshipAuditLogEntryDTO, RelationshipDTO } from "@nmshd/runtime-types";
import { Relationship, RelationshipAuditLogEntry } from "@nmshd/transport";
import { RuntimeErrors } from "../../common";

export class RelationshipMapper {
public static toRelationshipDTO(relationship: Relationship): RelationshipDTO {
if (!relationship.cache) {
throw RuntimeErrors.general.cacheEmpty(Relationship, relationship.id.toString());
}

return {
id: relationship.id.toString(),
templateId: relationship.cache.templateId.toString(),
templateId: relationship.templateId.toString(),
status: relationship.status,
peer: relationship.peer.address.toString(),
peerDeletionInfo: relationship.peerDeletionInfo?.toJSON(),
peerIdentity: {
address: relationship.peer.address.toString(),
publicKey: relationship.peer.publicKey.toBase64(false)
},
auditLog: relationship.cache.auditLog.map((entry) => this.toAuditLogEntryDTO(entry)),
creationContent: this.toCreationContent(relationship.cache.creationContent)
auditLog: relationship.auditLog.map((entry) => this.toAuditLogEntryDTO(entry)),
creationContent: this.toCreationContent(relationship.creationContent)
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export class RequestRelationshipReactivationUseCase extends UseCase<RequestRelat
return Result.fail(RuntimeErrors.general.recordNotFound(Relationship));
}

if (!relationship.cache) {
return Result.fail(RuntimeErrors.general.cacheEmpty(Relationship, relationship.id.toString()));
}

const updatedRelationship = await this.relationshipsController.requestReactivation(relationship.id);

await this.accountController.syncDatawallet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export class RevokeRelationshipUseCase extends UseCase<RevokeRelationshipRequest
return Result.fail(RuntimeErrors.general.recordNotFound(Relationship));
}

if (!relationship.cache) {
return Result.fail(RuntimeErrors.general.cacheEmpty(Relationship, relationship.id.toString()));
}

const updatedRelationship = await this.relationshipsController.revoke(relationship.id);

await this.accountController.syncDatawallet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export class RevokeRelationshipReactivationUseCase extends UseCase<RevokeRelatio
return Result.fail(RuntimeErrors.general.recordNotFound(Relationship));
}

if (!relationship.cache) {
return Result.fail(RuntimeErrors.general.cacheEmpty(Relationship, relationship.id.toString()));
}

const updatedRelationship = await this.relationshipsController.revokeReactivation(relationship.id);

await this.accountController.syncDatawallet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export class TerminateRelationshipUseCase extends UseCase<TerminateRelationshipR
return Result.fail(RuntimeErrors.general.recordNotFound(Relationship));
}

if (!relationship.cache) {
return Result.fail(RuntimeErrors.general.cacheEmpty(Relationship, relationship.id.toString()));
}

const updatedRelationship = await this.relationshipsController.terminate(relationship.id);

await this.accountController.syncDatawallet();
Expand Down
1 change: 0 additions & 1 deletion packages/transport/src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export * from "./publicRelationshipTemplateReferences/PublicRelationshipTemplate
export * from "./relationships/backbone/BackboneGetRelationships";
export * from "./relationships/backbone/BackbonePostRelationship";
export * from "./relationships/backbone/RelationshipClient";
export * from "./relationships/local/CachedRelationship";
export * from "./relationships/local/PeerDeletionInfo";
export * from "./relationships/local/Relationship";
export * from "./relationships/local/RelationshipAuditLog";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export class RelationshipTemplateController extends TransportController {
}

public async cleanupTemplatesOfDecomposedRelationship(relationship: Relationship): Promise<void> {
const templateOfRelationship = await this.getRelationshipTemplate(relationship.cache!.templateId);
const templateOfRelationship = await this.getRelationshipTemplate(relationship.templateId);
if (templateOfRelationship && (!templateOfRelationship.isOwn || templateOfRelationship.cache!.maxNumberOfAllocations === 1)) {
await this.templates.delete(templateOfRelationship);
}
Expand Down
Loading