@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,64 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
|
|
2
|
+
import { t as resolveValidatedMatrixHomeserverUrl } from "./url-validation-DlrXNjAE.js";
|
|
3
|
+
import { a as resolveMatrixStoragePaths, n as maybeMigrateLegacyStorage, o as writeStorageMeta } from "./storage-nyO0DOFE.js";
|
|
4
|
+
import "./shared-D6MFMnpG.js";
|
|
5
|
+
import { normalizeOptionalString } from "klaw/plugin-sdk/string-coerce-runtime";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import { ssrfPolicyFromDangerouslyAllowPrivateNetwork } from "klaw/plugin-sdk/ssrf-runtime";
|
|
8
|
+
//#region extensions/matrix/src/matrix/client/create-client.ts
|
|
9
|
+
var create_client_exports = /* @__PURE__ */ __exportAll({ createMatrixClient: () => createMatrixClient });
|
|
10
|
+
let matrixCreateClientRuntimeDepsPromise;
|
|
11
|
+
async function loadMatrixCreateClientRuntimeDeps() {
|
|
12
|
+
matrixCreateClientRuntimeDepsPromise ??= Promise.all([import("./sdk-Jhq7mLtD.js").then((n) => n.n), import("./logging-Df7aPD1z.js").then((n) => n.n)]).then(([sdkModule, loggingModule]) => ({
|
|
13
|
+
MatrixClient: sdkModule.MatrixClient,
|
|
14
|
+
ensureMatrixSdkLoggingConfigured: loggingModule.ensureMatrixSdkLoggingConfigured
|
|
15
|
+
}));
|
|
16
|
+
return await matrixCreateClientRuntimeDepsPromise;
|
|
17
|
+
}
|
|
18
|
+
async function createMatrixClient(params) {
|
|
19
|
+
const { MatrixClient, ensureMatrixSdkLoggingConfigured } = await loadMatrixCreateClientRuntimeDeps();
|
|
20
|
+
ensureMatrixSdkLoggingConfigured();
|
|
21
|
+
const homeserver = await resolveValidatedMatrixHomeserverUrl(params.homeserver, { dangerouslyAllowPrivateNetwork: params.allowPrivateNetwork });
|
|
22
|
+
const matrixClientUserId = normalizeOptionalString(params.userId);
|
|
23
|
+
const userId = matrixClientUserId ?? "unknown";
|
|
24
|
+
const storagePaths = params.persistStorage !== false ? resolveMatrixStoragePaths({
|
|
25
|
+
homeserver,
|
|
26
|
+
userId,
|
|
27
|
+
accessToken: params.accessToken,
|
|
28
|
+
accountId: params.accountId,
|
|
29
|
+
deviceId: params.deviceId,
|
|
30
|
+
env: process.env
|
|
31
|
+
}) : null;
|
|
32
|
+
if (storagePaths) {
|
|
33
|
+
await maybeMigrateLegacyStorage({
|
|
34
|
+
storagePaths,
|
|
35
|
+
env: process.env
|
|
36
|
+
});
|
|
37
|
+
fs.mkdirSync(storagePaths.rootDir, { recursive: true });
|
|
38
|
+
writeStorageMeta({
|
|
39
|
+
storagePaths,
|
|
40
|
+
homeserver,
|
|
41
|
+
userId,
|
|
42
|
+
accountId: params.accountId,
|
|
43
|
+
deviceId: params.deviceId
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const cryptoDatabasePrefix = storagePaths ? `klaw-matrix-${storagePaths.accountKey}-${storagePaths.tokenHash}` : void 0;
|
|
47
|
+
return new MatrixClient(homeserver, params.accessToken, {
|
|
48
|
+
userId: matrixClientUserId,
|
|
49
|
+
password: params.password,
|
|
50
|
+
deviceId: params.deviceId,
|
|
51
|
+
encryption: params.encryption,
|
|
52
|
+
localTimeoutMs: params.localTimeoutMs,
|
|
53
|
+
initialSyncLimit: params.initialSyncLimit,
|
|
54
|
+
storagePath: storagePaths?.storagePath,
|
|
55
|
+
recoveryKeyPath: storagePaths?.recoveryKeyPath,
|
|
56
|
+
idbSnapshotPath: storagePaths?.idbSnapshotPath,
|
|
57
|
+
cryptoDatabasePrefix,
|
|
58
|
+
autoBootstrapCrypto: params.autoBootstrapCrypto,
|
|
59
|
+
ssrfPolicy: params.ssrfPolicy ?? ssrfPolicyFromDangerouslyAllowPrivateNetwork(params.allowPrivateNetwork),
|
|
60
|
+
dispatcherPolicy: params.dispatcherPolicy
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { create_client_exports as n, createMatrixClient as t };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { a as resolveMatrixCredentialsDir, i as loadMatrixCredentials, n as credentialsMatchConfig, o as resolveMatrixCredentialsPath, t as clearMatrixCredentials } from "./credentials-read-8fE4qoWs.js";
|
|
2
|
+
import { t as createAsyncLock } from "./async-lock-SsmtFXtt.js";
|
|
3
|
+
import { writeJsonFileAtomically } from "klaw/plugin-sdk/json-store";
|
|
4
|
+
//#region extensions/matrix/src/matrix/credentials.ts
|
|
5
|
+
const credentialWriteLocks = /* @__PURE__ */ new Map();
|
|
6
|
+
function withCredentialWriteLock(credPath, fn) {
|
|
7
|
+
let withLock = credentialWriteLocks.get(credPath);
|
|
8
|
+
if (!withLock) {
|
|
9
|
+
withLock = createAsyncLock();
|
|
10
|
+
credentialWriteLocks.set(credPath, withLock);
|
|
11
|
+
}
|
|
12
|
+
return withLock(fn);
|
|
13
|
+
}
|
|
14
|
+
async function writeMatrixCredentialsUnlocked(params) {
|
|
15
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
16
|
+
const toSave = {
|
|
17
|
+
...params.credentials,
|
|
18
|
+
createdAt: params.existing?.createdAt ?? now,
|
|
19
|
+
lastUsedAt: now
|
|
20
|
+
};
|
|
21
|
+
await writeJsonFileAtomically(params.credPath, toSave);
|
|
22
|
+
}
|
|
23
|
+
async function saveMatrixCredentials(credentials, env = process.env, accountId) {
|
|
24
|
+
const credPath = resolveMatrixCredentialsPath(env, accountId);
|
|
25
|
+
await withCredentialWriteLock(credPath, async () => {
|
|
26
|
+
await writeMatrixCredentialsUnlocked({
|
|
27
|
+
credPath,
|
|
28
|
+
credentials,
|
|
29
|
+
existing: loadMatrixCredentials(env, accountId)
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async function saveBackfilledMatrixDeviceId(credentials, env = process.env, accountId) {
|
|
34
|
+
const credPath = resolveMatrixCredentialsPath(env, accountId);
|
|
35
|
+
return await withCredentialWriteLock(credPath, async () => {
|
|
36
|
+
const existing = loadMatrixCredentials(env, accountId);
|
|
37
|
+
if (existing && (existing.homeserver !== credentials.homeserver || existing.userId !== credentials.userId || existing.accessToken !== credentials.accessToken)) return "skipped";
|
|
38
|
+
await writeMatrixCredentialsUnlocked({
|
|
39
|
+
credPath,
|
|
40
|
+
credentials,
|
|
41
|
+
existing
|
|
42
|
+
});
|
|
43
|
+
return "saved";
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async function touchMatrixCredentials(env = process.env, accountId) {
|
|
47
|
+
const credPath = resolveMatrixCredentialsPath(env, accountId);
|
|
48
|
+
await withCredentialWriteLock(credPath, async () => {
|
|
49
|
+
const existing = loadMatrixCredentials(env, accountId);
|
|
50
|
+
if (!existing) return;
|
|
51
|
+
existing.lastUsedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
52
|
+
await writeJsonFileAtomically(credPath, existing);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { clearMatrixCredentials, credentialsMatchConfig, loadMatrixCredentials, resolveMatrixCredentialsDir, resolveMatrixCredentialsPath, saveBackfilledMatrixDeviceId, saveMatrixCredentials, touchMatrixCredentials };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
|
|
2
|
+
import { a as resolveMatrixDefaultOrOnlyAccountId, n as requiresExplicitMatrixDefaultAccount } from "./account-selection-Y50DNJ2l.js";
|
|
3
|
+
import { t as getMatrixRuntime } from "./runtime-B-Fyrmxo.js";
|
|
4
|
+
import { a as resolveMatrixCredentialsPath$1, r as resolveMatrixCredentialsDir$1 } from "./storage-paths-BTAketfg.js";
|
|
5
|
+
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "klaw/plugin-sdk/account-id";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import os from "node:os";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
//#region extensions/matrix/src/matrix/credentials-read.ts
|
|
10
|
+
var credentials_read_exports = /* @__PURE__ */ __exportAll({
|
|
11
|
+
clearMatrixCredentials: () => clearMatrixCredentials,
|
|
12
|
+
credentialsMatchConfig: () => credentialsMatchConfig,
|
|
13
|
+
loadMatrixCredentials: () => loadMatrixCredentials,
|
|
14
|
+
resolveMatrixCredentialsDir: () => resolveMatrixCredentialsDir,
|
|
15
|
+
resolveMatrixCredentialsPath: () => resolveMatrixCredentialsPath
|
|
16
|
+
});
|
|
17
|
+
function resolveStateDir(env) {
|
|
18
|
+
try {
|
|
19
|
+
return getMatrixRuntime().state.resolveStateDir(env, os.homedir);
|
|
20
|
+
} catch {
|
|
21
|
+
const override = (env.KLAW_STATE_DIR ?? env.KLAW_STATE_DIR)?.trim();
|
|
22
|
+
if (override) return path.resolve(override);
|
|
23
|
+
const homeDir = env.KLAW_HOME?.trim() || env.KLAW_HOME?.trim() || env.HOME?.trim() || os.homedir();
|
|
24
|
+
return path.join(homeDir, ".klaw");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function resolveLegacyMatrixCredentialsPath(env) {
|
|
28
|
+
return path.join(resolveMatrixCredentialsDir(env), "credentials.json");
|
|
29
|
+
}
|
|
30
|
+
function shouldReadLegacyCredentialsForAccount(accountId) {
|
|
31
|
+
const normalizedAccountId = normalizeAccountId(accountId);
|
|
32
|
+
const cfg = getMatrixRuntime().config.current();
|
|
33
|
+
if (!cfg.channels?.matrix || typeof cfg.channels.matrix !== "object") return normalizedAccountId === DEFAULT_ACCOUNT_ID;
|
|
34
|
+
if (requiresExplicitMatrixDefaultAccount(cfg)) return false;
|
|
35
|
+
return normalizeAccountId(resolveMatrixDefaultOrOnlyAccountId(cfg)) === normalizedAccountId;
|
|
36
|
+
}
|
|
37
|
+
function resolveLegacyMigrationSourcePath(env, accountId) {
|
|
38
|
+
if (!shouldReadLegacyCredentialsForAccount(accountId)) return null;
|
|
39
|
+
const legacyPath = resolveLegacyMatrixCredentialsPath(env);
|
|
40
|
+
return legacyPath === resolveMatrixCredentialsPath(env, accountId) ? null : legacyPath;
|
|
41
|
+
}
|
|
42
|
+
function parseMatrixCredentialsFile(filePath) {
|
|
43
|
+
const raw = fs.readFileSync(filePath, "utf-8");
|
|
44
|
+
const parsed = JSON.parse(raw);
|
|
45
|
+
if (typeof parsed.homeserver !== "string" || typeof parsed.userId !== "string" || typeof parsed.accessToken !== "string") return null;
|
|
46
|
+
return parsed;
|
|
47
|
+
}
|
|
48
|
+
function loadMatrixCredentialsFile(filePath, source) {
|
|
49
|
+
try {
|
|
50
|
+
return {
|
|
51
|
+
kind: "loaded",
|
|
52
|
+
source,
|
|
53
|
+
credentials: parseMatrixCredentialsFile(filePath)
|
|
54
|
+
};
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (error?.code === "ENOENT") return { kind: "missing" };
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function loadLegacyMatrixCredentialsWithCurrentFallback(params) {
|
|
61
|
+
const legacy = loadMatrixCredentialsFile(params.legacyPath, "legacy");
|
|
62
|
+
if (legacy.kind === "loaded") return legacy;
|
|
63
|
+
return loadMatrixCredentialsFile(params.currentPath, "current");
|
|
64
|
+
}
|
|
65
|
+
function resolveMatrixCredentialsDir(env = process.env, stateDir) {
|
|
66
|
+
return resolveMatrixCredentialsDir$1(stateDir ?? resolveStateDir(env));
|
|
67
|
+
}
|
|
68
|
+
function resolveMatrixCredentialsPath(env = process.env, accountId) {
|
|
69
|
+
return resolveMatrixCredentialsPath$1({
|
|
70
|
+
stateDir: resolveStateDir(env),
|
|
71
|
+
accountId
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function loadMatrixCredentials(env = process.env, accountId) {
|
|
75
|
+
const currentPath = resolveMatrixCredentialsPath(env, accountId);
|
|
76
|
+
try {
|
|
77
|
+
const current = loadMatrixCredentialsFile(currentPath, "current");
|
|
78
|
+
if (current.kind === "loaded") return current.credentials;
|
|
79
|
+
const legacyPath = resolveLegacyMigrationSourcePath(env, accountId);
|
|
80
|
+
if (!legacyPath) return null;
|
|
81
|
+
const loaded = loadLegacyMatrixCredentialsWithCurrentFallback({
|
|
82
|
+
legacyPath,
|
|
83
|
+
currentPath
|
|
84
|
+
});
|
|
85
|
+
if (loaded.kind !== "loaded" || !loaded.credentials) return null;
|
|
86
|
+
if (loaded.source === "legacy") try {
|
|
87
|
+
fs.mkdirSync(path.dirname(currentPath), { recursive: true });
|
|
88
|
+
fs.renameSync(legacyPath, currentPath);
|
|
89
|
+
} catch {}
|
|
90
|
+
return loaded.credentials;
|
|
91
|
+
} catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function clearMatrixCredentials(env = process.env, accountId) {
|
|
96
|
+
const paths = [resolveMatrixCredentialsPath(env, accountId), resolveLegacyMigrationSourcePath(env, accountId)];
|
|
97
|
+
for (const filePath of paths) {
|
|
98
|
+
if (!filePath) continue;
|
|
99
|
+
try {
|
|
100
|
+
fs.unlinkSync(filePath);
|
|
101
|
+
} catch {}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function credentialsMatchConfig(stored, config) {
|
|
105
|
+
if (!config.userId) {
|
|
106
|
+
if (!config.accessToken) return false;
|
|
107
|
+
return stored.homeserver === config.homeserver && stored.accessToken === config.accessToken;
|
|
108
|
+
}
|
|
109
|
+
return stored.homeserver === config.homeserver && stored.userId === config.userId;
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
export { resolveMatrixCredentialsDir as a, loadMatrixCredentials as i, credentialsMatchConfig as n, resolveMatrixCredentialsPath as o, credentials_read_exports as r, clearMatrixCredentials as t };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region extensions/matrix/src/matrix/credentials-write.runtime.ts
|
|
2
|
+
let matrixCredentialsRuntimePromise;
|
|
3
|
+
function loadMatrixCredentialsRuntime() {
|
|
4
|
+
matrixCredentialsRuntimePromise ??= import("./credentials-B7GsBbgQ.js");
|
|
5
|
+
return matrixCredentialsRuntimePromise;
|
|
6
|
+
}
|
|
7
|
+
async function saveMatrixCredentials(...args) {
|
|
8
|
+
return (await loadMatrixCredentialsRuntime()).saveMatrixCredentials(...args);
|
|
9
|
+
}
|
|
10
|
+
async function saveBackfilledMatrixDeviceId(...args) {
|
|
11
|
+
return (await loadMatrixCredentialsRuntime()).saveBackfilledMatrixDeviceId(...args);
|
|
12
|
+
}
|
|
13
|
+
async function touchMatrixCredentials(...args) {
|
|
14
|
+
return (await loadMatrixCredentialsRuntime()).touchMatrixCredentials(...args);
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { saveBackfilledMatrixDeviceId, saveMatrixCredentials, touchMatrixCredentials };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
//#region extensions/matrix/src/matrix/sdk/crypto-node.runtime.ts
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
function loadMatrixCryptoNodeBindings() {
|
|
5
|
+
const { Attachment, EncryptedAttachment } = require("@matrix-org/matrix-sdk-crypto-nodejs");
|
|
6
|
+
return {
|
|
7
|
+
Attachment,
|
|
8
|
+
EncryptedAttachment
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { loadMatrixCryptoNodeBindings };
|