Modernize: upgrade matrix-js-sdk to v42, fix dead auto-join, update login endpoint #1

Merged
jochen merged 2 commits from claude/node-red-contrib-matrix:modernize/matrix-js-sdk-42-upgrade into master 2026-09-16 20:19:28 +00:00
Contributor

Follow-up to the audit requested in Redmine #4 ("node-red-contrib-matrix anschauen, steinalt, krasser bit rot"). The core Node-RED node structure (config node + 4 function nodes) is sound and needed no changes; the rot was entirely in the pinned dependency and one long-standing bug.

matrix-js-sdk 5.0.0 to 42.4.0: the SDK is now ESM-only, so require() throws ERR_REQUIRE_ESM. Loaded lazily via dynamic import() on first config-node creation; matrixClient stays null until resolved. Every call site already guarded on that, so no other structural changes needed. Verified locally against the real published package (import works from CJS, all used client methods still present with compatible signatures, sync ERROR/SYNCING/PREPARED states still drive the connected/disconnected status logic) - not verified against a live homeserver.

Added package-lock.json (missing before), removed node-red from dependencies (a node module should not bundle its host runtime), added engines.node >=22 to match the SDK's own requirement, bumped package version to 0.1.0.

Bug fix: the RoomMember.membership handler compared against node.userId (never set) instead of node.userid, so auto-join-on-invite has been dead since the first commit. Fixed.

Editor fix: token-generation login now uses /_matrix/client/v3/login instead of the retired r0 prefix.

Deliberately out of scope: end-to-end encryption (opt-in via initRustCrypto(), not needed for this module's plaintext-only usage).

Please verify before merging: real homeserver behavior end-to-end, and that your Node-RED host runs on Node >=22 (matrix-js-sdk 42's own requirement).

(Originally opened as claude/node-red-contrib-matrix#1; the initial attempt to open this directly against the upstream repo failed with a 500 caused by a stale default-branch setting on this repo pointing at a non-existent "main" ref - fixed now, re-opening here directly.)

Follow-up to the audit requested in Redmine #4 ("node-red-contrib-matrix anschauen, steinalt, krasser bit rot"). The core Node-RED node structure (config node + 4 function nodes) is sound and needed no changes; the rot was entirely in the pinned dependency and one long-standing bug. matrix-js-sdk 5.0.0 to 42.4.0: the SDK is now ESM-only, so require() throws ERR_REQUIRE_ESM. Loaded lazily via dynamic import() on first config-node creation; matrixClient stays null until resolved. Every call site already guarded on that, so no other structural changes needed. Verified locally against the real published package (import works from CJS, all used client methods still present with compatible signatures, sync ERROR/SYNCING/PREPARED states still drive the connected/disconnected status logic) - not verified against a live homeserver. Added package-lock.json (missing before), removed node-red from dependencies (a node module should not bundle its host runtime), added engines.node >=22 to match the SDK's own requirement, bumped package version to 0.1.0. Bug fix: the RoomMember.membership handler compared against node.userId (never set) instead of node.userid, so auto-join-on-invite has been dead since the first commit. Fixed. Editor fix: token-generation login now uses /_matrix/client/v3/login instead of the retired r0 prefix. Deliberately out of scope: end-to-end encryption (opt-in via initRustCrypto(), not needed for this module's plaintext-only usage). Please verify before merging: real homeserver behavior end-to-end, and that your Node-RED host runs on Node >=22 (matrix-js-sdk 42's own requirement). (Originally opened as claude/node-red-contrib-matrix#1; the initial attempt to open this directly against the upstream repo failed with a 500 caused by a stale default-branch setting on this repo pointing at a non-existent "main" ref - fixed now, re-opening here directly.)
matrix-js-sdk was pinned to ^5.0.0 (2019/2020) and has since gone
ESM-only, so require("matrix-js-sdk") now throws ERR_REQUIRE_ESM.
Node-RED still loads this file synchronously via require(), so the SDK
is now loaded lazily via a dynamic import() the first time a
matrix-server config node is created; node.matrixClient stays null
until that resolves. Every existing call site already guards on
matrixClient being set or on the connected/disconnected events, so
this is a safe change.

Bumped matrix-js-sdk to ^42.4.0 and added package-lock.json (there was
none before). Verified locally against the real published package
(dynamic import, createClient, startClient, sendEvent, sendTextMessage,
sendNotice, joinRoom, getRooms all present with compatible signatures;
the ERROR/SYNCING/PREPARED sync states still fire as expected against
an unreachable homeserver) - not verified against a real Matrix
homeserver.

Removed node-red from dependencies: a Node-RED module should never
bundle the runtime that hosts it, that's supplied by the host. Added
an engines.node >=22.0.0 entry to match matrix-js-sdk's own
requirement. Bumped the package version to 0.1.0 given the breaking
dependency change.

Also fixes a real bug found during the audit: MatrixServerNode stores
the configured id as node.userid (lowercase), but the
RoomMember.membership handler compared against node.userId (capital
ID), which is never set - so the auto-join-on-invite feature has been
dead code since the very first commit. Fixed the comparison to use
node.userid.

matrix.html's "Generate Token" button logged in against the deprecated
/_matrix/client/r0/login endpoint; switched it to /_matrix/client/v3/login,
since r0 is retired on current Synapse/Dendrite versions.

Not covered here: TLS/network behavior, and end-to-end encryption
(intentionally out of scope - this module only ever sent/received
plaintext org.nodered.msg / m.room.message events, and
matrix-js-sdk's crypto is opt-in via initRustCrypto(), so skipping it
keeps behavior equivalent to before). Please test against a real
homeserver before merging - I could not do that in this environment.
The previous commit on this branch accidentally dropped the "default
room specified in the server" bullet from the matrix-sendtext help
text while retyping the file. This restores it; no functional change.
jochen approved these changes 2026-09-16 20:17:40 +00:00
Dismissed
jochen approved these changes 2026-09-16 20:19:11 +00:00
jochen merged commit 3ba784f98d into master 2026-09-16 20:19:28 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jochen/node-red-contrib-matrix!1
No description provided.