Skip to content

Commit a9fc837

Browse files
committed
Merge branch 'main' into release/v7
2 parents 8dd8e3d + 7cc57b2 commit a9fc837

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

packages/runtime/src/useCases/common/Schemas.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21380,6 +21380,7 @@ export const SendMessageRequest: any = {
2138021380
"definitions": {
2138121381
"SendMessageRequest": {
2138221382
"type": "object",
21383+
"additionalProperties": false,
2138321384
"properties": {
2138421385
"recipients": {
2138521386
"type": "array",
@@ -21399,10 +21400,9 @@ export const SendMessageRequest: any = {
2139921400
}
2140021401
},
2140121402
"required": [
21402-
"recipients",
21403-
"content"
21404-
],
21405-
"additionalProperties": false
21403+
"content",
21404+
"recipients"
21405+
]
2140621406
},
2140721407
"AddressString": {
2140821408
"type": "string",

packages/runtime/src/useCases/transport/messages/SendMessage.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import { Serializable } from "@js-soft/ts-serval";
22
import { ApplicationError, Result } from "@js-soft/ts-utils";
33
import { LocalRequestStatus, OutgoingRequestsController } from "@nmshd/consumption";
4-
import { ArbitraryMessageContent, Mail, Notification, Request, ResponseWrapper } from "@nmshd/content";
4+
import {
5+
ArbitraryMessageContent,
6+
ArbitraryMessageContentJSON,
7+
Mail,
8+
MailJSON,
9+
Notification,
10+
NotificationJSON,
11+
Request,
12+
RequestJSON,
13+
ResponseWrapper,
14+
ResponseWrapperJSON
15+
} from "@nmshd/content";
516
import { CoreAddress, CoreDate, CoreError, CoreId } from "@nmshd/core-types";
617
import { MessageDTO } from "@nmshd/runtime-types";
718
import { AccountController, File, FileController, MessageController, PeerDeletionStatus, RelationshipsController, RelationshipStatus, TransportCoreErrors } from "@nmshd/transport";
@@ -10,19 +21,23 @@ import _ from "lodash";
1021
import { AddressString, FileIdString, RuntimeErrors, SchemaRepository, SchemaValidator, UseCase } from "../../common";
1122
import { MessageMapper } from "./MessageMapper";
1223

13-
export interface SendMessageRequest {
24+
interface AbstractSendMessageRequest<T> {
1425
/**
1526
* @minItems 1
1627
* @uniqueItems true
1728
*/
1829
recipients: AddressString[];
19-
content: any;
30+
content: T;
2031
/**
2132
* @uniqueItems true
2233
*/
2334
attachments?: FileIdString[];
2435
}
2536

37+
export interface SendMessageRequest extends AbstractSendMessageRequest<MailJSON | ResponseWrapperJSON | NotificationJSON | ArbitraryMessageContentJSON | RequestJSON> {}
38+
39+
export interface SchemaValidatableSendMessageRequest extends AbstractSendMessageRequest<unknown> {}
40+
2641
class Validator extends SchemaValidator<SendMessageRequest> {
2742
public constructor(@Inject schemaRepository: SchemaRepository) {
2843
super(schemaRepository.getSchema("SendMessageRequest"));

packages/runtime/test/transport/messages.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ describe("Message errors", () => {
228228
"@type": "Mail",
229229
subject: "aSubject",
230230
body: "aBody"
231-
}
231+
} as any
232232
});
233233
expect(result).toBeAnError("Mail.to :: Value is not defined", "error.runtime.requestDeserialization");
234234
});
@@ -326,7 +326,7 @@ describe("Message errors", () => {
326326
test("should throw correct error for false content type", async () => {
327327
const result = await client1.transport.messages.sendMessage({
328328
recipients: [client2.address],
329-
content: {}
329+
content: {} as any
330330
});
331331
expect(result).toBeAnError("The content of a Message", "error.runtime.validation.invalidPropertyValue");
332332
});

0 commit comments

Comments
 (0)