Skip to content

Commit

Permalink
js: Add convenient construction of rawPayload messages
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte committed Nov 29, 2024
1 parent 724e8dc commit 3ad873e
Showing 1 changed file with 25 additions and 0 deletions.
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 {
let headers = contentType ? { "content-type": contentType } : undefined;

return {
eventType,
payload: {},

Check failure on line 719 in javascript/src/index.ts

View workflow job for this annotation

GitHub Actions / build

'headers' is never reassigned. Use 'const' instead
transformationsParams: {
rawPayload: payload,
headers,
}
};
}

class MessageAttempt {
private readonly api: MessageAttemptApi;

Expand Down

0 comments on commit 3ad873e

Please sign in to comment.