Skip to content

js: Add convenient construction of rawPayload messages #1539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2024
Merged
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
25 changes: 25 additions & 0 deletions javascript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down