From 29e863ff42eddfbf009da3fc0821505a165f58a3 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 29 Nov 2024 13:36:34 +0100 Subject: [PATCH] js: Add convenient construction of rawPayload messages --- javascript/src/index.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/javascript/src/index.ts b/javascript/src/index.ts index 8ada51317..ed96af0be 100644 --- a/javascript/src/index.ts +++ b/javascript/src/index.ts @@ -699,6 +699,31 @@ class Message { } } +/** + * Creates a `MessageIn` with the payload already being serialized. + * + * The payload is not normalized on the server (usually whitespace outside + * of string literals, unnecessarily escaped characters in string and such + * are fixed up by the server), and is not even required to be JSON. + * + * @param payload Serialized message payload + * @param contentType Content type of the payload to send as a header. Defaults to `application/json`. + * + * See the class documentation for details about the other parameters. + */ +export function messageInRaw(eventType: string, payload: string, contentType?: string): MessageIn { + const headers = contentType ? { "content-type": contentType } : undefined; + + return { + eventType, + payload: {}, + transformationsParams: { + rawPayload: payload, + headers, + } + }; +} + class MessageAttempt { private readonly api: MessageAttemptApi;