Modernize: upgrade matrix-js-sdk to v42, fix dead auto-join, update login endpoint #1
Loading…
Reference in a new issue
No description provided.
Delete branch "modernize/matrix-js-sdk-42-upgrade"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
Note: this should target the upstream repo jochen/node-red-contrib-matrix, not this fork - the create_pull_request tool's cross-repo head (owner:branch) failed against this Forgejo instance, so this PR needs to be re-targeted (or recreated) against jochen/node-red-contrib-matrix, same as the earlier webspace-gen fixes.
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).
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.Superseded by jochen/node-red-contrib-matrix#1, now that the repo's stale default-branch setting (pointed at a non-existent "main" ref, causing the earlier 500s) has been fixed. Closing this duplicate.
Pull request closed