@kodelyth/matrix 2026.5.39 → 2026.5.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +321 -0
- package/SPEC-SUPPORT.md +116 -0
- package/api.ts +38 -0
- package/auth-presence.ts +56 -0
- package/channel-plugin-api.ts +3 -0
- package/cli-metadata.ts +11 -0
- package/contract-api.ts +17 -0
- package/dist/account-selection-Y50DNJ2l.js +158 -0
- package/dist/active-client-CmFdvPdO.js +20 -0
- package/dist/api.js +12 -0
- package/dist/approval-handler.runtime-BIi4fL0R.js +377 -0
- package/dist/approval-ids-BGHK7PnZ.js +7 -0
- package/dist/approval-reaction-auth-CL0-nCNV.js +27 -0
- package/dist/approval-reactions-nDm2x-K5.js +162 -0
- package/dist/async-lock-SsmtFXtt.js +19 -0
- package/dist/auth-presence.js +26 -0
- package/dist/backup-health-3BHbHxyd.js +60 -0
- package/dist/channel-C0kCyTNB.js +1380 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-CdrdEN-0.js +250 -0
- package/dist/cli-FtY6Nuzw.js +1338 -0
- package/dist/cli-metadata-Dkwua7CB.js +22 -0
- package/dist/cli-metadata.js +2 -0
- package/dist/client-BnohYygh.js +25 -0
- package/dist/client-PhrTwuC4.js +30 -0
- package/dist/client-bootstrap-Mcj8ChJ5.js +114 -0
- package/dist/config-paths-DVvt6vM3.js +114 -0
- package/dist/config-schema-BMGOlhdI.js +308 -0
- package/dist/config-secret-input.runtime-Dv_4Br_f.js +2 -0
- package/dist/contract-api.js +8 -0
- package/dist/create-client-J0htTaRj.js +64 -0
- package/dist/credentials-B7GsBbgQ.js +56 -0
- package/dist/credentials-read-8fE4qoWs.js +112 -0
- package/dist/credentials-write.runtime-BibplB4Y.js +17 -0
- package/dist/crypto-node.runtime-D9qxgRPa.js +12 -0
- package/dist/crypto-runtime-1pKW4O2F.js +1214 -0
- package/dist/deps-DVpDS81G.js +208 -0
- package/dist/device-health-Ct2wDSPG.js +16 -0
- package/dist/directory-live-i3T8uORc.js +150 -0
- package/dist/doctor-contract-BLzYHl_9.js +246 -0
- package/dist/doctor-contract-api.js +2 -0
- package/dist/doctor-diR5gE7D.js +153 -0
- package/dist/draft-stream-HpPJ_VJt.js +143 -0
- package/dist/encryption-guidance-BNEgckrZ.js +15 -0
- package/dist/env-auth-UFiTGkDM.js +63 -0
- package/dist/env-vars-EQKQv-FE.js +63 -0
- package/dist/errors-BETj3zr9.js +17 -0
- package/dist/exec-approval-resolver-BxPorU_t.js +15 -0
- package/dist/helper-api.js +4 -0
- package/dist/http-client-DoQgbQsU.js +331 -0
- package/dist/index.js +46 -0
- package/dist/legacy-crypto-inspector-zK0hDCbt.js +41 -0
- package/dist/legacy-crypto-restore-DSFIXuDo.js +85 -0
- package/dist/logging-Df7aPD1z.js +99 -0
- package/dist/matrix-migration.runtime-BNoT1Prt.js +525 -0
- package/dist/media-text-ZhGA8Pcs.js +146 -0
- package/dist/messages-CRA9WGg0.js +140 -0
- package/dist/migration-snapshot-backup-BR-xD7Ew.js +69 -0
- package/dist/migration-snapshot.runtime-BLcy_Nvw.js +2 -0
- package/dist/monitor-DQm7_13y.js +4331 -0
- package/dist/plugin-entry.handlers.runtime.js +51 -0
- package/dist/probe.runtime-CjJS53Kz.js +3 -0
- package/dist/profile-update-DqkPgZ1P.js +68 -0
- package/dist/reaction-common-CmVLzP-u.js +71 -0
- package/dist/reaction-events-D0nUJuZV.js +121 -0
- package/dist/record-shared-DGvSFn5M.js +2 -0
- package/dist/resolve-targets-ChECUzD2.js +140 -0
- package/dist/resolver.runtime-hdY3n0GO.js +5 -0
- package/dist/rolldown-runtime-DUslC3ob.js +14 -0
- package/dist/route-xRKj_ESW.js +161 -0
- package/dist/runtime-B-Fyrmxo.js +8 -0
- package/dist/runtime-api-BYXXkxq2.js +24 -0
- package/dist/runtime-api.js +25 -0
- package/dist/runtime-heavy-api.js +3 -0
- package/dist/runtime-lwTSy9Yt.js +6 -0
- package/dist/runtime-setter-api.js +2 -0
- package/dist/sdk-Jhq7mLtD.js +1704 -0
- package/dist/secret-contract-DEMcDsjl.js +120 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/send-CJunc6QM.js +1517 -0
- package/dist/setup-bootstrap-rJ0qZWPe.js +62 -0
- package/dist/setup-core-BEYoXF3J.js +677 -0
- package/dist/setup-entry.js +19 -0
- package/dist/setup-plugin-api.js +43 -0
- package/dist/setup-surface-c28ON6jq.js +537 -0
- package/dist/shared-D6MFMnpG.js +642 -0
- package/dist/startup-abort-B2J3MU_h.js +109 -0
- package/dist/startup-verification-CkD4Cwce.js +132 -0
- package/dist/storage-nyO0DOFE.js +281 -0
- package/dist/storage-paths-BTAketfg.js +52 -0
- package/dist/subagent-hooks-api-Dr_xnMRG.js +170 -0
- package/dist/subagent-hooks-api.js +2 -0
- package/dist/sync-state-Bx0gPaGA.js +12 -0
- package/dist/target-ids-Bsazo8si.js +77 -0
- package/dist/test-api.js +4 -0
- package/dist/thread-binding-api-IGU0-L70.js +17 -0
- package/dist/thread-binding-api.js +2 -0
- package/dist/thread-bindings-FjAZmDUP.js +352 -0
- package/dist/thread-bindings-runtime.js +2 -0
- package/dist/thread-bindings-shared-fvfP7jVs.js +97 -0
- package/dist/timeout-abort-signal-DpSHDHhR.js +2 -0
- package/dist/tool-actions.runtime-Cbo7YcYZ.js +532 -0
- package/dist/url-validation-DlrXNjAE.js +36 -0
- package/dist/verification-7tDPRpJU.js +345 -0
- package/doctor-contract-api.ts +1 -0
- package/helper-api.ts +3 -0
- package/index.ts +55 -0
- package/klaw.plugin.json +3 -891
- package/package.json +4 -4
- package/plugin-entry.handlers.runtime.ts +1 -0
- package/runtime-api.ts +72 -0
- package/runtime-heavy-api.ts +1 -0
- package/runtime-setter-api.ts +3 -0
- package/secret-contract-api.ts +5 -0
- package/setup-entry.ts +17 -0
- package/setup-plugin-api.ts +3 -0
- package/src/account-selection.ts +223 -0
- package/src/actions.ts +346 -0
- package/src/approval-auth.ts +25 -0
- package/src/approval-handler.runtime.ts +592 -0
- package/src/approval-ids.ts +6 -0
- package/src/approval-native.ts +345 -0
- package/src/approval-reaction-auth.ts +45 -0
- package/src/approval-reactions.ts +313 -0
- package/src/auth-precedence.ts +61 -0
- package/src/channel-account-paths.ts +97 -0
- package/src/channel.runtime.ts +17 -0
- package/src/channel.setup.ts +48 -0
- package/src/channel.ts +667 -0
- package/src/cli-metadata.ts +19 -0
- package/src/cli.ts +2298 -0
- package/src/config-adapter.ts +41 -0
- package/src/config-schema.ts +159 -0
- package/src/config-ui-hints.ts +56 -0
- package/src/directory-live.ts +238 -0
- package/src/doctor-contract.ts +287 -0
- package/src/doctor.ts +262 -0
- package/src/env-vars.ts +92 -0
- package/src/exec-approval-resolver.ts +23 -0
- package/src/exec-approvals.ts +287 -0
- package/src/group-mentions.ts +41 -0
- package/src/legacy-crypto-inspector-availability.ts +60 -0
- package/src/legacy-crypto.ts +531 -0
- package/src/legacy-state.ts +156 -0
- package/src/matrix/account-config.ts +175 -0
- package/src/matrix/accounts.ts +194 -0
- package/src/matrix/actions/client.ts +31 -0
- package/src/matrix/actions/devices.ts +34 -0
- package/src/matrix/actions/limits.ts +6 -0
- package/src/matrix/actions/messages.ts +129 -0
- package/src/matrix/actions/pins.ts +63 -0
- package/src/matrix/actions/polls.ts +109 -0
- package/src/matrix/actions/profile.ts +37 -0
- package/src/matrix/actions/reactions.ts +59 -0
- package/src/matrix/actions/room.ts +71 -0
- package/src/matrix/actions/summary.ts +88 -0
- package/src/matrix/actions/types.ts +63 -0
- package/src/matrix/actions/verification.ts +589 -0
- package/src/matrix/actions.ts +37 -0
- package/src/matrix/active-client.ts +26 -0
- package/src/matrix/async-lock.ts +18 -0
- package/src/matrix/backup-health.ts +124 -0
- package/src/matrix/client/config-runtime-api.ts +9 -0
- package/src/matrix/client/config-secret-input.runtime.ts +1 -0
- package/src/matrix/client/config.ts +853 -0
- package/src/matrix/client/create-client.ts +105 -0
- package/src/matrix/client/env-auth.ts +95 -0
- package/src/matrix/client/file-sync-store.ts +289 -0
- package/src/matrix/client/logging.ts +140 -0
- package/src/matrix/client/migration-snapshot.runtime.ts +1 -0
- package/src/matrix/client/private-network-host.ts +1 -0
- package/src/matrix/client/runtime.ts +4 -0
- package/src/matrix/client/shared.ts +316 -0
- package/src/matrix/client/storage.ts +543 -0
- package/src/matrix/client/types.ts +50 -0
- package/src/matrix/client/url-validation.ts +73 -0
- package/src/matrix/client-bootstrap.ts +173 -0
- package/src/matrix/client.ts +23 -0
- package/src/matrix/config-paths.ts +31 -0
- package/src/matrix/config-update.ts +292 -0
- package/src/matrix/credentials-read.ts +208 -0
- package/src/matrix/credentials-write.runtime.ts +35 -0
- package/src/matrix/credentials.ts +95 -0
- package/src/matrix/deps.ts +309 -0
- package/src/matrix/device-health.ts +29 -0
- package/src/matrix/direct-management.ts +349 -0
- package/src/matrix/direct-room.ts +128 -0
- package/src/matrix/draft-stream.ts +225 -0
- package/src/matrix/encryption-guidance.ts +24 -0
- package/src/matrix/errors.ts +21 -0
- package/src/matrix/format.ts +426 -0
- package/src/matrix/legacy-crypto-inspector.ts +95 -0
- package/src/matrix/media-errors.ts +20 -0
- package/src/matrix/media-text.ts +162 -0
- package/src/matrix/monitor/access-state.ts +145 -0
- package/src/matrix/monitor/ack-config.ts +27 -0
- package/src/matrix/monitor/allowlist.ts +89 -0
- package/src/matrix/monitor/auto-join.ts +86 -0
- package/src/matrix/monitor/config.ts +569 -0
- package/src/matrix/monitor/context-summary.ts +43 -0
- package/src/matrix/monitor/direct.ts +296 -0
- package/src/matrix/monitor/events.ts +397 -0
- package/src/matrix/monitor/handler.ts +2266 -0
- package/src/matrix/monitor/inbound-dedupe.ts +267 -0
- package/src/matrix/monitor/index.ts +540 -0
- package/src/matrix/monitor/legacy-crypto-restore.ts +139 -0
- package/src/matrix/monitor/location.ts +108 -0
- package/src/matrix/monitor/media.ts +119 -0
- package/src/matrix/monitor/mentions.ts +256 -0
- package/src/matrix/monitor/reaction-events.ts +197 -0
- package/src/matrix/monitor/recent-invite.ts +30 -0
- package/src/matrix/monitor/replies.ts +136 -0
- package/src/matrix/monitor/reply-context.ts +92 -0
- package/src/matrix/monitor/room-history.ts +301 -0
- package/src/matrix/monitor/room-info.ts +126 -0
- package/src/matrix/monitor/rooms.ts +52 -0
- package/src/matrix/monitor/route.ts +179 -0
- package/src/matrix/monitor/runtime-api.ts +28 -0
- package/src/matrix/monitor/startup-verification.ts +237 -0
- package/src/matrix/monitor/startup.ts +218 -0
- package/src/matrix/monitor/status.ts +120 -0
- package/src/matrix/monitor/sync-lifecycle.ts +91 -0
- package/src/matrix/monitor/task-runner.ts +38 -0
- package/src/matrix/monitor/test-events.ts +21 -0
- package/src/matrix/monitor/thread-context.ts +108 -0
- package/src/matrix/monitor/threads.ts +85 -0
- package/src/matrix/monitor/types.ts +30 -0
- package/src/matrix/monitor/verification-events.ts +643 -0
- package/src/matrix/monitor/verification-utils.ts +46 -0
- package/src/matrix/outbound-media-runtime.ts +1 -0
- package/src/matrix/poll-summary.ts +110 -0
- package/src/matrix/poll-types.ts +429 -0
- package/src/matrix/probe.runtime.ts +4 -0
- package/src/matrix/probe.ts +97 -0
- package/src/matrix/profile.ts +184 -0
- package/src/matrix/reaction-common.ts +147 -0
- package/src/matrix/sdk/crypto-bootstrap.ts +438 -0
- package/src/matrix/sdk/crypto-facade.ts +242 -0
- package/src/matrix/sdk/crypto-node.runtime.ts +17 -0
- package/src/matrix/sdk/crypto-runtime.ts +14 -0
- package/src/matrix/sdk/decrypt-bridge.ts +410 -0
- package/src/matrix/sdk/event-helpers.ts +83 -0
- package/src/matrix/sdk/http-client.ts +87 -0
- package/src/matrix/sdk/idb-persistence-lock.ts +51 -0
- package/src/matrix/sdk/idb-persistence.ts +288 -0
- package/src/matrix/sdk/logger.ts +108 -0
- package/src/matrix/sdk/read-response-with-limit.ts +19 -0
- package/src/matrix/sdk/recovery-key-store.ts +453 -0
- package/src/matrix/sdk/timeout-abort-signal.ts +1 -0
- package/src/matrix/sdk/transport-runtime-api.ts +18 -0
- package/src/matrix/sdk/transport.ts +352 -0
- package/src/matrix/sdk/types.ts +245 -0
- package/src/matrix/sdk/verification-manager.ts +795 -0
- package/src/matrix/sdk/verification-status.ts +23 -0
- package/src/matrix/sdk.ts +2152 -0
- package/src/matrix/send/client.ts +93 -0
- package/src/matrix/send/formatting.ts +189 -0
- package/src/matrix/send/media.ts +244 -0
- package/src/matrix/send/targets.ts +104 -0
- package/src/matrix/send/types.ts +131 -0
- package/src/matrix/send.ts +660 -0
- package/src/matrix/session-store-metadata.ts +108 -0
- package/src/matrix/startup-abort.ts +44 -0
- package/src/matrix/subagent-hooks.ts +308 -0
- package/src/matrix/sync-state.ts +27 -0
- package/src/matrix/target-ids.ts +79 -0
- package/src/matrix/thread-bindings-shared.ts +206 -0
- package/src/matrix/thread-bindings.ts +580 -0
- package/src/matrix-migration.runtime.ts +9 -0
- package/src/migration-config.ts +243 -0
- package/src/migration-snapshot-backup.ts +116 -0
- package/src/migration-snapshot.ts +53 -0
- package/src/onboarding.ts +775 -0
- package/src/outbound.ts +248 -0
- package/src/plugin-entry.runtime.js +115 -0
- package/src/plugin-entry.runtime.ts +70 -0
- package/src/profile-update.ts +71 -0
- package/src/record-shared.ts +3 -0
- package/src/resolve-targets.ts +175 -0
- package/src/resolver.runtime.ts +5 -0
- package/src/resolver.ts +21 -0
- package/src/runtime-api.ts +106 -0
- package/src/runtime.ts +13 -0
- package/src/secret-contract.ts +174 -0
- package/src/session-route.ts +126 -0
- package/src/setup-bootstrap.ts +102 -0
- package/src/setup-config.ts +222 -0
- package/src/setup-contract.ts +90 -0
- package/src/setup-core.ts +146 -0
- package/src/setup-dm-policy.ts +15 -0
- package/src/setup-surface.ts +4 -0
- package/src/startup-maintenance.ts +114 -0
- package/src/storage-paths.ts +92 -0
- package/src/thread-binding-api.ts +23 -0
- package/src/tool-actions.runtime.ts +1 -0
- package/src/tool-actions.ts +498 -0
- package/src/types.ts +257 -0
- package/subagent-hooks-api.ts +31 -0
- package/test-api.ts +21 -0
- package/thread-binding-api.ts +4 -0
- package/thread-bindings-runtime.ts +4 -0
- package/tsconfig.json +16 -0
- package/api.js +0 -7
- package/auth-presence.js +0 -7
- package/channel-plugin-api.js +0 -7
- package/cli-metadata.js +0 -7
- package/contract-api.js +0 -7
- package/doctor-contract-api.js +0 -7
- package/helper-api.js +0 -7
- package/index.js +0 -7
- package/plugin-entry.handlers.runtime.js +0 -7
- package/runtime-api.js +0 -7
- package/runtime-heavy-api.js +0 -7
- package/runtime-setter-api.js +0 -7
- package/secret-contract-api.js +0 -7
- package/setup-entry.js +0 -7
- package/setup-plugin-api.js +0 -7
- package/subagent-hooks-api.js +0 -7
- package/test-api.js +0 -7
- package/thread-binding-api.js +0 -7
- package/thread-bindings-runtime.js +0 -7
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { formatErrorMessage } from "klaw/plugin-sdk/error-runtime";
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
//#region extensions/matrix/src/matrix/deps.ts
|
|
7
|
+
const REQUIRED_MATRIX_PACKAGES = [
|
|
8
|
+
"matrix-js-sdk",
|
|
9
|
+
"@matrix-org/matrix-sdk-crypto-nodejs",
|
|
10
|
+
"@matrix-org/matrix-sdk-crypto-wasm"
|
|
11
|
+
];
|
|
12
|
+
const MIN_MATRIX_CRYPTO_NATIVE_BINDING_BYTES = 1e6;
|
|
13
|
+
function resolveMissingMatrixPackages(resolveFn) {
|
|
14
|
+
const resolve = resolveFn ?? defaultResolveFn;
|
|
15
|
+
return REQUIRED_MATRIX_PACKAGES.filter((pkg) => {
|
|
16
|
+
try {
|
|
17
|
+
resolve(pkg);
|
|
18
|
+
return false;
|
|
19
|
+
} catch {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function isMatrixSdkAvailable() {
|
|
25
|
+
return resolveMissingMatrixPackages().length === 0;
|
|
26
|
+
}
|
|
27
|
+
function buildMatrixDepsMissingMessage(missing) {
|
|
28
|
+
return [`Matrix plugin dependencies are missing: ${missing.join(", ")}.`, "Repair this plugin with `klaw plugins update matrix` or run `klaw doctor --fix`."].join(" ");
|
|
29
|
+
}
|
|
30
|
+
let defaultMatrixCryptoRuntimeEnsurePromise = null;
|
|
31
|
+
async function runFixedCommandWithTimeout(params) {
|
|
32
|
+
return await new Promise((resolve) => {
|
|
33
|
+
const [command, ...args] = params.argv;
|
|
34
|
+
if (!command) {
|
|
35
|
+
resolve({
|
|
36
|
+
code: 1,
|
|
37
|
+
stdout: "",
|
|
38
|
+
stderr: "command is required"
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const proc = spawn(command, args, {
|
|
43
|
+
cwd: params.cwd,
|
|
44
|
+
env: {
|
|
45
|
+
...process.env,
|
|
46
|
+
...params.env
|
|
47
|
+
},
|
|
48
|
+
stdio: [
|
|
49
|
+
"ignore",
|
|
50
|
+
"pipe",
|
|
51
|
+
"pipe"
|
|
52
|
+
]
|
|
53
|
+
});
|
|
54
|
+
let stdout = "";
|
|
55
|
+
let stderr = "";
|
|
56
|
+
let settled = false;
|
|
57
|
+
let timer = null;
|
|
58
|
+
const killChildOnExit = () => {
|
|
59
|
+
if (!settled && proc.exitCode === null) proc.kill("SIGTERM");
|
|
60
|
+
};
|
|
61
|
+
const finalize = (result) => {
|
|
62
|
+
if (settled) return;
|
|
63
|
+
settled = true;
|
|
64
|
+
if (timer) clearTimeout(timer);
|
|
65
|
+
process.off("exit", killChildOnExit);
|
|
66
|
+
resolve(result);
|
|
67
|
+
};
|
|
68
|
+
process.once("exit", killChildOnExit);
|
|
69
|
+
proc.stdout?.on("data", (chunk) => {
|
|
70
|
+
stdout += chunk.toString();
|
|
71
|
+
});
|
|
72
|
+
proc.stderr?.on("data", (chunk) => {
|
|
73
|
+
stderr += chunk.toString();
|
|
74
|
+
});
|
|
75
|
+
timer = setTimeout(() => {
|
|
76
|
+
proc.kill("SIGKILL");
|
|
77
|
+
finalize({
|
|
78
|
+
code: 124,
|
|
79
|
+
stdout,
|
|
80
|
+
stderr: stderr || `command timed out after ${params.timeoutMs}ms`
|
|
81
|
+
});
|
|
82
|
+
}, params.timeoutMs);
|
|
83
|
+
proc.on("error", (err) => {
|
|
84
|
+
finalize({
|
|
85
|
+
code: 1,
|
|
86
|
+
stdout,
|
|
87
|
+
stderr: err.message
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
proc.on("close", (code) => {
|
|
91
|
+
finalize({
|
|
92
|
+
code: code ?? 1,
|
|
93
|
+
stdout,
|
|
94
|
+
stderr
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function defaultRequireFn(id) {
|
|
100
|
+
return createRequire(import.meta.url)(id);
|
|
101
|
+
}
|
|
102
|
+
function defaultResolveFn(id) {
|
|
103
|
+
return createRequire(import.meta.url).resolve(id);
|
|
104
|
+
}
|
|
105
|
+
function isMissingMatrixCryptoRuntimeError(error) {
|
|
106
|
+
const message = formatErrorMessage(error);
|
|
107
|
+
return message.includes("@matrix-org/matrix-sdk-crypto-nodejs-") || message.includes("matrix-sdk-crypto-nodejs") || message.includes("download-lib.js");
|
|
108
|
+
}
|
|
109
|
+
function isMuslRuntime() {
|
|
110
|
+
try {
|
|
111
|
+
return !(process.report?.getReport?.())?.header?.glibcVersionRuntime;
|
|
112
|
+
} catch {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function resolveMatrixCryptoNativeBindingFilename() {
|
|
117
|
+
switch (process.platform) {
|
|
118
|
+
case "darwin": return process.arch === "arm64" ? "matrix-sdk-crypto.darwin-arm64.node" : process.arch === "x64" ? "matrix-sdk-crypto.darwin-x64.node" : null;
|
|
119
|
+
case "linux":
|
|
120
|
+
if (process.arch === "x64") return isMuslRuntime() ? "matrix-sdk-crypto.linux-x64-musl.node" : "matrix-sdk-crypto.linux-x64-gnu.node";
|
|
121
|
+
if (process.arch === "arm64" && !isMuslRuntime()) return "matrix-sdk-crypto.linux-arm64-gnu.node";
|
|
122
|
+
if (process.arch === "arm") return "matrix-sdk-crypto.linux-arm-gnueabihf.node";
|
|
123
|
+
if (process.arch === "s390x") return "matrix-sdk-crypto.linux-s390x-gnu.node";
|
|
124
|
+
return null;
|
|
125
|
+
case "win32": return process.arch === "x64" ? "matrix-sdk-crypto.win32-x64-msvc.node" : process.arch === "ia32" ? "matrix-sdk-crypto.win32-ia32-msvc.node" : process.arch === "arm64" ? "matrix-sdk-crypto.win32-arm64-msvc.node" : null;
|
|
126
|
+
default: return null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function resolveMatrixCryptoNativeBindingPath(resolveFn) {
|
|
130
|
+
const filename = resolveMatrixCryptoNativeBindingFilename();
|
|
131
|
+
if (!filename) return null;
|
|
132
|
+
try {
|
|
133
|
+
return path.join(path.dirname(resolveFn("@matrix-org/matrix-sdk-crypto-nodejs/download-lib.js")), filename);
|
|
134
|
+
} catch {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function removeIncompleteMatrixCryptoNativeBinding(params) {
|
|
139
|
+
const bindingPath = params.bindingPath;
|
|
140
|
+
if (!bindingPath) return;
|
|
141
|
+
try {
|
|
142
|
+
const stat = fs.statSync(bindingPath);
|
|
143
|
+
if (!stat.isFile() || stat.size >= MIN_MATRIX_CRYPTO_NATIVE_BINDING_BYTES) return;
|
|
144
|
+
fs.unlinkSync(bindingPath);
|
|
145
|
+
params.log?.(`matrix: removed incomplete native crypto runtime (${stat.size} bytes); it will be downloaded again`);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
if (error.code !== "ENOENT") throw error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async function ensureMatrixCryptoRuntime(params = {}) {
|
|
151
|
+
const usesDefaultRuntime = !params.requireFn && !params.runCommand && !params.resolveFn && !params.nodeExecutable;
|
|
152
|
+
if (usesDefaultRuntime && defaultMatrixCryptoRuntimeEnsurePromise) {
|
|
153
|
+
await defaultMatrixCryptoRuntimeEnsurePromise;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const ensurePromise = ensureMatrixCryptoRuntimeOnce(params);
|
|
157
|
+
if (!usesDefaultRuntime) {
|
|
158
|
+
await ensurePromise;
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
defaultMatrixCryptoRuntimeEnsurePromise = ensurePromise.catch((error) => {
|
|
162
|
+
defaultMatrixCryptoRuntimeEnsurePromise = null;
|
|
163
|
+
throw error;
|
|
164
|
+
});
|
|
165
|
+
await defaultMatrixCryptoRuntimeEnsurePromise;
|
|
166
|
+
}
|
|
167
|
+
async function ensureMatrixCryptoRuntimeOnce(params) {
|
|
168
|
+
const resolveFn = params.resolveFn ?? defaultResolveFn;
|
|
169
|
+
const nativeBindingPath = resolveMatrixCryptoNativeBindingPath(resolveFn);
|
|
170
|
+
removeIncompleteMatrixCryptoNativeBinding({
|
|
171
|
+
bindingPath: nativeBindingPath,
|
|
172
|
+
log: params.log
|
|
173
|
+
});
|
|
174
|
+
const requireFn = params.requireFn ?? defaultRequireFn;
|
|
175
|
+
try {
|
|
176
|
+
requireFn("@matrix-org/matrix-sdk-crypto-nodejs");
|
|
177
|
+
return;
|
|
178
|
+
} catch (err) {
|
|
179
|
+
if (!isMissingMatrixCryptoRuntimeError(err)) throw err;
|
|
180
|
+
}
|
|
181
|
+
const scriptPath = resolveFn("@matrix-org/matrix-sdk-crypto-nodejs/download-lib.js");
|
|
182
|
+
params.log?.("matrix: bootstrapping native crypto runtime");
|
|
183
|
+
const result = await (params.runCommand ?? runFixedCommandWithTimeout)({
|
|
184
|
+
argv: [params.nodeExecutable ?? process.execPath, scriptPath],
|
|
185
|
+
cwd: path.dirname(scriptPath),
|
|
186
|
+
timeoutMs: 3e5,
|
|
187
|
+
env: { COREPACK_ENABLE_DOWNLOAD_PROMPT: "0" }
|
|
188
|
+
});
|
|
189
|
+
if (result.code !== 0) {
|
|
190
|
+
removeIncompleteMatrixCryptoNativeBinding({
|
|
191
|
+
bindingPath: nativeBindingPath,
|
|
192
|
+
log: params.log
|
|
193
|
+
});
|
|
194
|
+
throw new Error(result.stderr.trim() || result.stdout.trim() || "Matrix crypto runtime bootstrap failed.");
|
|
195
|
+
}
|
|
196
|
+
removeIncompleteMatrixCryptoNativeBinding({
|
|
197
|
+
bindingPath: nativeBindingPath,
|
|
198
|
+
log: params.log
|
|
199
|
+
});
|
|
200
|
+
requireFn("@matrix-org/matrix-sdk-crypto-nodejs");
|
|
201
|
+
}
|
|
202
|
+
async function ensureMatrixSdkInstalled(params) {
|
|
203
|
+
const missing = resolveMissingMatrixPackages(params?.resolveFn);
|
|
204
|
+
if (missing.length === 0) return;
|
|
205
|
+
throw new Error(buildMatrixDepsMissingMessage(missing));
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
208
|
+
export { ensureMatrixSdkInstalled as n, isMatrixSdkAvailable as r, ensureMatrixCryptoRuntime as t };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region extensions/matrix/src/matrix/device-health.ts
|
|
2
|
+
const KLAW_DEVICE_NAME_PREFIX = "Klaw ";
|
|
3
|
+
function isKlawManagedMatrixDevice(displayName) {
|
|
4
|
+
return displayName?.startsWith(KLAW_DEVICE_NAME_PREFIX) === true;
|
|
5
|
+
}
|
|
6
|
+
function summarizeMatrixDeviceHealth(devices) {
|
|
7
|
+
const currentDeviceId = devices.find((device) => device.current)?.deviceId ?? null;
|
|
8
|
+
const openClawDevices = devices.filter((device) => isKlawManagedMatrixDevice(device.displayName));
|
|
9
|
+
return {
|
|
10
|
+
currentDeviceId,
|
|
11
|
+
staleKlawDevices: openClawDevices.filter((device) => !device.current),
|
|
12
|
+
currentKlawDevices: openClawDevices.filter((device) => device.current)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { isKlawManagedMatrixDevice, summarizeMatrixDeviceHealth };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
|
|
2
|
+
import { n as normalizeMatrixMessagingTarget, t as isMatrixQualifiedUserId } from "./target-ids-Bsazo8si.js";
|
|
3
|
+
import { t as MatrixAuthedHttpClient } from "./http-client-DoQgbQsU.js";
|
|
4
|
+
import { l as resolveMatrixAuth } from "./shared-D6MFMnpG.js";
|
|
5
|
+
import "./client-PhrTwuC4.js";
|
|
6
|
+
import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "klaw/plugin-sdk/string-coerce-runtime";
|
|
7
|
+
//#region extensions/matrix/src/directory-live.ts
|
|
8
|
+
var directory_live_exports = /* @__PURE__ */ __exportAll({
|
|
9
|
+
listMatrixDirectoryGroupsLive: () => listMatrixDirectoryGroupsLive,
|
|
10
|
+
listMatrixDirectoryPeersLive: () => listMatrixDirectoryPeersLive
|
|
11
|
+
});
|
|
12
|
+
const MATRIX_DIRECTORY_TIMEOUT_MS = 1e4;
|
|
13
|
+
function resolveMatrixDirectoryLimit(limit) {
|
|
14
|
+
return typeof limit === "number" && Number.isFinite(limit) && limit > 0 ? Math.max(1, Math.floor(limit)) : 20;
|
|
15
|
+
}
|
|
16
|
+
function createMatrixDirectoryClient(auth) {
|
|
17
|
+
return new MatrixAuthedHttpClient({
|
|
18
|
+
homeserver: auth.homeserver,
|
|
19
|
+
accessToken: auth.accessToken,
|
|
20
|
+
ssrfPolicy: auth.ssrfPolicy,
|
|
21
|
+
dispatcherPolicy: auth.dispatcherPolicy
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async function resolveMatrixDirectoryContext(params) {
|
|
25
|
+
const query = normalizeOptionalString(params.query) ?? "";
|
|
26
|
+
if (!query) return null;
|
|
27
|
+
const auth = await resolveMatrixAuth({
|
|
28
|
+
cfg: params.cfg,
|
|
29
|
+
accountId: params.accountId
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
auth,
|
|
33
|
+
client: createMatrixDirectoryClient(auth),
|
|
34
|
+
query,
|
|
35
|
+
queryLower: normalizeLowercaseStringOrEmpty(query)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function createGroupDirectoryEntry(params) {
|
|
39
|
+
return {
|
|
40
|
+
kind: "group",
|
|
41
|
+
id: params.id,
|
|
42
|
+
name: params.name,
|
|
43
|
+
handle: params.handle
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async function requestMatrixJson(client, params) {
|
|
47
|
+
return await client.requestJson({
|
|
48
|
+
method: params.method,
|
|
49
|
+
endpoint: params.endpoint,
|
|
50
|
+
body: params.body,
|
|
51
|
+
timeoutMs: MATRIX_DIRECTORY_TIMEOUT_MS
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async function listMatrixDirectoryPeersLive(params) {
|
|
55
|
+
const query = normalizeOptionalString(params.query) ?? "";
|
|
56
|
+
if (!query) return [];
|
|
57
|
+
const directUserId = normalizeMatrixMessagingTarget(query);
|
|
58
|
+
if (directUserId && isMatrixQualifiedUserId(directUserId)) return [{
|
|
59
|
+
kind: "user",
|
|
60
|
+
id: directUserId
|
|
61
|
+
}];
|
|
62
|
+
const context = await resolveMatrixDirectoryContext({
|
|
63
|
+
...params,
|
|
64
|
+
query
|
|
65
|
+
});
|
|
66
|
+
if (!context) return [];
|
|
67
|
+
return ((await requestMatrixJson(context.client, {
|
|
68
|
+
method: "POST",
|
|
69
|
+
endpoint: "/_matrix/client/v3/user_directory/search",
|
|
70
|
+
body: {
|
|
71
|
+
search_term: context.query,
|
|
72
|
+
limit: resolveMatrixDirectoryLimit(params.limit)
|
|
73
|
+
}
|
|
74
|
+
})).results ?? []).map((entry) => {
|
|
75
|
+
const userId = normalizeOptionalString(entry.user_id);
|
|
76
|
+
if (!userId) return null;
|
|
77
|
+
const displayName = normalizeOptionalString(entry.display_name);
|
|
78
|
+
return {
|
|
79
|
+
kind: "user",
|
|
80
|
+
id: userId,
|
|
81
|
+
name: displayName,
|
|
82
|
+
handle: displayName ? `@${displayName}` : void 0,
|
|
83
|
+
raw: entry
|
|
84
|
+
};
|
|
85
|
+
}).filter(Boolean);
|
|
86
|
+
}
|
|
87
|
+
async function resolveMatrixRoomAlias(client, alias) {
|
|
88
|
+
try {
|
|
89
|
+
return normalizeOptionalString((await requestMatrixJson(client, {
|
|
90
|
+
method: "GET",
|
|
91
|
+
endpoint: `/_matrix/client/v3/directory/room/${encodeURIComponent(alias)}`
|
|
92
|
+
})).room_id) ?? null;
|
|
93
|
+
} catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async function fetchMatrixRoomName(client, roomId) {
|
|
98
|
+
try {
|
|
99
|
+
return normalizeOptionalString((await requestMatrixJson(client, {
|
|
100
|
+
method: "GET",
|
|
101
|
+
endpoint: `/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/state/m.room.name`
|
|
102
|
+
})).name) ?? null;
|
|
103
|
+
} catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function listMatrixDirectoryGroupsLive(params) {
|
|
108
|
+
const query = normalizeOptionalString(params.query) ?? "";
|
|
109
|
+
if (!query) return [];
|
|
110
|
+
const directTarget = normalizeMatrixMessagingTarget(query);
|
|
111
|
+
if (directTarget?.startsWith("!")) return [createGroupDirectoryEntry({
|
|
112
|
+
id: directTarget,
|
|
113
|
+
name: directTarget
|
|
114
|
+
})];
|
|
115
|
+
const context = await resolveMatrixDirectoryContext({
|
|
116
|
+
...params,
|
|
117
|
+
query
|
|
118
|
+
});
|
|
119
|
+
if (!context) return [];
|
|
120
|
+
const { client, queryLower } = context;
|
|
121
|
+
const limit = resolveMatrixDirectoryLimit(params.limit);
|
|
122
|
+
if (directTarget?.startsWith("#")) {
|
|
123
|
+
const roomId = await resolveMatrixRoomAlias(client, directTarget);
|
|
124
|
+
if (!roomId) return [];
|
|
125
|
+
return [createGroupDirectoryEntry({
|
|
126
|
+
id: roomId,
|
|
127
|
+
name: directTarget,
|
|
128
|
+
handle: directTarget
|
|
129
|
+
})];
|
|
130
|
+
}
|
|
131
|
+
const rooms = ((await requestMatrixJson(client, {
|
|
132
|
+
method: "GET",
|
|
133
|
+
endpoint: "/_matrix/client/v3/joined_rooms"
|
|
134
|
+
})).joined_rooms ?? []).map((roomId) => normalizeOptionalString(roomId)).filter((roomId) => Boolean(roomId));
|
|
135
|
+
const results = [];
|
|
136
|
+
for (const roomId of rooms) {
|
|
137
|
+
const name = await fetchMatrixRoomName(client, roomId);
|
|
138
|
+
if (!name || !normalizeLowercaseStringOrEmpty(name).includes(queryLower)) continue;
|
|
139
|
+
results.push({
|
|
140
|
+
kind: "group",
|
|
141
|
+
id: roomId,
|
|
142
|
+
name,
|
|
143
|
+
handle: `#${name}`
|
|
144
|
+
});
|
|
145
|
+
if (results.length >= limit) break;
|
|
146
|
+
}
|
|
147
|
+
return results;
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
export { listMatrixDirectoryGroupsLive as n, listMatrixDirectoryPeersLive as r, directory_live_exports as t };
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { t as isRecord } from "./record-shared-DGvSFn5M.js";
|
|
2
|
+
import { hasLegacyFlatAllowPrivateNetworkAlias, migrateLegacyFlatAllowPrivateNetworkAlias } from "klaw/plugin-sdk/ssrf-runtime";
|
|
3
|
+
//#region extensions/matrix/src/doctor-contract.ts
|
|
4
|
+
function hasLegacyMatrixRoomAllowAlias(value) {
|
|
5
|
+
const room = isRecord(value) ? value : null;
|
|
6
|
+
return Boolean(room && typeof room.allow === "boolean");
|
|
7
|
+
}
|
|
8
|
+
function hasLegacyMatrixRoomMapAllowAliases(value) {
|
|
9
|
+
const rooms = isRecord(value) ? value : null;
|
|
10
|
+
return Boolean(rooms && Object.values(rooms).some((room) => hasLegacyMatrixRoomAllowAlias(room)));
|
|
11
|
+
}
|
|
12
|
+
function hasLegacyMatrixAccountRoomAllowAliases(value) {
|
|
13
|
+
const accounts = isRecord(value) ? value : null;
|
|
14
|
+
if (!accounts) return false;
|
|
15
|
+
return Object.values(accounts).some((account) => {
|
|
16
|
+
if (!isRecord(account)) return false;
|
|
17
|
+
return hasLegacyMatrixRoomMapAllowAliases(account.groups) || hasLegacyMatrixRoomMapAllowAliases(account.rooms);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function hasLegacyMatrixAccountPrivateNetworkAliases(value) {
|
|
21
|
+
const accounts = isRecord(value) ? value : null;
|
|
22
|
+
if (!accounts) return false;
|
|
23
|
+
return Object.values(accounts).some((account) => hasLegacyFlatAllowPrivateNetworkAlias(isRecord(account) ? account : {}));
|
|
24
|
+
}
|
|
25
|
+
function hasLegacyTrustedDmPolicy(value) {
|
|
26
|
+
const root = isRecord(value) ? value : null;
|
|
27
|
+
if (!root) return false;
|
|
28
|
+
return (isRecord(root.dm) ? root.dm : null)?.policy === "trusted";
|
|
29
|
+
}
|
|
30
|
+
function hasLegacyMatrixAccountTrustedDmPolicies(value) {
|
|
31
|
+
const accounts = isRecord(value) ? value : null;
|
|
32
|
+
if (!accounts) return false;
|
|
33
|
+
return Object.values(accounts).some((account) => hasLegacyTrustedDmPolicy(account));
|
|
34
|
+
}
|
|
35
|
+
function migrateLegacyTrustedDmPolicy(params) {
|
|
36
|
+
const dm = isRecord(params.entry.dm) ? params.entry.dm : null;
|
|
37
|
+
if (!dm || dm.policy !== "trusted") return {
|
|
38
|
+
entry: params.entry,
|
|
39
|
+
changed: false
|
|
40
|
+
};
|
|
41
|
+
const allowFromRaw = dm.allowFrom;
|
|
42
|
+
const allowFromEntries = Array.isArray(allowFromRaw) ? allowFromRaw.filter((entry) => typeof entry === "string" && entry.trim().length > 0).length : 0;
|
|
43
|
+
const nextPolicy = allowFromEntries > 0 ? "allowlist" : "pairing";
|
|
44
|
+
const nextDm = {
|
|
45
|
+
...dm,
|
|
46
|
+
policy: nextPolicy
|
|
47
|
+
};
|
|
48
|
+
params.changes.push(`Migrated ${params.pathPrefix}.dm.policy "trusted" → "${nextPolicy}" (legacy alias removed; ${allowFromEntries > 0 ? `preserved ${allowFromEntries} ${params.pathPrefix}.dm.allowFrom ${allowFromEntries === 1 ? "entry" : "entries"}` : "no allowFrom entries present, defaulting to pairing for safety"}).`);
|
|
49
|
+
return {
|
|
50
|
+
entry: {
|
|
51
|
+
...params.entry,
|
|
52
|
+
dm: nextDm
|
|
53
|
+
},
|
|
54
|
+
changed: true
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function normalizeMatrixRoomAllowAliases(params) {
|
|
58
|
+
let changed = false;
|
|
59
|
+
const nextRooms = { ...params.rooms };
|
|
60
|
+
for (const [roomId, roomValue] of Object.entries(params.rooms)) {
|
|
61
|
+
const room = isRecord(roomValue) ? roomValue : null;
|
|
62
|
+
if (!room || typeof room.allow !== "boolean") continue;
|
|
63
|
+
const nextRoom = { ...room };
|
|
64
|
+
if (typeof nextRoom.enabled !== "boolean") nextRoom.enabled = room.allow;
|
|
65
|
+
delete nextRoom.allow;
|
|
66
|
+
nextRooms[roomId] = nextRoom;
|
|
67
|
+
changed = true;
|
|
68
|
+
params.changes.push(`Moved ${params.pathPrefix}.${roomId}.allow → ${params.pathPrefix}.${roomId}.enabled (${String(nextRoom.enabled)}).`);
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
rooms: nextRooms,
|
|
72
|
+
changed
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const legacyConfigRules = [
|
|
76
|
+
{
|
|
77
|
+
path: ["channels", "matrix"],
|
|
78
|
+
message: "channels.matrix.allowPrivateNetwork is legacy; use channels.matrix.network.dangerouslyAllowPrivateNetwork instead. Run \"klaw doctor --fix\".",
|
|
79
|
+
match: (value) => hasLegacyFlatAllowPrivateNetworkAlias(isRecord(value) ? value : {})
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
path: [
|
|
83
|
+
"channels",
|
|
84
|
+
"matrix",
|
|
85
|
+
"accounts"
|
|
86
|
+
],
|
|
87
|
+
message: "channels.matrix.accounts.<id>.allowPrivateNetwork is legacy; use channels.matrix.accounts.<id>.network.dangerouslyAllowPrivateNetwork instead. Run \"klaw doctor --fix\".",
|
|
88
|
+
match: hasLegacyMatrixAccountPrivateNetworkAliases
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
path: [
|
|
92
|
+
"channels",
|
|
93
|
+
"matrix",
|
|
94
|
+
"groups"
|
|
95
|
+
],
|
|
96
|
+
message: "channels.matrix.groups.<room>.allow is legacy; use channels.matrix.groups.<room>.enabled instead. Run \"klaw doctor --fix\".",
|
|
97
|
+
match: hasLegacyMatrixRoomMapAllowAliases
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
path: [
|
|
101
|
+
"channels",
|
|
102
|
+
"matrix",
|
|
103
|
+
"rooms"
|
|
104
|
+
],
|
|
105
|
+
message: "channels.matrix.rooms.<room>.allow is legacy; use channels.matrix.rooms.<room>.enabled instead. Run \"klaw doctor --fix\".",
|
|
106
|
+
match: hasLegacyMatrixRoomMapAllowAliases
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
path: [
|
|
110
|
+
"channels",
|
|
111
|
+
"matrix",
|
|
112
|
+
"accounts"
|
|
113
|
+
],
|
|
114
|
+
message: "channels.matrix.accounts.<id>.{groups,rooms}.<room>.allow is legacy; use channels.matrix.accounts.<id>.{groups,rooms}.<room>.enabled instead. Run \"klaw doctor --fix\".",
|
|
115
|
+
match: hasLegacyMatrixAccountRoomAllowAliases
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
path: ["channels", "matrix"],
|
|
119
|
+
message: "channels.matrix.dm.policy \"trusted\" is legacy; use \"allowlist\" (with allowFrom entries) or \"pairing\" instead. Run \"klaw doctor --fix\".",
|
|
120
|
+
match: hasLegacyTrustedDmPolicy
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
path: [
|
|
124
|
+
"channels",
|
|
125
|
+
"matrix",
|
|
126
|
+
"accounts"
|
|
127
|
+
],
|
|
128
|
+
message: "channels.matrix.accounts.<id>.dm.policy \"trusted\" is legacy; use \"allowlist\" (with allowFrom entries) or \"pairing\" instead. Run \"klaw doctor --fix\".",
|
|
129
|
+
match: hasLegacyMatrixAccountTrustedDmPolicies
|
|
130
|
+
}
|
|
131
|
+
];
|
|
132
|
+
function normalizeCompatibilityConfig({ cfg }) {
|
|
133
|
+
const channels = isRecord(cfg.channels) ? cfg.channels : null;
|
|
134
|
+
const matrix = isRecord(channels?.matrix) ? channels.matrix : null;
|
|
135
|
+
if (!matrix) return {
|
|
136
|
+
config: cfg,
|
|
137
|
+
changes: []
|
|
138
|
+
};
|
|
139
|
+
const changes = [];
|
|
140
|
+
let updatedMatrix = matrix;
|
|
141
|
+
let changed = false;
|
|
142
|
+
const topLevelPrivateNetwork = migrateLegacyFlatAllowPrivateNetworkAlias({
|
|
143
|
+
entry: updatedMatrix,
|
|
144
|
+
pathPrefix: "channels.matrix",
|
|
145
|
+
changes
|
|
146
|
+
});
|
|
147
|
+
updatedMatrix = topLevelPrivateNetwork.entry;
|
|
148
|
+
changed = changed || topLevelPrivateNetwork.changed;
|
|
149
|
+
const topLevelTrustedDmPolicy = migrateLegacyTrustedDmPolicy({
|
|
150
|
+
entry: updatedMatrix,
|
|
151
|
+
pathPrefix: "channels.matrix",
|
|
152
|
+
changes
|
|
153
|
+
});
|
|
154
|
+
updatedMatrix = topLevelTrustedDmPolicy.entry;
|
|
155
|
+
changed = changed || topLevelTrustedDmPolicy.changed;
|
|
156
|
+
const normalizeTopLevelRoomScope = (key) => {
|
|
157
|
+
const rooms = isRecord(updatedMatrix[key]) ? updatedMatrix[key] : null;
|
|
158
|
+
if (!rooms) return;
|
|
159
|
+
const normalized = normalizeMatrixRoomAllowAliases({
|
|
160
|
+
rooms,
|
|
161
|
+
pathPrefix: `channels.matrix.${key}`,
|
|
162
|
+
changes
|
|
163
|
+
});
|
|
164
|
+
if (normalized.changed) {
|
|
165
|
+
updatedMatrix = {
|
|
166
|
+
...updatedMatrix,
|
|
167
|
+
[key]: normalized.rooms
|
|
168
|
+
};
|
|
169
|
+
changed = true;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
normalizeTopLevelRoomScope("groups");
|
|
173
|
+
normalizeTopLevelRoomScope("rooms");
|
|
174
|
+
const accounts = isRecord(updatedMatrix.accounts) ? updatedMatrix.accounts : null;
|
|
175
|
+
if (accounts) {
|
|
176
|
+
let accountsChanged = false;
|
|
177
|
+
const nextAccounts = { ...accounts };
|
|
178
|
+
for (const [accountId, accountValue] of Object.entries(accounts)) {
|
|
179
|
+
const account = isRecord(accountValue) ? accountValue : null;
|
|
180
|
+
if (!account) continue;
|
|
181
|
+
let nextAccount = account;
|
|
182
|
+
let accountChanged = false;
|
|
183
|
+
const privateNetworkMigration = migrateLegacyFlatAllowPrivateNetworkAlias({
|
|
184
|
+
entry: nextAccount,
|
|
185
|
+
pathPrefix: `channels.matrix.accounts.${accountId}`,
|
|
186
|
+
changes
|
|
187
|
+
});
|
|
188
|
+
if (privateNetworkMigration.changed) {
|
|
189
|
+
nextAccount = privateNetworkMigration.entry;
|
|
190
|
+
accountChanged = true;
|
|
191
|
+
}
|
|
192
|
+
const accountTrustedDmPolicy = migrateLegacyTrustedDmPolicy({
|
|
193
|
+
entry: nextAccount,
|
|
194
|
+
pathPrefix: `channels.matrix.accounts.${accountId}`,
|
|
195
|
+
changes
|
|
196
|
+
});
|
|
197
|
+
if (accountTrustedDmPolicy.changed) {
|
|
198
|
+
nextAccount = accountTrustedDmPolicy.entry;
|
|
199
|
+
accountChanged = true;
|
|
200
|
+
}
|
|
201
|
+
for (const key of ["groups", "rooms"]) {
|
|
202
|
+
const rooms = isRecord(nextAccount[key]) ? nextAccount[key] : null;
|
|
203
|
+
if (!rooms) continue;
|
|
204
|
+
const normalized = normalizeMatrixRoomAllowAliases({
|
|
205
|
+
rooms,
|
|
206
|
+
pathPrefix: `channels.matrix.accounts.${accountId}.${key}`,
|
|
207
|
+
changes
|
|
208
|
+
});
|
|
209
|
+
if (normalized.changed) {
|
|
210
|
+
nextAccount = {
|
|
211
|
+
...nextAccount,
|
|
212
|
+
[key]: normalized.rooms
|
|
213
|
+
};
|
|
214
|
+
accountChanged = true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (accountChanged) {
|
|
218
|
+
nextAccounts[accountId] = nextAccount;
|
|
219
|
+
accountsChanged = true;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (accountsChanged) {
|
|
223
|
+
updatedMatrix = {
|
|
224
|
+
...updatedMatrix,
|
|
225
|
+
accounts: nextAccounts
|
|
226
|
+
};
|
|
227
|
+
changed = true;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (!changed) return {
|
|
231
|
+
config: cfg,
|
|
232
|
+
changes: []
|
|
233
|
+
};
|
|
234
|
+
return {
|
|
235
|
+
config: {
|
|
236
|
+
...cfg,
|
|
237
|
+
channels: {
|
|
238
|
+
...cfg.channels,
|
|
239
|
+
matrix: updatedMatrix
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
changes
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
//#endregion
|
|
246
|
+
export { normalizeCompatibilityConfig as n, legacyConfigRules as t };
|