fix: address presentation sync review findings

This commit is contained in:
lda
2026-07-14 11:42:14 +07:00 Verified
parent e42561a117
commit a16c652884
4 changed files with 98 additions and 0 deletions
@@ -160,6 +160,21 @@ const JoinSessionRequestSchema = Schema.Struct({
),
});
const SessionCredentialSchema = Schema.String.pipe(
Schema.minLength(1),
Schema.maxLength(MAX_MESSAGE_ID_LENGTH),
);
const SessionCodeSchema = Schema.String.pipe(
Schema.filter((value) => value.length === JOIN_CODE_LENGTH),
);
const SessionGrantSchema = Schema.Struct({
sessionId: SessionCredentialSchema,
code: SessionCodeSchema,
connectionToken: SessionCredentialSchema,
websocketPath: Schema.Literal("/api/presentation-sync/ws"),
snapshot: SnapshotSchema,
});
const parseJson = (input: string): DecodeResult<unknown> => {
// Measure UTF-8 bytes before parsing so websocket limits match transport size.
if (new TextEncoder().encode(input).byteLength > MAX_SYNC_MESSAGE_BYTES) {
@@ -235,3 +250,7 @@ export const decodeJoinSessionRequest = (
return { ok: false, error: "invalid_message" };
}
};
export const decodeSessionGrant = (
input: string,
): DecodeResult<SessionGrant> => decodeSchema(input, SessionGrantSchema);