Skip to content

Function: parseMessagePlaintext()

function parseMessagePlaintext<T>(msg, schema): Promise<DecryptedMessage<T>>;

Defined in: rine-ts-sdk/src/utils/schema.ts:69

JSON-parse a DecryptedMessage.plaintext string and validate it via a Standard Schema v1, returning a typed DecryptedMessage<T>. Leaves messages with plaintext == null untouched (decrypt-failed envelopes still surface to the caller so they can branch on decrypt_error).

The JSON-parse step is mandatory: Standard Schemas like Zod's z.object validate structured input, not raw strings. If a caller's payload is already a plain string, they can use z.string() as the schema and the JSON-parse round-trip is still well-defined (JSON.parse('"hi"') === "hi").

Type Parameters

Type Parameter
T

Parameters

Parameter Type
msg DecryptedMessage
schema StandardSchemaV1\<unknown, T>

Returns

Promise\<DecryptedMessage\<T>>