Upgrade from matrix-js-sdk v34 to v34.13.0

This commit is contained in:
2026-02-19 22:45:31 -07:00
parent 99909a77c3
commit 68e63e5def
4 changed files with 111 additions and 124 deletions
+52 -46
View File
@@ -1,12 +1,12 @@
{ {
"name": "node-red-contrib-matrix-chat", "name": "node-red-contrib-matrix-chat",
"version": "0.8.0", "version": "0.9.2",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "node-red-contrib-matrix-chat", "name": "node-red-contrib-matrix-chat",
"version": "0.8.0", "version": "0.9.2",
"license": "SEE LICENSE FILE", "license": "SEE LICENSE FILE",
"dependencies": { "dependencies": {
"abort-controller": "^3.0.0", "abort-controller": "^3.0.0",
@@ -15,7 +15,7 @@
"got": "^12.0.2", "got": "^12.0.2",
"image-size": "^1.0.2", "image-size": "^1.0.2",
"isomorphic-webcrypto": "^2.3.8", "isomorphic-webcrypto": "^2.3.8",
"matrix-js-sdk": "34.11.1", "matrix-js-sdk": "^34.13.0",
"mime": "^3.0.0", "mime": "^3.0.0",
"node-fetch": "^3.3.0", "node-fetch": "^3.3.0",
"node-localstorage": "^2.2.1", "node-localstorage": "^2.2.1",
@@ -25,7 +25,7 @@
"utf8": "^3.0.0" "utf8": "^3.0.0"
}, },
"engines": { "engines": {
"node": ">=14.0.0" "node": ">=18.0.0"
} }
}, },
"node_modules/@ampproject/remapping": { "node_modules/@ampproject/remapping": {
@@ -4191,6 +4191,7 @@
"version": "9.1.0", "version": "9.1.0",
"resolved": "https://registry.npmjs.org/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-9.1.0.tgz", "resolved": "https://registry.npmjs.org/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-9.1.0.tgz",
"integrity": "sha512-CtPoNcoRW6ehwxpRQAksG3tR+NJ7k4DV02nMFYTDwQtie1V4R8OTY77BjEIs97NOblhtS26jU8m1lWsOBEz0Og==", "integrity": "sha512-CtPoNcoRW6ehwxpRQAksG3tR+NJ7k4DV02nMFYTDwQtie1V4R8OTY77BjEIs97NOblhtS26jU8m1lWsOBEz0Og==",
"license": "Apache-2.0",
"engines": { "engines": {
"node": ">= 10" "node": ">= 10"
} }
@@ -4198,7 +4199,8 @@
"node_modules/@matrix-org/olm": { "node_modules/@matrix-org/olm": {
"version": "3.2.15", "version": "3.2.15",
"resolved": "https://registry.npmjs.org/@matrix-org/olm/-/olm-3.2.15.tgz", "resolved": "https://registry.npmjs.org/@matrix-org/olm/-/olm-3.2.15.tgz",
"integrity": "sha512-S7lOrndAK9/8qOtaTq/WhttJC/o4GAzdfK0MUPpo8ApzsJEC0QjtwrkC3KBXdFP1cD1MXi/mlKR7aaoVMKgs6Q==" "integrity": "sha512-S7lOrndAK9/8qOtaTq/WhttJC/o4GAzdfK0MUPpo8ApzsJEC0QjtwrkC3KBXdFP1cD1MXi/mlKR7aaoVMKgs6Q==",
"license": "Apache-2.0"
}, },
"node_modules/@nodelib/fs.scandir": { "node_modules/@nodelib/fs.scandir": {
"version": "2.1.5", "version": "2.1.5",
@@ -6620,9 +6622,10 @@
"integrity": "sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA==" "integrity": "sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA=="
}, },
"node_modules/base-x": { "node_modules/base-x": {
"version": "5.0.0", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/base-x/-/base-x-5.0.0.tgz", "resolved": "https://registry.npmjs.org/base-x/-/base-x-5.0.1.tgz",
"integrity": "sha512-sMW3VGSX1QWVFA6l8U62MLKz29rRfpTlYdCqLdpLo1/Yd4zZwSbnUaDfciIAowAqvq7YFnWq9hrhdg1KYgc1lQ==" "integrity": "sha512-M7uio8Zt++eg3jPj+rHMfCC+IuygQHHCOU+IYsVtik6FWjuYpVt/+MRKcgsAMHh8mMFAwnB+Bs+mTrFiXjMzKg==",
"license": "MIT"
}, },
"node_modules/base64-js": { "node_modules/base64-js": {
"version": "1.5.1", "version": "1.5.1",
@@ -6824,6 +6827,7 @@
"version": "6.0.0", "version": "6.0.0",
"resolved": "https://registry.npmjs.org/bs58/-/bs58-6.0.0.tgz", "resolved": "https://registry.npmjs.org/bs58/-/bs58-6.0.0.tgz",
"integrity": "sha512-PD0wEnEYg6ijszw/u8s+iI3H17cTymlrwkKhDhPZq+Sokl3AU4htyBFTjAeNAlCCmg0f53g6ih3jATyCKftTfw==", "integrity": "sha512-PD0wEnEYg6ijszw/u8s+iI3H17cTymlrwkKhDhPZq+Sokl3AU4htyBFTjAeNAlCCmg0f53g6ih3jATyCKftTfw==",
"license": "MIT",
"dependencies": { "dependencies": {
"base-x": "^5.0.0" "base-x": "^5.0.0"
} }
@@ -10629,9 +10633,9 @@
} }
}, },
"node_modules/loglevel": { "node_modules/loglevel": {
"version": "1.8.1", "version": "1.9.2",
"resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.8.1.tgz", "resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.9.2.tgz",
"integrity": "sha512-tCRIJM51SHjAayKwC+QAg8hT8vg6z7GSgLJKGvzuPb1Wc+hLzqtuVLxp6/HzSPOozuK+8ErAhy7U/sVzw8Dgfg==", "integrity": "sha512-HgMmCqIJSAKqo68l0rS2AanEWfkxaZ5wNiEFb5ggm08lDs9Xl2KxBlX3PTcaD2chBM1gXAYf491/M2Rv8Jwayg==",
"engines": { "engines": {
"node": ">= 0.6.0" "node": ">= 0.6.0"
}, },
@@ -10713,9 +10717,10 @@
"integrity": "sha512-1QEOsXO+bhyCroIe2/A5OwaxHvBm7EsSQ46DEDn8RBIfQwN5HWBpFvyWWR4QY0KHPPnnJdI99wgRiAl7Ad5qaA==" "integrity": "sha512-1QEOsXO+bhyCroIe2/A5OwaxHvBm7EsSQ46DEDn8RBIfQwN5HWBpFvyWWR4QY0KHPPnnJdI99wgRiAl7Ad5qaA=="
}, },
"node_modules/matrix-js-sdk": { "node_modules/matrix-js-sdk": {
"version": "34.11.1", "version": "34.13.0",
"resolved": "https://registry.npmjs.org/matrix-js-sdk/-/matrix-js-sdk-34.11.1.tgz", "resolved": "https://registry.npmjs.org/matrix-js-sdk/-/matrix-js-sdk-34.13.0.tgz",
"integrity": "sha512-rDbIUIqEsN/pbHb6haBQmjxxgeb9G3Df2IhPPOotUbX6R1KseA8yJ6TAY0YySM2zVaBV3yZ6dnKWexF/uWvZfA==", "integrity": "sha512-AAU8ZdCawca+7ucQfdcC3LA85OtCTV7QeqcjvKt/ZZhU3xL9VoawuoRQ+4R6H8KZnqyJmT4j7bdeC0jG4qcqLg==",
"license": "Apache-2.0",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.12.5", "@babel/runtime": "^7.12.5",
"@matrix-org/matrix-sdk-crypto-wasm": "^9.0.0", "@matrix-org/matrix-sdk-crypto-wasm": "^9.0.0",
@@ -10726,33 +10731,34 @@
"jwt-decode": "^4.0.0", "jwt-decode": "^4.0.0",
"loglevel": "^1.7.1", "loglevel": "^1.7.1",
"matrix-events-sdk": "0.0.1", "matrix-events-sdk": "0.0.1",
"matrix-widget-api": "^1.8.2", "matrix-widget-api": "^1.10.0",
"oidc-client-ts": "^3.0.1", "oidc-client-ts": "^3.0.1",
"p-retry": "4", "p-retry": "4",
"sdp-transform": "^2.14.1", "sdp-transform": "^2.14.1",
"unhomoglyph": "^1.0.6", "unhomoglyph": "^1.0.6",
"uuid": "10" "uuid": "11"
}, },
"engines": { "engines": {
"node": ">=20.0.0" "node": ">=20.0.0"
} }
}, },
"node_modules/matrix-js-sdk/node_modules/uuid": { "node_modules/matrix-js-sdk/node_modules/uuid": {
"version": "10.0.0", "version": "11.1.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.0.tgz",
"integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==", "integrity": "sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==",
"funding": [ "funding": [
"https://github.com/sponsors/broofa", "https://github.com/sponsors/broofa",
"https://github.com/sponsors/ctavan" "https://github.com/sponsors/ctavan"
], ],
"license": "MIT",
"bin": { "bin": {
"uuid": "dist/bin/uuid" "uuid": "dist/esm/bin/uuid"
} }
}, },
"node_modules/matrix-widget-api": { "node_modules/matrix-widget-api": {
"version": "1.13.1", "version": "1.17.0",
"resolved": "https://registry.npmjs.org/matrix-widget-api/-/matrix-widget-api-1.13.1.tgz", "resolved": "https://registry.npmjs.org/matrix-widget-api/-/matrix-widget-api-1.17.0.tgz",
"integrity": "sha512-mkOHUVzaN018TCbObfGOSaMW2GoUxOfcxNNlTVx5/HeMk3OSQPQM0C9oEME5Liiv/dBUoSrEB64V8wF7e/gb1w==", "integrity": "sha512-5FHoo3iEP3Bdlv5jsYPWOqj+pGdFQNLWnJLiB0V7Ygne7bb+Gsj3ibyFyHWC6BVw+Z+tSW4ljHpO17I9TwStwQ==",
"dependencies": { "dependencies": {
"@types/events": "^3.0.0", "@types/events": "^3.0.0",
"events": "^3.2.0" "events": "^3.2.0"
@@ -13767,9 +13773,9 @@
} }
}, },
"node_modules/sdp-transform": { "node_modules/sdp-transform": {
"version": "2.14.1", "version": "2.15.0",
"resolved": "https://registry.npmjs.org/sdp-transform/-/sdp-transform-2.14.1.tgz", "resolved": "https://registry.npmjs.org/sdp-transform/-/sdp-transform-2.15.0.tgz",
"integrity": "sha512-RjZyX3nVwJyCuTo5tGPx+PZWkDMCg7oOLpSlhjDdZfwUoNqG1mM8nyj31IGHyaPWXhjbP7cdK3qZ2bmkJ1GzRw==", "integrity": "sha512-KrOH82c/W+GYQ0LHqtr3caRpM3ITglq3ljGUIb8LTki7ByacJZ9z+piSGiwZDsRyhQbYBOBJgr2k6X4BZXi3Kw==",
"bin": { "bin": {
"sdp-verify": "checker.js" "sdp-verify": "checker.js"
} }
@@ -20333,9 +20339,9 @@
"integrity": "sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA==" "integrity": "sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA=="
}, },
"base-x": { "base-x": {
"version": "5.0.0", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/base-x/-/base-x-5.0.0.tgz", "resolved": "https://registry.npmjs.org/base-x/-/base-x-5.0.1.tgz",
"integrity": "sha512-sMW3VGSX1QWVFA6l8U62MLKz29rRfpTlYdCqLdpLo1/Yd4zZwSbnUaDfciIAowAqvq7YFnWq9hrhdg1KYgc1lQ==" "integrity": "sha512-M7uio8Zt++eg3jPj+rHMfCC+IuygQHHCOU+IYsVtik6FWjuYpVt/+MRKcgsAMHh8mMFAwnB+Bs+mTrFiXjMzKg=="
}, },
"base64-js": { "base64-js": {
"version": "1.5.1", "version": "1.5.1",
@@ -23413,9 +23419,9 @@
} }
}, },
"loglevel": { "loglevel": {
"version": "1.8.1", "version": "1.9.2",
"resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.8.1.tgz", "resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.9.2.tgz",
"integrity": "sha512-tCRIJM51SHjAayKwC+QAg8hT8vg6z7GSgLJKGvzuPb1Wc+hLzqtuVLxp6/HzSPOozuK+8ErAhy7U/sVzw8Dgfg==" "integrity": "sha512-HgMmCqIJSAKqo68l0rS2AanEWfkxaZ5wNiEFb5ggm08lDs9Xl2KxBlX3PTcaD2chBM1gXAYf491/M2Rv8Jwayg=="
}, },
"loose-envify": { "loose-envify": {
"version": "1.4.0", "version": "1.4.0",
@@ -23477,9 +23483,9 @@
"integrity": "sha512-1QEOsXO+bhyCroIe2/A5OwaxHvBm7EsSQ46DEDn8RBIfQwN5HWBpFvyWWR4QY0KHPPnnJdI99wgRiAl7Ad5qaA==" "integrity": "sha512-1QEOsXO+bhyCroIe2/A5OwaxHvBm7EsSQ46DEDn8RBIfQwN5HWBpFvyWWR4QY0KHPPnnJdI99wgRiAl7Ad5qaA=="
}, },
"matrix-js-sdk": { "matrix-js-sdk": {
"version": "34.11.1", "version": "34.13.0",
"resolved": "https://registry.npmjs.org/matrix-js-sdk/-/matrix-js-sdk-34.11.1.tgz", "resolved": "https://registry.npmjs.org/matrix-js-sdk/-/matrix-js-sdk-34.13.0.tgz",
"integrity": "sha512-rDbIUIqEsN/pbHb6haBQmjxxgeb9G3Df2IhPPOotUbX6R1KseA8yJ6TAY0YySM2zVaBV3yZ6dnKWexF/uWvZfA==", "integrity": "sha512-AAU8ZdCawca+7ucQfdcC3LA85OtCTV7QeqcjvKt/ZZhU3xL9VoawuoRQ+4R6H8KZnqyJmT4j7bdeC0jG4qcqLg==",
"requires": { "requires": {
"@babel/runtime": "^7.12.5", "@babel/runtime": "^7.12.5",
"@matrix-org/matrix-sdk-crypto-wasm": "^9.0.0", "@matrix-org/matrix-sdk-crypto-wasm": "^9.0.0",
@@ -23490,25 +23496,25 @@
"jwt-decode": "^4.0.0", "jwt-decode": "^4.0.0",
"loglevel": "^1.7.1", "loglevel": "^1.7.1",
"matrix-events-sdk": "0.0.1", "matrix-events-sdk": "0.0.1",
"matrix-widget-api": "^1.8.2", "matrix-widget-api": "^1.10.0",
"oidc-client-ts": "^3.0.1", "oidc-client-ts": "^3.0.1",
"p-retry": "4", "p-retry": "4",
"sdp-transform": "^2.14.1", "sdp-transform": "^2.14.1",
"unhomoglyph": "^1.0.6", "unhomoglyph": "^1.0.6",
"uuid": "10" "uuid": "11"
}, },
"dependencies": { "dependencies": {
"uuid": { "uuid": {
"version": "10.0.0", "version": "11.1.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.0.tgz",
"integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==" "integrity": "sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A=="
} }
} }
}, },
"matrix-widget-api": { "matrix-widget-api": {
"version": "1.13.1", "version": "1.17.0",
"resolved": "https://registry.npmjs.org/matrix-widget-api/-/matrix-widget-api-1.13.1.tgz", "resolved": "https://registry.npmjs.org/matrix-widget-api/-/matrix-widget-api-1.17.0.tgz",
"integrity": "sha512-mkOHUVzaN018TCbObfGOSaMW2GoUxOfcxNNlTVx5/HeMk3OSQPQM0C9oEME5Liiv/dBUoSrEB64V8wF7e/gb1w==", "integrity": "sha512-5FHoo3iEP3Bdlv5jsYPWOqj+pGdFQNLWnJLiB0V7Ygne7bb+Gsj3ibyFyHWC6BVw+Z+tSW4ljHpO17I9TwStwQ==",
"requires": { "requires": {
"@types/events": "^3.0.0", "@types/events": "^3.0.0",
"events": "^3.2.0" "events": "^3.2.0"
@@ -25867,9 +25873,9 @@
} }
}, },
"sdp-transform": { "sdp-transform": {
"version": "2.14.1", "version": "2.15.0",
"resolved": "https://registry.npmjs.org/sdp-transform/-/sdp-transform-2.14.1.tgz", "resolved": "https://registry.npmjs.org/sdp-transform/-/sdp-transform-2.15.0.tgz",
"integrity": "sha512-RjZyX3nVwJyCuTo5tGPx+PZWkDMCg7oOLpSlhjDdZfwUoNqG1mM8nyj31IGHyaPWXhjbP7cdK3qZ2bmkJ1GzRw==" "integrity": "sha512-KrOH82c/W+GYQ0LHqtr3caRpM3ITglq3ljGUIb8LTki7ByacJZ9z+piSGiwZDsRyhQbYBOBJgr2k6X4BZXi3Kw=="
}, },
"semver": { "semver": {
"version": "7.6.2", "version": "7.6.2",
+6 -3
View File
@@ -9,7 +9,7 @@
"got": "^12.0.2", "got": "^12.0.2",
"image-size": "^1.0.2", "image-size": "^1.0.2",
"isomorphic-webcrypto": "^2.3.8", "isomorphic-webcrypto": "^2.3.8",
"matrix-js-sdk": "34.11.1", "matrix-js-sdk": "^34.13.0",
"mime": "^3.0.0", "mime": "^3.0.0",
"node-fetch": "^3.3.0", "node-fetch": "^3.3.0",
"node-localstorage": "^2.2.1", "node-localstorage": "^2.2.1",
@@ -55,7 +55,7 @@
} }
}, },
"engines": { "engines": {
"node": ">=14.0.0" "node": ">=18.0.0"
}, },
"keywords": [ "keywords": [
"node-red", "node-red",
@@ -72,5 +72,8 @@
"name": "Skylar Sadlier", "name": "Skylar Sadlier",
"url": "https://skylar.tech" "url": "https://skylar.tech"
}, },
"license": "SEE LICENSE FILE" "license": "SEE LICENSE FILE",
"engines": {
"node": ">=18.0.0"
}
} }
+2 -2
View File
@@ -58,11 +58,11 @@ module.exports = function(RED) {
RED.nodes.registerType("matrix-decrypt-file", MatrixDecryptFile); RED.nodes.registerType("matrix-decrypt-file", MatrixDecryptFile);
function atob(a) { function atob(a) {
return new Buffer.from(a, 'base64').toString('binary'); return Buffer.from(a, 'base64').toString('binary');
} }
function btoa(b) { function btoa(b) {
return new Buffer.from(b).toString('base64'); return Buffer.from(b).toString('base64');
} }
// the following was taken & modified from https://github.com/matrix-org/browser-encrypt-attachment/blob/master/index.js // the following was taken & modified from https://github.com/matrix-org/browser-encrypt-attachment/blob/master/index.js
+51 -73
View File
@@ -1,51 +1,32 @@
const {RelationType, TimelineWindow} = require("matrix-js-sdk");
global.Olm = require('olm'); global.Olm = require('olm');
const fs = require("fs-extra"); const fs = require("fs-extra");
let RelationType, sdk, LocalStorageCryptoStore, RoomEvent, RoomMemberEvent, HttpApiEvent, ClientEvent, MemoryStore; const sdk = require("matrix-js-sdk");
(async () => {
const mod = await import("matrix-js-sdk");
RelationType = mod.RelationType;
// matrix-js-sdk doesn't export a default the top-level export is the same object:
sdk = mod;
RoomEvent = mod.RoomEvent;
RoomMemberEvent = mod.RoomMemberEvent;
HttpApiEvent = mod.HttpApiEvent;
ClientEvent = mod.ClientEvent;
MemoryStore = mod.MemoryStore;
// For LocalStorageCryptoStore, specify the file extension for Node 20+:
const cmod = await import("matrix-js-sdk/lib/crypto/store/localStorage-crypto-store.js");
LocalStorageCryptoStore = cmod.LocalStorageCryptoStore;
})();
const { resolve } = require('path'); const { resolve } = require('path');
const { LocalStorage } = require('node-localstorage'); const { LocalStorage } = require('node-localstorage');
const { LocalStorageCryptoStore } = require('matrix-js-sdk/lib/crypto/store/localStorage-crypto-store');
const {RoomEvent, RoomMemberEvent, HttpApiEvent, ClientEvent, MemoryStore} = require("matrix-js-sdk");
require("abort-controller/polyfill"); // polyfill abort-controller if we don't have it require("abort-controller/polyfill"); // polyfill abort-controller if we don't have it
if (!globalThis.fetch) { if (!globalThis.fetch) {
// polyfill fetch if we don't have it // polyfill fetch if we don't have it
if (!globalThis.fetch) { if (!globalThis.fetch) {
import('node-fetch').then(({ default: fetch, Headers, Request, Response }) => { import('node-fetch').then(({ default: fetch, Headers, Request, Response }) => {
Object.assign(globalThis, { fetch, Headers, Request, Response }); Object.assign(globalThis, { fetch, Headers, Request, Response })
}); })
} }
} }
module.exports = function(RED) { module.exports = function(RED) {
// disable logging if set to "off" // disable logging if set to "off"
let loggingSettings = RED.settings.get('logging'); let loggingSettings = RED.settings.get('logging');
if ( if(
typeof loggingSettings.console !== 'undefined' && typeof loggingSettings.console !== 'undefined' &&
typeof loggingSettings.console.level !== 'undefined' && typeof loggingSettings.console.level !== 'undefined' &&
['info','debug','trace'].indexOf(loggingSettings.console.level.toLowerCase()) >= 0 ['info','debug','trace'].indexOf(loggingSettings.console.level.toLowerCase()) >= 0
) { ) {
import('matrix-js-sdk/lib/logger.js') const { logger } = require('matrix-js-sdk/lib/logger');
.then(({ logger }) => { logger.disableAll();
logger.disableAll();
})
.catch((err) => {
console.error("Error loading logger module:", err);
});
} }
function MatrixFolderNameFromUserId(name) { function MatrixFolderNameFromUserId(name) {
@@ -74,18 +55,17 @@ module.exports = function(RED) {
this.autoAcceptRoomInvites = n.autoAcceptRoomInvites; this.autoAcceptRoomInvites = n.autoAcceptRoomInvites;
this.e2ee = n.enableE2ee || false; this.e2ee = n.enableE2ee || false;
this.globalAccess = n.global; this.globalAccess = n.global;
this.allowUnknownDevices = n.allowUnknownDevices || false;
this.initializedAt = new Date(); this.initializedAt = new Date();
node.initialSyncLimit = 25; node.initialSyncLimit = 25;
// Keep track of all consumers of this node to catch errors // Keep track of all consumers of this node to be able to catch errors
node.register = function(consumerNode) { node.register = function(consumerNode) {
node.users[consumerNode.id] = consumerNode; node.users[consumerNode.id] = consumerNode;
}; };
node.deregister = function(consumerNode) { node.deregister = function(consumerNode) {
delete node.users[consumerNode.id]; delete node.users[consumerNode.id];
}; };
if(!this.userId) { if(!this.userId) {
node.log("Matrix connection failed: missing user ID in configuration."); node.log("Matrix connection failed: missing user ID in configuration.");
return; return;
@@ -118,7 +98,7 @@ module.exports = function(RED) {
device_id = this.matrixClient.getDeviceId(); device_id = this.matrixClient.getDeviceId();
if(!device_id && node.enableE2ee) { if(!device_id && node.enableE2ee) {
node.error("Failed to auto detect deviceId for this auth token. You will need to manually specify one. You may need to login to create a new deviceId.", {}); node.error("Failed to auto detect deviceId for this auth token. You will need to manually specify one. You may need to login to create a new deviceId.", {})
} else { } else {
if(!stored_device_id || stored_device_id !== device_id) { if(!stored_device_id || stored_device_id !== device_id) {
node.log(`Saving Device ID (old:${stored_device_id} new:${device_id})`); node.log(`Saving Device ID (old:${stored_device_id} new:${device_id})`);
@@ -135,7 +115,7 @@ module.exports = function(RED) {
node.matrixClient.setDeviceDetails(device_id, { node.matrixClient.setDeviceDetails(device_id, {
display_name: node.deviceLabel display_name: node.deviceLabel
}).then( }).then(
function() {}, function(response) {},
function(error) { function(error) {
node.error("Failed to set device label: " + error, {}); node.error("Failed to set device label: " + error, {});
} }
@@ -173,6 +153,7 @@ module.exports = function(RED) {
}), }),
userId: this.userId, userId: this.userId,
deviceId: (this.deviceId || getStoredDeviceId(localStorage)) || undefined deviceId: (this.deviceId || getStoredDeviceId(localStorage)) || undefined
// verificationMethods: ["m.sas.v1"]
}); });
node.debug(`hasLazyLoadMembersEnabled=${node.matrixClient.hasLazyLoadMembersEnabled()}`); node.debug(`hasLazyLoadMembersEnabled=${node.matrixClient.hasLazyLoadMembersEnabled()}`);
@@ -198,7 +179,7 @@ module.exports = function(RED) {
if(node.globalAccess) { if(node.globalAccess) {
try { try {
node.context().global.set('matrixClient["'+node.userId+'"]', undefined); node.context().global.set('matrixClient["'+node.userId+'"]', undefined);
} catch(e) { } catch(e){
node.error(e.message, {}); node.error(e.message, {});
} }
} }
@@ -212,15 +193,15 @@ module.exports = function(RED) {
node.matrixClient.on(RoomEvent.Timeline, async function(event, room, toStartOfTimeline, removed, data) { node.matrixClient.on(RoomEvent.Timeline, async function(event, room, toStartOfTimeline, removed, data) {
if (toStartOfTimeline) { if (toStartOfTimeline) {
node.log("Ignoring" + (event.isEncrypted() ? ' encrypted' : '') +" timeline event [" + (event.getContent()['msgtype'] || event.getType()) + "]: (" + room.name + ") " + event.getId() + " for reason: paginated result"); node.log("Ignoring" + (event.isEncrypted() ? ' encrypted' : '') +" timeline event [" + (event.getContent()['msgtype'] || event.getType()) + "]: (" + room.name + ") " + event.getId() + " for reason: paginated result");
return; return; // ignore paginated results
} }
if (!data || !data.liveEvent) { if (!data || !data.liveEvent) {
node.log("Ignoring" + (event.isEncrypted() ? ' encrypted' : '') +" timeline event [" + (event.getContent()['msgtype'] || event.getType()) + "]: (" + room.name + ") " + event.getId() + " for reason: old message"); node.log("Ignoring" + (event.isEncrypted() ? ' encrypted' : '') +" timeline event [" + (event.getContent()['msgtype'] || event.getType()) + "]: (" + room.name + ") " + event.getId() + " for reason: old message");
return; return; // ignore old message (we only want live events)
} }
if(node.initializedAt > event.getDate()) { if(node.initializedAt > event.getDate()) {
node.log("Ignoring" + (event.isEncrypted() ? ' encrypted' : '') +" timeline event [" + (event.getContent()['msgtype'] || event.getType()) + "]: (" + room.name + ") " + event.getId() + " for reason: old message before init"); node.log("Ignoring" + (event.isEncrypted() ? ' encrypted' : '') +" timeline event [" + (event.getContent()['msgtype'] || event.getType()) + "]: (" + room.name + ") " + event.getId() + " for reason: old message before init");
return; return; // skip events that occurred before our client initialized
} }
try { try {
@@ -395,6 +376,7 @@ module.exports = function(RED) {
} }
}); });
node.matrixClient.on(HttpApiEvent.SessionLoggedOut, async function(errorObj){ node.matrixClient.on(HttpApiEvent.SessionLoggedOut, async function(errorObj){
// Example if user auth token incorrect: // Example if user auth token incorrect:
// { // {
@@ -417,7 +399,6 @@ module.exports = function(RED) {
node.log("Initializing crypto..."); node.log("Initializing crypto...");
await node.matrixClient.initCrypto(); await node.matrixClient.initCrypto();
node.matrixClient.getCrypto().globalBlacklistUnverifiedDevices = false; // prevent errors from unverified devices node.matrixClient.getCrypto().globalBlacklistUnverifiedDevices = false; // prevent errors from unverified devices
node.matrixClient.getCrypto().globalErrorOnUnknownDevices = !node.allowUnknownDevices;
} }
node.log("Connecting to Matrix server..."); node.log("Connecting to Matrix server...");
await node.matrixClient.startClient({ await node.matrixClient.startClient({
@@ -467,7 +448,7 @@ module.exports = function(RED) {
node.error("Auth check failed: " + err, {}); node.error("Auth check failed: " + err, {});
} }
} }
); )
})(); })();
} }
} }
@@ -492,19 +473,17 @@ module.exports = function(RED) {
deviceId = req.body.deviceId || undefined, deviceId = req.body.deviceId || undefined,
displayName = req.body.displayName || undefined; displayName = req.body.displayName || undefined;
(async () => { const matrixClient = sdk.createClient({
const mod = await import("matrix-js-sdk"); baseUrl: baseUrl,
const matrixClient = mod.createClient({ deviceId: deviceId,
baseUrl: baseUrl, timelineSupport: true,
deviceId: deviceId, localTimeoutMs: '30000'
timelineSupport: true, });
localTimeoutMs: '30000'
});
matrixClient.timelineSupport = true;
matrixClient.timelineSupport = true; matrixClient.login(
'm.login.password', {
matrixClient.login('m.login.password', {
identifier: { identifier: {
type: 'm.id.user', type: 'm.id.user',
user: userId, user: userId,
@@ -512,27 +491,23 @@ module.exports = function(RED) {
password: password, password: password,
initial_device_display_name: displayName initial_device_display_name: displayName
}) })
.then( .then(
function(response) { function(response) {
res.json({ res.json({
'result': 'ok', 'result': 'ok',
'token': response.access_token, 'token': response.access_token,
'device_id': response.device_id, 'device_id': response.device_id,
'user_id': response.user_id, 'user_id': response.user_id,
}); });
}, },
function(err) { function(err) {
res.json({ res.json({
'result': 'error', 'result': 'error',
'message': err 'message': err
}); });
} }
); );
})().catch(err => { });
res.json({ result: 'error', message: err.toString() });
});
}
);
function upgradeDirectoryIfNecessary(node, storageDir) { function upgradeDirectoryIfNecessary(node, storageDir) {
let oldStorageDir = './matrix-local-storage', let oldStorageDir = './matrix-local-storage',
@@ -573,6 +548,9 @@ module.exports = function(RED) {
} }
} }
/**
* If a device ID is stored we will use that for the client
*/
function getStoredDeviceId(localStorage) { function getStoredDeviceId(localStorage) {
let deviceId = localStorage.getItem('my_device_id'); let deviceId = localStorage.getItem('my_device_id');
if(deviceId === "null" || !deviceId) { if(deviceId === "null" || !deviceId) {
@@ -588,4 +566,4 @@ module.exports = function(RED) {
localStorage.setItem('my_device_id', deviceId); localStorage.setItem('my_device_id', deviceId);
return true; return true;
} }
}; }