matrix-js-sdk 42.1.0 → 42.2.0

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.
Files changed (154) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lib/@types/beacon.d.ts +1 -1
  3. package/lib/@types/beacon.js +1 -1
  4. package/lib/@types/beacon.js.map +1 -1
  5. package/lib/@types/extensible_events.d.ts.map +1 -1
  6. package/lib/@types/extensible_events.js.map +1 -1
  7. package/lib/autodiscovery.js.map +1 -1
  8. package/lib/browser-index.js.map +1 -1
  9. package/lib/client.d.ts +12 -5
  10. package/lib/client.d.ts.map +1 -1
  11. package/lib/client.js +23 -26
  12. package/lib/client.js.map +1 -1
  13. package/lib/common-crypto/key-passphrase.js +1 -1
  14. package/lib/common-crypto/key-passphrase.js.map +1 -1
  15. package/lib/crypto/store/indexeddb-crypto-store-backend.js +2 -1
  16. package/lib/crypto/store/indexeddb-crypto-store-backend.js.map +1 -1
  17. package/lib/crypto/store/indexeddb-crypto-store.d.ts.map +1 -1
  18. package/lib/crypto/store/indexeddb-crypto-store.js +1 -1
  19. package/lib/crypto/store/indexeddb-crypto-store.js.map +1 -1
  20. package/lib/crypto/store/memory-crypto-store.js.map +1 -1
  21. package/lib/embedded.d.ts +16 -0
  22. package/lib/embedded.d.ts.map +1 -1
  23. package/lib/embedded.js +19 -6
  24. package/lib/embedded.js.map +1 -1
  25. package/lib/matrixrtc/MatrixRTCSession.js.map +1 -1
  26. package/lib/matrixrtc/MembershipManager.js.map +1 -1
  27. package/lib/matrixrtc/MembershipManagerActionScheduler.js.map +1 -1
  28. package/lib/matrixrtc/RTCEncryptionManager.js.map +1 -1
  29. package/lib/matrixrtc/ToDeviceKeyTransport.js.map +1 -1
  30. package/lib/matrixrtc/membershipData/rtc.js.map +1 -1
  31. package/lib/matrixrtc/utils.d.ts +0 -1
  32. package/lib/matrixrtc/utils.d.ts.map +1 -1
  33. package/lib/matrixrtc/utils.js +0 -1
  34. package/lib/matrixrtc/utils.js.map +1 -1
  35. package/lib/models/event-timeline-set.js +3 -3
  36. package/lib/models/event-timeline-set.js.map +1 -1
  37. package/lib/models/event.d.ts.map +1 -1
  38. package/lib/models/event.js.map +1 -1
  39. package/lib/models/invites-ignorer.js.map +1 -1
  40. package/lib/models/poll.js.map +1 -1
  41. package/lib/models/read-receipt.js.map +1 -1
  42. package/lib/models/relations-container.d.ts +10 -0
  43. package/lib/models/relations-container.d.ts.map +1 -1
  44. package/lib/models/relations-container.js +39 -17
  45. package/lib/models/relations-container.js.map +1 -1
  46. package/lib/models/relations.js +1 -1
  47. package/lib/models/relations.js.map +1 -1
  48. package/lib/models/room.js +3 -3
  49. package/lib/models/room.js.map +1 -1
  50. package/lib/models/thread.d.ts +3 -0
  51. package/lib/models/thread.d.ts.map +1 -1
  52. package/lib/models/thread.js +36 -3
  53. package/lib/models/thread.js.map +1 -1
  54. package/lib/oauth/authorize.js +1 -1
  55. package/lib/oauth/authorize.js.map +1 -1
  56. package/lib/oauth/index.js +4 -2
  57. package/lib/oauth/index.js.map +1 -1
  58. package/lib/pollingCachedValue.d.ts +77 -0
  59. package/lib/pollingCachedValue.d.ts.map +1 -0
  60. package/lib/pollingCachedValue.js +160 -0
  61. package/lib/pollingCachedValue.js.map +1 -0
  62. package/lib/pushprocessor.js.map +1 -1
  63. package/lib/receipt-accumulator.d.ts.map +1 -1
  64. package/lib/receipt-accumulator.js.map +1 -1
  65. package/lib/rendezvous/MSC4108SignInWithQR.d.ts.map +1 -1
  66. package/lib/rendezvous/MSC4108SignInWithQR.js +2 -3
  67. package/lib/rendezvous/MSC4108SignInWithQR.js.map +1 -1
  68. package/lib/rtcTransportsCachedValue.d.ts +9 -0
  69. package/lib/rtcTransportsCachedValue.d.ts.map +1 -0
  70. package/lib/rtcTransportsCachedValue.js +38 -0
  71. package/lib/rtcTransportsCachedValue.js.map +1 -0
  72. package/lib/rust-crypto/PerSessionKeyBackupDownloader.js.map +1 -1
  73. package/lib/rust-crypto/backup.d.ts +2 -3
  74. package/lib/rust-crypto/backup.d.ts.map +1 -1
  75. package/lib/rust-crypto/backup.js.map +1 -1
  76. package/lib/rust-crypto/index.d.ts +10 -4
  77. package/lib/rust-crypto/index.d.ts.map +1 -1
  78. package/lib/rust-crypto/index.js +20 -3
  79. package/lib/rust-crypto/index.js.map +1 -1
  80. package/lib/rust-crypto/libolm_migration.js.map +1 -1
  81. package/lib/rust-crypto/rust-crypto.js.map +1 -1
  82. package/lib/sliding-sync-sdk.js.map +1 -1
  83. package/lib/sliding-sync.js.map +1 -1
  84. package/lib/store/indexeddb-local-backend.js +1 -1
  85. package/lib/store/indexeddb-local-backend.js.map +1 -1
  86. package/lib/store/indexeddb-store-worker.d.ts.map +1 -1
  87. package/lib/store/indexeddb-store-worker.js +1 -0
  88. package/lib/store/indexeddb-store-worker.js.map +1 -1
  89. package/lib/sync.d.ts.map +1 -1
  90. package/lib/sync.js.map +1 -1
  91. package/lib/utils.d.ts +1 -1
  92. package/lib/utils.d.ts.map +1 -1
  93. package/lib/utils.js +1 -0
  94. package/lib/utils.js.map +1 -1
  95. package/lib/webrtc/call.js.map +1 -1
  96. package/lib/webrtc/groupCall.js.map +1 -1
  97. package/lib/webrtc/mediaHandler.js.map +1 -1
  98. package/lib/webrtc/stats/callStatsReportGatherer.js.map +1 -1
  99. package/lib/webrtc/stats/transportStatsBuilder.js.map +1 -1
  100. package/lib/wellKnownCachedValue.d.ts +8 -0
  101. package/lib/wellKnownCachedValue.d.ts.map +1 -0
  102. package/lib/wellKnownCachedValue.js +34 -0
  103. package/lib/wellKnownCachedValue.js.map +1 -0
  104. package/package.json +4 -4
  105. package/src/@types/beacon.ts +1 -1
  106. package/src/@types/extensible_events.ts +3 -4
  107. package/src/autodiscovery.ts +2 -2
  108. package/src/browser-index.ts +1 -1
  109. package/src/client.ts +48 -40
  110. package/src/common-crypto/key-passphrase.ts +1 -1
  111. package/src/crypto/store/indexeddb-crypto-store-backend.ts +2 -1
  112. package/src/crypto/store/indexeddb-crypto-store.ts +1 -3
  113. package/src/crypto/store/memory-crypto-store.ts +1 -1
  114. package/src/embedded.ts +34 -11
  115. package/src/matrixrtc/MatrixRTCSession.ts +3 -3
  116. package/src/matrixrtc/MembershipManager.ts +1 -1
  117. package/src/matrixrtc/MembershipManagerActionScheduler.ts +1 -1
  118. package/src/matrixrtc/RTCEncryptionManager.ts +2 -2
  119. package/src/matrixrtc/ToDeviceKeyTransport.ts +3 -3
  120. package/src/matrixrtc/membershipData/rtc.ts +1 -1
  121. package/src/matrixrtc/utils.ts +0 -2
  122. package/src/models/event-timeline-set.ts +3 -3
  123. package/src/models/event.ts +7 -10
  124. package/src/models/invites-ignorer.ts +1 -1
  125. package/src/models/poll.ts +1 -1
  126. package/src/models/read-receipt.ts +1 -1
  127. package/src/models/relations-container.ts +55 -19
  128. package/src/models/relations.ts +1 -1
  129. package/src/models/room.ts +9 -9
  130. package/src/models/thread.ts +49 -4
  131. package/src/oauth/authorize.ts +1 -1
  132. package/src/oauth/index.ts +2 -2
  133. package/src/pollingCachedValue.ts +184 -0
  134. package/src/pushprocessor.ts +3 -3
  135. package/src/receipt-accumulator.ts +1 -2
  136. package/src/rendezvous/MSC4108SignInWithQR.ts +3 -4
  137. package/src/rtcTransportsCachedValue.ts +40 -0
  138. package/src/rust-crypto/PerSessionKeyBackupDownloader.ts +1 -1
  139. package/src/rust-crypto/backup.ts +1 -5
  140. package/src/rust-crypto/index.ts +23 -25
  141. package/src/rust-crypto/libolm_migration.ts +1 -1
  142. package/src/rust-crypto/rust-crypto.ts +3 -3
  143. package/src/sliding-sync-sdk.ts +1 -1
  144. package/src/sliding-sync.ts +1 -1
  145. package/src/store/indexeddb-local-backend.ts +1 -1
  146. package/src/store/indexeddb-store-worker.ts +1 -0
  147. package/src/sync.ts +4 -3
  148. package/src/utils.ts +3 -2
  149. package/src/webrtc/call.ts +6 -6
  150. package/src/webrtc/groupCall.ts +7 -7
  151. package/src/webrtc/mediaHandler.ts +1 -1
  152. package/src/webrtc/stats/callStatsReportGatherer.ts +2 -2
  153. package/src/webrtc/stats/transportStatsBuilder.ts +1 -1
  154. package/src/wellKnownCachedValue.ts +34 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ Changes in [42.2.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v42.2.0) (2026-08-18)
2
+ ==================================================================================================
3
+ ## 🐛 Bug Fixes
4
+
5
+ * Fix pre-initialization thread edits when target is known ([#5440](https://github.com/matrix-org/matrix-js-sdk/pull/5440)). Contributed by @basnijholt.
6
+ * Fix package failing to load in Node ESM due to directory import ([#5460](https://github.com/matrix-org/matrix-js-sdk/pull/5460)). Contributed by @syphernl.
7
+
8
+
1
9
  Changes in [42.1.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v42.1.0) (2026-08-04)
2
10
  ==================================================================================================
3
11
  ## 🦖 Deprecations
@@ -12,7 +12,7 @@ import { type MAssetEvent, type MLocationEvent, type MTimestampEvent } from "./l
12
12
  * 2. a user can have an arbitrary number of beacon_info events
13
13
  *
14
14
  * 1. is achieved by setting the state_key to the owners mxid.
15
- * Event keys in room state are a combination of `type` + `state_key`.
15
+ * Event keys in room state are a combination of `typestate_key`.
16
16
  * To achieve an arbitrary number of only owner-writable state events
17
17
  * we introduce a variable suffix to the event type
18
18
  *
@@ -27,7 +27,7 @@ import { UnstableValue } from "../NamespacedValue.js";
27
27
  * 2. a user can have an arbitrary number of beacon_info events
28
28
  *
29
29
  * 1. is achieved by setting the state_key to the owners mxid.
30
- * Event keys in room state are a combination of `type` + `state_key`.
30
+ * Event keys in room state are a combination of `typestate_key`.
31
31
  * To achieve an arbitrary number of only owner-writable state events
32
32
  * we introduce a variable suffix to the event type
33
33
  *
@@ -1 +1 @@
1
- {"version":3,"file":"beacon.js","names":[],"sources":["../../src/@types/beacon.ts"],"sourcesContent":["/*\nCopyright 2022 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type RelatesToRelationship, type REFERENCE_RELATION } from \"./extensible_events.ts\";\nimport { UnstableValue } from \"../NamespacedValue.ts\";\nimport { type MAssetEvent, type MLocationEvent, type MTimestampEvent } from \"./location.ts\";\n\n/**\n * Beacon info and beacon event types as described in MSC3672\n * https://github.com/matrix-org/matrix-spec-proposals/pull/3672\n */\n\n/**\n * Beacon info events are state events.\n * We have two requirements for these events:\n * 1. they can only be written by their owner\n * 2. a user can have an arbitrary number of beacon_info events\n *\n * 1. is achieved by setting the state_key to the owners mxid.\n * Event keys in room state are a combination of `type` + `state_key`.\n * To achieve an arbitrary number of only owner-writable state events\n * we introduce a variable suffix to the event type\n *\n * @example\n * ```\n * {\n * \"type\": \"m.beacon_info.@matthew:matrix.org.1\",\n * \"state_key\": \"@matthew:matrix.org\",\n * \"content\": {\n * \"m.beacon_info\": {\n * \"description\": \"The Matthew Tracker\",\n * \"timeout\": 86400000,\n * },\n * // more content as described below\n * }\n * },\n * {\n * \"type\": \"m.beacon_info.@matthew:matrix.org.2\",\n * \"state_key\": \"@matthew:matrix.org\",\n * \"content\": {\n * \"m.beacon_info\": {\n * \"description\": \"Another different Matthew tracker\",\n * \"timeout\": 400000,\n * },\n * // more content as described below\n * }\n * }\n * ```\n */\n\n/**\n * Non-variable type for m.beacon_info event content\n */\nexport const M_BEACON_INFO = new UnstableValue(\"m.beacon_info\", \"org.matrix.msc3672.beacon_info\");\nexport const M_BEACON = new UnstableValue(\"m.beacon\", \"org.matrix.msc3672.beacon\");\n\nexport type MBeaconInfoContent = {\n description?: string;\n // how long from the last event until we consider the beacon inactive in milliseconds\n timeout: number;\n // true when this is a live location beacon\n // https://github.com/matrix-org/matrix-spec-proposals/pull/3672\n live?: boolean;\n};\n\n/**\n * m.beacon_info Event example from the spec\n * https://github.com/matrix-org/matrix-spec-proposals/pull/3672\n * @example\n * ```\n * {\n * \"type\": \"m.beacon_info\",\n * \"state_key\": \"@matthew:matrix.org\",\n * \"content\": {\n * \"m.beacon_info\": {\n * \"description\": \"The Matthew Tracker\", // same as an `m.location` description\n * \"timeout\": 86400000, // how long from the last event until we consider the beacon inactive in milliseconds\n * },\n * \"m.ts\": 1436829458432, // creation timestamp of the beacon on the client\n * \"m.asset\": {\n * \"type\": \"m.self\" // the type of asset being tracked as per MSC3488\n * }\n * }\n * }\n * ```\n */\n\n/**\n * m.beacon_info.* event content\n */\nexport type MBeaconInfoEventContent = MBeaconInfoContent &\n // creation timestamp of the beacon on the client\n MTimestampEvent &\n // the type of asset being tracked as per MSC3488\n MAssetEvent;\n\n/**\n * m.beacon event example\n * https://github.com/matrix-org/matrix-spec-proposals/pull/3672\n * @example\n * ```\n * {\n * \"type\": \"m.beacon\",\n * \"sender\": \"@matthew:matrix.org\",\n * \"content\": {\n * \"m.relates_to\": { // from MSC2674: https://github.com/matrix-org/matrix-doc/pull/2674\n * \"rel_type\": \"m.reference\", // from MSC3267: https://github.com/matrix-org/matrix-doc/pull/3267\n * \"event_id\": \"$beacon_info\"\n * },\n * \"m.location\": {\n * \"uri\": \"geo:51.5008,0.1247;u=35\",\n * \"description\": \"Arbitrary beacon information\"\n * },\n * \"m.ts\": 1636829458432,\n * }\n * }\n * ```\n */\n\n/**\n * Content of an m.beacon event\n */\nexport type MBeaconEventContent = MLocationEvent &\n // timestamp when location was taken\n MTimestampEvent &\n // relates to a beacon_info event\n RelatesToRelationship<typeof REFERENCE_RELATION>;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAAS,aAAa,QAAQ,uBAAuB;AAGrD;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,eAAe,EAAE,gCAAgC,CAAC;AACjG,OAAO,MAAM,QAAQ,GAAG,IAAI,aAAa,CAAC,UAAU,EAAE,2BAA2B,CAAC;;AAWlF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"beacon.js","names":[],"sources":["../../src/@types/beacon.ts"],"sourcesContent":["/*\nCopyright 2022 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type RelatesToRelationship, type REFERENCE_RELATION } from \"./extensible_events.ts\";\nimport { UnstableValue } from \"../NamespacedValue.ts\";\nimport { type MAssetEvent, type MLocationEvent, type MTimestampEvent } from \"./location.ts\";\n\n/**\n * Beacon info and beacon event types as described in MSC3672\n * https://github.com/matrix-org/matrix-spec-proposals/pull/3672\n */\n\n/**\n * Beacon info events are state events.\n * We have two requirements for these events:\n * 1. they can only be written by their owner\n * 2. a user can have an arbitrary number of beacon_info events\n *\n * 1. is achieved by setting the state_key to the owners mxid.\n * Event keys in room state are a combination of `typestate_key`.\n * To achieve an arbitrary number of only owner-writable state events\n * we introduce a variable suffix to the event type\n *\n * @example\n * ```\n * {\n * \"type\": \"m.beacon_info.@matthew:matrix.org.1\",\n * \"state_key\": \"@matthew:matrix.org\",\n * \"content\": {\n * \"m.beacon_info\": {\n * \"description\": \"The Matthew Tracker\",\n * \"timeout\": 86400000,\n * },\n * // more content as described below\n * }\n * },\n * {\n * \"type\": \"m.beacon_info.@matthew:matrix.org.2\",\n * \"state_key\": \"@matthew:matrix.org\",\n * \"content\": {\n * \"m.beacon_info\": {\n * \"description\": \"Another different Matthew tracker\",\n * \"timeout\": 400000,\n * },\n * // more content as described below\n * }\n * }\n * ```\n */\n\n/**\n * Non-variable type for m.beacon_info event content\n */\nexport const M_BEACON_INFO = new UnstableValue(\"m.beacon_info\", \"org.matrix.msc3672.beacon_info\");\nexport const M_BEACON = new UnstableValue(\"m.beacon\", \"org.matrix.msc3672.beacon\");\n\nexport type MBeaconInfoContent = {\n description?: string;\n // how long from the last event until we consider the beacon inactive in milliseconds\n timeout: number;\n // true when this is a live location beacon\n // https://github.com/matrix-org/matrix-spec-proposals/pull/3672\n live?: boolean;\n};\n\n/**\n * m.beacon_info Event example from the spec\n * https://github.com/matrix-org/matrix-spec-proposals/pull/3672\n * @example\n * ```\n * {\n * \"type\": \"m.beacon_info\",\n * \"state_key\": \"@matthew:matrix.org\",\n * \"content\": {\n * \"m.beacon_info\": {\n * \"description\": \"The Matthew Tracker\", // same as an `m.location` description\n * \"timeout\": 86400000, // how long from the last event until we consider the beacon inactive in milliseconds\n * },\n * \"m.ts\": 1436829458432, // creation timestamp of the beacon on the client\n * \"m.asset\": {\n * \"type\": \"m.self\" // the type of asset being tracked as per MSC3488\n * }\n * }\n * }\n * ```\n */\n\n/**\n * m.beacon_info.* event content\n */\nexport type MBeaconInfoEventContent = MBeaconInfoContent &\n // creation timestamp of the beacon on the client\n MTimestampEvent &\n // the type of asset being tracked as per MSC3488\n MAssetEvent;\n\n/**\n * m.beacon event example\n * https://github.com/matrix-org/matrix-spec-proposals/pull/3672\n * @example\n * ```\n * {\n * \"type\": \"m.beacon\",\n * \"sender\": \"@matthew:matrix.org\",\n * \"content\": {\n * \"m.relates_to\": { // from MSC2674: https://github.com/matrix-org/matrix-doc/pull/2674\n * \"rel_type\": \"m.reference\", // from MSC3267: https://github.com/matrix-org/matrix-doc/pull/3267\n * \"event_id\": \"$beacon_info\"\n * },\n * \"m.location\": {\n * \"uri\": \"geo:51.5008,0.1247;u=35\",\n * \"description\": \"Arbitrary beacon information\"\n * },\n * \"m.ts\": 1636829458432,\n * }\n * }\n * ```\n */\n\n/**\n * Content of an m.beacon event\n */\nexport type MBeaconEventContent = MLocationEvent &\n // timestamp when location was taken\n MTimestampEvent &\n // relates to a beacon_info event\n RelatesToRelationship<typeof REFERENCE_RELATION>;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAAS,aAAa,QAAQ,uBAAuB;AAGrD;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,eAAe,EAAE,gCAAgC,CAAC;AACjG,OAAO,MAAM,QAAQ,GAAG,IAAI,aAAa,CAAC,UAAU,EAAE,2BAA2B,CAAC;;AAWlF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"extensible_events.d.ts","sourceRoot":"","sources":["../../src/@types/extensible_events.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,SAAS,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMnF;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IACrB,CAAC,SAAS,eAAe,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;AAEpG;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC;AAE/D;;GAEG;AAEH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,SAAS,0DAA+D,CAAC;AAEtF;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,SAAS,CACjD;IAAE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,iBAAiB,EAAE,CAAA;CAAE,EACzC;IAAE,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAA;CAAE,CAC/C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,MAAM,oDAAyD,CAAC;AAE7E;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,SAAS,CAAC;IAAE,CAAC,MAAM,CAAC,IAAI,CAAC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yD,CAAC;AAE7E;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,SAAS,CAAC;IAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE;IAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAElG;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG,6BAA6B,GAAG,gBAAgB,GAAG,gBAAgB,CAAC;AAEnH;;GAEG;AACH,eAAO,MAAM,kBAAkB,wCAAqC,CAAC;AAErE;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,OAAO,kBAAkB,CAAC,GAAG,MAAM,CAAC;AAE1E;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,GAAG,KAAK,IAAI;IAC3C,cAAc,EAAE;QAEZ,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;QAC7D,QAAQ,EAAE,MAAM,CAAC;KACpB,CAAC;CACL,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,QAAQ;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,QAAQ,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;AAE3E;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI,EAAE,QAAQ,EAAE,mBAAmB,GAAG,IAAI,GAAG,OAAO,CAkBhH"}
@@ -1 +1 @@
1
- {"version":3,"file":"extensible_events.js","names":[],"sources":["../../src/@types/extensible_events.ts"],"sourcesContent":["/*\nCopyright 2021 - 2023 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type EitherAnd, NamespacedValue, UnstableValue } from \"matrix-events-sdk\";\n\nimport { isProvided } from \"../extensible_events_v1/utilities.ts\";\n\n// Types and utilities for MSC1767: Extensible events (version 1) in Matrix\n\n/**\n * Represents the stable and unstable values of a given namespace.\n */\nexport type TSNamespace<N> =\n N extends NamespacedValue<infer S, infer U> ? TSNamespaceValue<S> | TSNamespaceValue<U> : never;\n\n/**\n * Represents a namespaced value, if the value is a string. Used to extract provided types\n * from a TSNamespace<N> (in cases where only stable *or* unstable is provided).\n */\nexport type TSNamespaceValue<V> = V extends string ? V : never;\n\n/**\n * Creates a type which is V when T is `never`, otherwise T.\n */\n// See https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887 for details on the array syntax.\nexport type DefaultNever<T, V> = [T] extends [never] ? V : T;\n\n/**\n * The namespaced value for m.message\n */\nexport const M_MESSAGE = new UnstableValue(\"m.message\", \"org.matrix.msc1767.message\");\n\n/**\n * An m.message event rendering\n */\nexport interface IMessageRendering {\n body: string;\n mimetype?: string;\n}\n\n/**\n * The content for an m.message event\n */\nexport type ExtensibleMessageEventContent = EitherAnd<\n { [M_MESSAGE.name]: IMessageRendering[] },\n { [M_MESSAGE.altName]: IMessageRendering[] }\n>;\n\n/**\n * The namespaced value for m.text\n */\nexport const M_TEXT = new UnstableValue(\"m.text\", \"org.matrix.msc1767.text\");\n\n/**\n * The content for an m.text event\n */\nexport type TextEventContent = EitherAnd<{ [M_TEXT.name]: string }, { [M_TEXT.altName]: string }>;\n\n/**\n * The namespaced value for m.html\n */\nexport const M_HTML = new UnstableValue(\"m.html\", \"org.matrix.msc1767.html\");\n\n/**\n * The content for an m.html event\n */\nexport type HtmlEventContent = EitherAnd<{ [M_HTML.name]: string }, { [M_HTML.altName]: string }>;\n\n/**\n * The content for an m.message, m.text, or m.html event\n */\nexport type ExtensibleAnyMessageEventContent = ExtensibleMessageEventContent | TextEventContent | HtmlEventContent;\n\n/**\n * The namespaced value for an m.reference relation\n */\nexport const REFERENCE_RELATION = new NamespacedValue(\"m.reference\");\n\n/**\n * Represents any relation type\n */\nexport type AnyRelation = TSNamespace<typeof REFERENCE_RELATION> | string;\n\n/**\n * An m.relates_to relationship\n */\nexport type RelatesToRelationship<R = never> = {\n \"m.relates_to\": {\n // See https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887 for array syntax\n rel_type: [R] extends [never] ? AnyRelation : TSNamespace<R>;\n event_id: string;\n };\n};\n\n/**\n * Partial types for a Matrix Event.\n */\nexport interface IPartialEvent<TContent> {\n type: string;\n content: TContent;\n}\n\n/**\n * Represents a potentially namespaced event type.\n */\nexport type ExtensibleEventType = NamespacedValue<string, string> | string;\n\n/**\n * Determines if two event types are the same, including namespaces.\n * @param given - The given event type. This will be compared\n * against the expected type.\n * @param expected - The expected event type.\n * @returns True if the given type matches the expected type.\n */\nexport function isEventTypeSame(given: ExtensibleEventType | null, expected: ExtensibleEventType | null): boolean {\n if (typeof given === \"string\") {\n if (typeof expected === \"string\") {\n return expected === given;\n } else {\n return expected!.matches(given as string);\n }\n } else {\n if (typeof expected === \"string\") {\n return given!.matches(expected as string);\n } else {\n const expectedNs = expected!;\n const givenNs = given!;\n return (\n expectedNs.matches(givenNs.name) ||\n (isProvided(givenNs.altName) && expectedNs.matches(givenNs.altName!))\n );\n }\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAyB,eAAe,EAAE,aAAa,QAAQ,mBAAmB;AAElF,SAAS,UAAU,QAAQ,sCAAsC;;AAEjE;;AAEA;AACA;AACA;;AAIA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA,OAAO,MAAM,SAAS,GAAG,IAAI,aAAa,CAAC,WAAW,EAAE,4BAA4B,CAAC;;AAErF;AACA;AACA;;AAMA;AACA;AACA;;AAMA;AACA;AACA;AACA,OAAO,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,QAAQ,EAAE,yBAAyB,CAAC;;AAE5E;AACA;AACA;;AAGA;AACA;AACA;AACA,OAAO,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,QAAQ,EAAE,yBAAyB,CAAC;;AAE5E;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA,OAAO,MAAM,kBAAkB,GAAG,IAAI,eAAe,CAAC,aAAa,CAAC;;AAEpE;AACA;AACA;;AAGA;AACA;AACA;;AASA;AACA;AACA;;AAMA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,eAAe,CAAC,KAAiC,EAAE,QAAoC,EAAW;EAC9G,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;IAC3B,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;MAC9B,OAAO,QAAQ,KAAK,KAAK;IAC7B,CAAC,MAAM;MACH,OAAO,QAAQ,CAAE,OAAO,CAAC,KAAe,CAAC;IAC7C;EACJ,CAAC,MAAM;IACH,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;MAC9B,OAAO,KAAK,CAAE,OAAO,CAAC,QAAkB,CAAC;IAC7C,CAAC,MAAM;MACH,MAAM,UAAU,GAAG,QAAS;MAC5B,MAAM,OAAO,GAAG,KAAM;MACtB,OACI,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAC/B,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,OAAQ,CAAE;IAE7E;EACJ;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"extensible_events.js","names":[],"sources":["../../src/@types/extensible_events.ts"],"sourcesContent":["/*\nCopyright 2021 - 2023 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type EitherAnd, NamespacedValue, UnstableValue } from \"matrix-events-sdk\";\n\nimport { isProvided } from \"../extensible_events_v1/utilities.ts\";\n\n// Types and utilities for MSC1767: Extensible events (version 1) in Matrix\n\n/**\n * Represents the stable and unstable values of a given namespace.\n */\nexport type TSNamespace<N> =\n N extends NamespacedValue<infer S, infer U> ? TSNamespaceValue<S> | TSNamespaceValue<U> : never;\n\n/**\n * Represents a namespaced value, if the value is a string. Used to extract provided types\n * from a TSNamespace<N> (in cases where only stable *or* unstable is provided).\n */\nexport type TSNamespaceValue<V> = V extends string ? V : never;\n\n/**\n * Creates a type which is V when T is `never`, otherwise T.\n */\n// See https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887 for details on the array syntax.\nexport type DefaultNever<T, V> = [T] extends [never] ? V : T;\n\n/**\n * The namespaced value for m.message\n */\nexport const M_MESSAGE = new UnstableValue(\"m.message\", \"org.matrix.msc1767.message\");\n\n/**\n * An m.message event rendering\n */\nexport interface IMessageRendering {\n body: string;\n mimetype?: string;\n}\n\n/**\n * The content for an m.message event\n */\nexport type ExtensibleMessageEventContent = EitherAnd<\n { [M_MESSAGE.name]: IMessageRendering[] },\n { [M_MESSAGE.altName]: IMessageRendering[] }\n>;\n\n/**\n * The namespaced value for m.text\n */\nexport const M_TEXT = new UnstableValue(\"m.text\", \"org.matrix.msc1767.text\");\n\n/**\n * The content for an m.text event\n */\nexport type TextEventContent = EitherAnd<{ [M_TEXT.name]: string }, { [M_TEXT.altName]: string }>;\n\n/**\n * The namespaced value for m.html\n */\nexport const M_HTML = new UnstableValue(\"m.html\", \"org.matrix.msc1767.html\");\n\n/**\n * The content for an m.html event\n */\nexport type HtmlEventContent = EitherAnd<{ [M_HTML.name]: string }, { [M_HTML.altName]: string }>;\n\n/**\n * The content for an m.message, m.text, or m.html event\n */\nexport type ExtensibleAnyMessageEventContent = ExtensibleMessageEventContent | TextEventContent | HtmlEventContent;\n\n/**\n * The namespaced value for an m.reference relation\n */\nexport const REFERENCE_RELATION = new NamespacedValue(\"m.reference\");\n\n/**\n * Represents any relation type\n */\nexport type AnyRelation = TSNamespace<typeof REFERENCE_RELATION> | string;\n\n/**\n * An m.relates_to relationship\n */\nexport type RelatesToRelationship<R = never> = {\n \"m.relates_to\": {\n // See https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887 for array syntax\n rel_type: [R] extends [never] ? AnyRelation : TSNamespace<R>;\n event_id: string;\n };\n};\n\n/**\n * Partial types for a Matrix Event.\n */\nexport interface IPartialEvent<TContent> {\n type: string;\n content: TContent;\n}\n\n/**\n * Represents a potentially namespaced event type.\n */\nexport type ExtensibleEventType = NamespacedValue<string, string> | string;\n\n/**\n * Determines if two event types are the same, including namespaces.\n * @param given - The given event type. This will be compared\n * against the expected type.\n * @param expected - The expected event type.\n * @returns True if the given type matches the expected type.\n */\nexport function isEventTypeSame(given: ExtensibleEventType | null, expected: ExtensibleEventType | null): boolean {\n if (typeof given === \"string\") {\n if (typeof expected === \"string\") {\n return expected === given;\n } else {\n return expected!.matches(given);\n }\n } else {\n if (typeof expected === \"string\") {\n return given!.matches(expected);\n } else {\n const expectedNs = expected!;\n const givenNs = given!;\n return (\n expectedNs.matches(givenNs.name) || (isProvided(givenNs.altName) && expectedNs.matches(givenNs.altName))\n );\n }\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAyB,eAAe,EAAE,aAAa,QA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AO,CAAC,OAAO,CAAE;IAEhH;EACJ;AACJ","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"autodiscovery.js","names":[],"sources":["../src/autodiscovery.ts"],"sourcesContent":["/*\nCopyright 2018 New Vector Ltd\nCopyright 2019 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type IClientWellKnown, type IWellKnownConfig, type IServerVersions } from \"./client.ts\";\nimport { logger } from \"./logger.ts\";\nimport { type MatrixError, Method, timeoutSignal } from \"./http-api/index.ts\";\nimport { SUPPORTED_MATRIX_VERSIONS } from \"./version-support.ts\";\n\n// Dev note: Auto discovery is part of the spec.\n// See: https://matrix.org/docs/spec/client_server/r0.4.0.html#server-discovery\n\nexport enum AutoDiscoveryAction {\n SUCCESS = \"SUCCESS\",\n IGNORE = \"IGNORE\",\n PROMPT = \"PROMPT\",\n FAIL_PROMPT = \"FAIL_PROMPT\",\n FAIL_ERROR = \"FAIL_ERROR\",\n}\n\nexport enum AutoDiscoveryError {\n Invalid = \"Invalid homeserver discovery response\",\n GenericFailure = \"Failed to get autodiscovery configuration from server\",\n InvalidHsBaseUrl = \"Invalid base_url for m.homeserver\",\n InvalidHomeserver = \"Homeserver URL does not appear to be a valid Matrix homeserver\",\n InvalidIsBaseUrl = \"Invalid base_url for m.identity_server\",\n InvalidIdentityServer = \"Identity server URL does not appear to be a valid identity server\",\n InvalidIs = \"Invalid identity server discovery response\",\n MissingWellknown = \"No .well-known JSON file found\",\n InvalidJson = \"Invalid JSON\",\n UnsupportedHomeserverSpecVersion = \"The homeserver does not meet the version requirements\",\n\n // TODO: Implement when Sydent supports the `/versions` endpoint - https://github.com/matrix-org/sydent/issues/424\n //IdentityServerTooOld = \"The identity server does not meet the minimum version requirements\",\n}\n\ninterface AutoDiscoveryState {\n state: AutoDiscoveryAction;\n error?: IWellKnownConfig[\"error\"] | null;\n}\ninterface WellKnownConfig extends Omit<IWellKnownConfig, \"error\">, AutoDiscoveryState {}\n\nexport interface ClientConfig extends Omit<IClientWellKnown, \"m.homeserver\" | \"m.identity_server\"> {\n \"m.homeserver\": WellKnownConfig;\n \"m.identity_server\": WellKnownConfig;\n}\n\n/**\n * Utilities for automatically discovery resources, such as homeservers\n * for users to log in to.\n */\nexport class AutoDiscovery {\n // Dev note: the constants defined here are related to but not\n // exactly the same as those in the spec. This is to hopefully\n // translate the meaning of the states in the spec, but also\n // support our own if needed.\n\n public static readonly ERROR_INVALID = AutoDiscoveryError.Invalid;\n\n public static readonly ERROR_GENERIC_FAILURE = AutoDiscoveryError.GenericFailure;\n\n public static readonly ERROR_INVALID_HS_BASE_URL = AutoDiscoveryError.InvalidHsBaseUrl;\n\n public static readonly ERROR_INVALID_HOMESERVER = AutoDiscoveryError.InvalidHomeserver;\n\n public static readonly ERROR_INVALID_IS_BASE_URL = AutoDiscoveryError.InvalidIsBaseUrl;\n\n public static readonly ERROR_INVALID_IDENTITY_SERVER = AutoDiscoveryError.InvalidIdentityServer;\n\n public static readonly ERROR_INVALID_IS = AutoDiscoveryError.InvalidIs;\n\n public static readonly ERROR_MISSING_WELLKNOWN = AutoDiscoveryError.MissingWellknown;\n\n public static readonly ERROR_INVALID_JSON = AutoDiscoveryError.InvalidJson;\n\n public static readonly ERROR_UNSUPPORTED_HOMESERVER_SPEC_VERSION =\n AutoDiscoveryError.UnsupportedHomeserverSpecVersion;\n\n public static readonly ALL_ERRORS = Object.keys(AutoDiscoveryError) as AutoDiscoveryError[];\n\n /**\n * The auto discovery failed. The client is expected to communicate\n * the error to the user and refuse logging in.\n */\n public static readonly FAIL_ERROR = AutoDiscoveryAction.FAIL_ERROR;\n\n /**\n * The auto discovery failed, however the client may still recover\n * from the problem. The client is recommended to that the same\n * action it would for PROMPT while also warning the user about\n * what went wrong. The client may also treat this the same as\n * a FAIL_ERROR state.\n */\n public static readonly FAIL_PROMPT = AutoDiscoveryAction.FAIL_PROMPT;\n\n /**\n * The auto discovery didn't fail but did not find anything of\n * interest. The client is expected to prompt the user for more\n * information, or fail if it prefers.\n */\n public static readonly PROMPT = AutoDiscoveryAction.PROMPT;\n\n /**\n * The auto discovery was successful.\n */\n public static readonly SUCCESS = AutoDiscoveryAction.SUCCESS;\n\n /**\n * Validates and verifies client configuration information for purposes\n * of logging in. Such information includes the homeserver URL\n * and identity server URL the client would want. Additional details\n * may also be included, and will be transparently brought into the\n * response object unaltered.\n * @param wellknown - The configuration object itself, as returned\n * by the .well-known auto-discovery endpoint.\n * @returns Promise which resolves to the verified\n * configuration, which may include error states. Rejects on unexpected\n * failure, not when verification fails.\n */\n public static async fromDiscoveryConfig(wellknown?: IClientWellKnown): Promise<ClientConfig> {\n // Step 1 is to get the config, which is provided to us here.\n\n // We default to an error state to make the first few checks easier to\n // write. We'll update the properties of this object over the duration\n // of this function.\n const clientConfig: ClientConfig = {\n \"m.homeserver\": {\n state: AutoDiscovery.FAIL_ERROR,\n error: AutoDiscovery.ERROR_INVALID,\n base_url: null,\n },\n \"m.identity_server\": {\n // Technically, we don't have a problem with the identity server\n // config at this point.\n state: AutoDiscovery.PROMPT,\n error: null,\n base_url: null,\n },\n };\n\n if (!wellknown?.[\"m.homeserver\"]) {\n logger.error(\"No m.homeserver key in config\");\n\n clientConfig[\"m.homeserver\"].state = AutoDiscovery.FAIL_PROMPT;\n clientConfig[\"m.homeserver\"].error = AutoDiscovery.ERROR_INVALID;\n\n return Promise.resolve(clientConfig);\n }\n\n if (!wellknown[\"m.homeserver\"][\"base_url\"]) {\n logger.error(\"No m.homeserver base_url in config\");\n\n clientConfig[\"m.homeserver\"].state = AutoDiscovery.FAIL_PROMPT;\n clientConfig[\"m.homeserver\"].error = AutoDiscovery.ERROR_INVALID_HS_BASE_URL;\n\n return Promise.resolve(clientConfig);\n }\n\n // Step 2: Make sure the homeserver URL is valid *looking*. We'll make\n // sure it points to a homeserver in Step 3.\n const hsUrl = this.sanitizeWellKnownUrl(wellknown[\"m.homeserver\"][\"base_url\"]);\n if (!hsUrl) {\n logger.error(\"Invalid base_url for m.homeserver\");\n clientConfig[\"m.homeserver\"].error = AutoDiscovery.ERROR_INVALID_HS_BASE_URL;\n return Promise.resolve(clientConfig);\n }\n\n // Step 3: Make sure the homeserver URL points to a homeserver.\n const hsVersions = await this.fetchWellKnownObject<IServerVersions>(`${hsUrl}/_matrix/client/versions`);\n if (!hsVersions || !Array.isArray(hsVersions.raw?.[\"versions\"])) {\n logger.error(\"Invalid /versions response\");\n clientConfig[\"m.homeserver\"].error = AutoDiscovery.ERROR_INVALID_HOMESERVER;\n\n // Supply the base_url to the caller because they may be ignoring liveliness\n // errors, like this one.\n clientConfig[\"m.homeserver\"].base_url = hsUrl;\n\n return Promise.resolve(clientConfig);\n }\n\n // Step 3.1: Non-spec check to ensure the server will actually work for us. We need to check if\n // any of the versions in `SUPPORTED_MATRIX_VERSIONS` are listed in the /versions response.\n const hsVersionSet = new Set(hsVersions.raw![\"versions\"]);\n let supportedVersionFound = false;\n for (const version of SUPPORTED_MATRIX_VERSIONS) {\n if (hsVersionSet.has(version)) {\n supportedVersionFound = true;\n break;\n }\n }\n if (!supportedVersionFound) {\n logger.error(\"Homeserver does not meet version requirements\");\n clientConfig[\"m.homeserver\"].error = AutoDiscovery.ERROR_UNSUPPORTED_HOMESERVER_SPEC_VERSION;\n\n // Supply the base_url to the caller because they may be ignoring liveliness\n // errors, like this one.\n clientConfig[\"m.homeserver\"].base_url = hsUrl;\n\n return Promise.resolve(clientConfig);\n }\n\n // Step 4: Now that the homeserver looks valid, update our client config.\n clientConfig[\"m.homeserver\"] = {\n state: AutoDiscovery.SUCCESS,\n error: null,\n base_url: hsUrl,\n };\n\n // Step 5: Try to pull out the identity server configuration\n let isUrl: string | boolean = \"\";\n if (wellknown[\"m.identity_server\"]) {\n // We prepare a failing identity server response to save lines later\n // in this branch.\n const failingClientConfig: ClientConfig = {\n \"m.homeserver\": clientConfig[\"m.homeserver\"],\n \"m.identity_server\": {\n state: AutoDiscovery.FAIL_PROMPT,\n error: AutoDiscovery.ERROR_INVALID_IS,\n base_url: null,\n },\n };\n\n // Step 5a: Make sure the URL is valid *looking*. We'll make sure it\n // points to an identity server in Step 5b.\n isUrl = this.sanitizeWellKnownUrl(wellknown[\"m.identity_server\"][\"base_url\"]);\n if (!isUrl) {\n logger.error(\"Invalid base_url for m.identity_server\");\n failingClientConfig[\"m.identity_server\"].error = AutoDiscovery.ERROR_INVALID_IS_BASE_URL;\n return Promise.resolve(failingClientConfig);\n }\n\n // Step 5b: Verify there is an identity server listening on the provided\n // URL.\n const isResponse = await this.fetchWellKnownObject(`${isUrl}/_matrix/identity/v2`);\n if (!isResponse?.raw || isResponse.action !== AutoDiscoveryAction.SUCCESS) {\n logger.error(\"Invalid /v2 response\");\n failingClientConfig[\"m.identity_server\"].error = AutoDiscovery.ERROR_INVALID_IDENTITY_SERVER;\n\n // Supply the base_url to the caller because they may be ignoring\n // liveliness errors, like this one.\n failingClientConfig[\"m.identity_server\"].base_url = isUrl;\n\n return Promise.resolve(failingClientConfig);\n }\n }\n\n // Step 6: Now that the identity server is valid, or never existed,\n // populate the IS section.\n if (isUrl && isUrl.toString().length > 0) {\n clientConfig[\"m.identity_server\"] = {\n state: AutoDiscovery.SUCCESS,\n error: null,\n base_url: isUrl,\n };\n }\n\n // Step 7: Copy any other keys directly into the clientConfig. This is for\n // things like custom configuration of services.\n Object.keys(wellknown).forEach((k: keyof IClientWellKnown) => {\n if (k === \"m.homeserver\" || k === \"m.identity_server\") {\n // Only copy selected parts of the config to avoid overwriting\n // properties computed by the validation logic above.\n const notProps = [\"error\", \"state\", \"base_url\"];\n for (const prop of Object.keys(wellknown[k]!)) {\n if (notProps.includes(prop)) continue;\n type Prop = Exclude<keyof IWellKnownConfig, \"error\" | \"state\" | \"base_url\">;\n // @ts-ignore - ts gets unhappy as we're mixing types here\n clientConfig[k][prop as Prop] = wellknown[k]![prop as Prop];\n }\n } else {\n // Just copy the whole thing over otherwise\n clientConfig[k] = wellknown[k];\n }\n });\n\n // Step 8: Give the config to the caller (finally)\n return Promise.resolve(clientConfig);\n }\n\n /**\n * Attempts to automatically discover client configuration information\n * prior to logging in. Such information includes the homeserver URL\n * and identity server URL the client would want. Additional details\n * may also be discovered, and will be transparently included in the\n * response object unaltered.\n * @param domain - The homeserver domain to perform discovery\n * on. For example, \"matrix.org\".\n * @returns Promise which resolves to the discovered\n * configuration, which may include error states. Rejects on unexpected\n * failure, not when discovery fails.\n */\n public static async findClientConfig(domain: string): Promise<ClientConfig> {\n if (!domain || typeof domain !== \"string\" || domain.length === 0) {\n throw new Error(\"'domain' must be a string of non-zero length\");\n }\n\n // We use a .well-known lookup for all cases. According to the spec, we\n // can do other discovery mechanisms if we want such as custom lookups\n // however we won't bother with that here (mostly because the spec only\n // supports .well-known right now).\n //\n // By using .well-known, we need to ensure we at least pull out a URL\n // for the homeserver. We don't really need an identity server configuration\n // but will return one anyways (with state PROMPT) to make development\n // easier for clients. If we can't get a homeserver URL, all bets are\n // off on the rest of the config and we'll assume it is invalid too.\n\n // We default to an error state to make the first few checks easier to\n // write. We'll update the properties of this object over the duration\n // of this function.\n const clientConfig: ClientConfig = {\n \"m.homeserver\": {\n state: AutoDiscovery.FAIL_ERROR,\n error: AutoDiscovery.ERROR_INVALID,\n base_url: null,\n },\n \"m.identity_server\": {\n // Technically, we don't have a problem with the identity server\n // config at this point.\n state: AutoDiscovery.PROMPT,\n error: null,\n base_url: null,\n },\n };\n\n // Step 1: Actually request the .well-known JSON file and make sure it\n // at least has a homeserver definition.\n const domainWithProtocol = domain.includes(\"://\") ? domain : `https://${domain}`;\n const wellknown = await this.fetchWellKnownObject(`${domainWithProtocol}/.well-known/matrix/client`);\n if (!wellknown || wellknown.action !== AutoDiscoveryAction.SUCCESS) {\n logger.error(\"No response or error when parsing .well-known\");\n if (wellknown.reason) logger.error(wellknown.reason);\n if (wellknown.action === AutoDiscoveryAction.IGNORE) {\n clientConfig[\"m.homeserver\"] = {\n state: AutoDiscovery.PROMPT,\n error: null,\n base_url: null,\n };\n } else {\n // this can only ever be FAIL_PROMPT at this point.\n clientConfig[\"m.homeserver\"].state = AutoDiscovery.FAIL_PROMPT;\n clientConfig[\"m.homeserver\"].error = AutoDiscovery.ERROR_INVALID;\n }\n return Promise.resolve(clientConfig);\n }\n\n // Step 2: Validate and parse the config\n return AutoDiscovery.fromDiscoveryConfig(wellknown.raw!);\n }\n\n /**\n * Gets the raw discovery client configuration for the given domain name.\n * Should only be used if there's no validation to be done on the resulting\n * object, otherwise use findClientConfig().\n * @param domain - The domain to get the client config for.\n * @returns Promise which resolves to the domain's client config. Can\n * be an empty object.\n */\n public static async getRawClientConfig(domain?: string): Promise<IClientWellKnown> {\n if (!domain || typeof domain !== \"string\" || domain.length === 0) {\n throw new Error(\"'domain' must be a string of non-zero length\");\n }\n\n const response = await this.fetchWellKnownObject(`https://${domain}/.well-known/matrix/client`);\n if (!response) return {};\n return response.raw ?? {};\n }\n\n /**\n * Sanitizes a given URL to ensure it is either an HTTP or HTTP URL and\n * is suitable for the requirements laid out by .well-known auto discovery.\n * If valid, the URL will also be stripped of any trailing slashes.\n * @param url - The potentially invalid URL to sanitize.\n * @returns The sanitized URL or a falsey value if the URL is invalid.\n * @internal\n */\n private static sanitizeWellKnownUrl(url?: string | null): string | false {\n if (!url) return false;\n\n try {\n let parsed: URL | undefined;\n try {\n parsed = new URL(url);\n } catch (e) {\n logger.error(\"Could not parse url\", e);\n }\n\n if (!parsed?.hostname) return false;\n if (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") return false;\n\n const port = parsed.port ? `:${parsed.port}` : \"\";\n const path = parsed.pathname ? parsed.pathname : \"\";\n let saferUrl = `${parsed.protocol}//${parsed.hostname}${port}${path}`;\n if (saferUrl.endsWith(\"/\")) {\n saferUrl = saferUrl.substring(0, saferUrl.length - 1);\n }\n return saferUrl;\n } catch (e) {\n logger.error(e);\n return false;\n }\n }\n\n private static fetch(resource: URL | string, options?: RequestInit): ReturnType<typeof globalThis.fetch> {\n if (this.fetchFn) {\n return this.fetchFn(resource, options);\n }\n return globalThis.fetch(resource, options);\n }\n\n private static fetchFn?: typeof globalThis.fetch;\n\n public static setFetchFn(fetchFn: typeof globalThis.fetch): void {\n AutoDiscovery.fetchFn = fetchFn;\n }\n\n /**\n * Fetches a JSON object from a given URL, as expected by all .well-known\n * related lookups. If the server gives a 404 then the `action` will be\n * IGNORE. If the server returns something that isn't JSON, the `action`\n * will be FAIL_PROMPT. For any other failure the `action` will be FAIL_PROMPT.\n *\n * The returned object will be a result of the call in object form with\n * the following properties:\n * raw: The JSON object returned by the server.\n * action: One of SUCCESS, IGNORE, or FAIL_PROMPT.\n * reason: Relatively human-readable description of what went wrong.\n * error: The actual Error, if one exists.\n * @param url - The URL to fetch a JSON object from.\n * @returns Promise which resolves to the returned state.\n * @internal\n */\n private static async fetchWellKnownObject<T = IWellKnownConfig>(\n url: string,\n ): Promise<IWellKnownConfig<Partial<T>>> {\n let response: Response;\n\n try {\n response = await AutoDiscovery.fetch(url, {\n method: Method.Get,\n signal: timeoutSignal(5000),\n });\n\n if (response.status === 404) {\n return {\n raw: {},\n action: AutoDiscoveryAction.IGNORE,\n reason: AutoDiscovery.ERROR_MISSING_WELLKNOWN,\n };\n }\n\n if (response.status !== 200) {\n return {\n raw: {},\n action: AutoDiscoveryAction.FAIL_PROMPT,\n reason: \"General failure\",\n };\n }\n } catch (err) {\n const error = err as AutoDiscoveryError | string | undefined;\n let reason = \"\";\n if (typeof error === \"object\") {\n reason = (<Error>error)?.message;\n }\n\n return {\n error,\n raw: {},\n action: AutoDiscoveryAction.FAIL_PROMPT,\n reason: reason || \"General failure\",\n };\n }\n\n try {\n return {\n raw: await response.json(),\n action: AutoDiscoveryAction.SUCCESS,\n };\n } catch (err) {\n const error = err as Error;\n return {\n error,\n raw: {},\n action: AutoDiscoveryAction.FAIL_PROMPT,\n reason:\n (error as MatrixError)?.name === \"SyntaxError\"\n ? AutoDiscovery.ERROR_INVALID_JSON\n : AutoDiscovery.ERROR_INVALID,\n };\n }\n }\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAAS,MAAM,QAAQ,aAAa;AACpC,SAA2B,MAAM,EAAE,aAAa,QAAQ,qBAAqB;AAC7E,SAAS,yBAAyB,QAAQ,sBAAsB;;AAEhE;AACA;;AAEA,WAAY,mBAAmB,0BAAnB,mBAAmB;EAAnB,mBAAmB;EAAnB,mBAAmB;EAAnB,mBAAmB;EAAnB,mBAAmB;EAAnB,mBAAmB;EAAA,OAAnB,mBAAmB;AAAA;AAQ/B,WAAY,kBAAkB,0BAAlB,kBAAkB;EAAlB,kBAAkB;EAAlB,kBAAkB;EAAlB,kBAAkB;EAAlB,kBAAkB;EAAlB,kBAAkB;EAAlB,kBAAkB;EAAlB,kBAAkB;EAAlB,kBAAkB;EAAlB,kBAAkB;EAAlB,kBAAkB,gGAY1B;EACA;EAAA,OAbQ,kBAAkB;AAAA;AA2B9B;AACA;AACA;AACA;AACA,OAAO,MAAM,aAAa,CAAC;EAwDvB;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACI,aAAoB,mBAAmB,CAAC,SAA4B,EAAyB;IACzF;;IAEA;IACA;IACA;IACA,MAAM,YAA0B,GAAG;MAC/B,cAAc,EAAE;QACZ,KAAK,EAAE,aAAa,CAAC,UAAU;QAC/B,KAAK,EAAE,aAAa,CAAC,aAAa;QAClC,QAAQ,EAAE;MACd,CAAC;MACD,mBAAmB,EAAE;QACjB;QACA;QACA,KAAK,EAAE,aAAa,CAAC,MAAM;QAC3B,KAAK,EAAE,IA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O;AAAA,gBANxD,aAAa,2BAQyB,kBAAkB,CAAC,cAAc;AAAA,gBARvE,aAAa,+BAU6B,kBAAkB,CAAC,gBAAgB;AAAA,gBAV7E,aAAa,8BAY4B,kBAAkB,CAAC,iBAAiB;AAAA,gBAZ7E,aAAa,+BAc6B,kBAAkB,CAAC,gBAAgB;AAAA,gBAd7E,aAAa,mCAgBiC,kBAAkB,CAAC,qBAAqB;AAAA,gBAhBtF,aAAa,sBAkBoB,kBAAkB,CAAC,SAAS;AAAA,gBAlB7D,aAAa,6BAoB2B,kBAAkB,CAAC,gBAAgB;AAAA,gBApB3E,aAAa,wBAsBsB,kBAAkB,CAAC,WAAW;AAAA,gBAtBjE,aAAa,+CAyBlB,kBAAkB,CAAC,gCAAgC;AAAA,gBAzB9C,aAAa,gBA2Bc,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC;AAEnE;AACJ;AACA;AACA;AAHI,gBA7BS,aAAa,gBAiCc,mBAAmB,CAAC,UAAU;AAElE;AACJ;AACA;AACA;AACA;AACA;AACA;AANI,gBAnCS,aAAa,iBA0Ce,mBAAmB,CAAC,WAAW;AAEpE;AACJ;AACA;AACA;AACA;AAJI,gBA5CS,aAAa,YAiDU,mBAAmB,CAAC,MAAM;AAE1D;AACJ;AACA;AAFI,gBAnDS,aAAa,aAsDW,mBAAmB,CAAC,OAAO;AAAA,gBAtDnD,aAAa","ignoreList":[]}
1
+ {"version":3,"file":"autodiscovery.js","names":[],"sources":["../src/autodiscovery.ts"],"sourcesContent":["/*\nCopyright 2018 New Vector Ltd\nCopyright 2019 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type IClientWellKnown, type IWellKnownConfig, type IServerVersions } from \"./client.ts\";\nimport { logger } from \"./logger.ts\";\nimport { type MatrixError, Method, timeoutSignal } from \"./http-api/index.ts\";\nimport { SUPPORTED_MATRIX_VERSIONS } from \"./version-support.ts\";\n\n// Dev note: Auto discovery is part of the spec.\n// See: https://matrix.org/docs/spec/client_server/r0.4.0.html#server-discovery\n\nexport enum AutoDiscoveryAction {\n SUCCESS = \"SUCCESS\",\n IGNORE = \"IGNORE\",\n PROMPT = \"PROMPT\",\n FAIL_PROMPT = \"FAIL_PROMPT\",\n FAIL_ERROR = \"FAIL_ERROR\",\n}\n\nexport enum AutoDiscoveryError {\n Invalid = \"Invalid homeserver discovery response\",\n GenericFailure = \"Failed to get autodiscovery configuration from server\",\n InvalidHsBaseUrl = \"Invalid base_url for m.homeserver\",\n InvalidHomeserver = \"Homeserver URL does not appear to be a valid Matrix homeserver\",\n InvalidIsBaseUrl = \"Invalid base_url for m.identity_server\",\n InvalidIdentityServer = \"Identity server URL does not appear to be a valid identity server\",\n InvalidIs = \"Invalid identity server discovery response\",\n MissingWellknown = \"No .well-known JSON file found\",\n InvalidJson = \"Invalid JSON\",\n UnsupportedHomeserverSpecVersion = \"The homeserver does not meet the version requirements\",\n\n // TODO: Implement when Sydent supports the `/versions` endpoint - https://github.com/matrix-org/sydent/issues/424\n //IdentityServerTooOld = \"The identity server does not meet the minimum version requirements\",\n}\n\ninterface AutoDiscoveryState {\n state: AutoDiscoveryAction;\n error?: IWellKnownConfig[\"error\"] | null;\n}\ninterface WellKnownConfig extends Omit<IWellKnownConfig, \"error\">, AutoDiscoveryState {}\n\nexport interface ClientConfig extends Omit<IClientWellKnown, \"m.homeserver\" | \"m.identity_server\"> {\n \"m.homeserver\": WellKnownConfig;\n \"m.identity_server\": WellKnownConfig;\n}\n\n/**\n * Utilities for automatically discovery resources, such as homeservers\n * for users to log in to.\n */\nexport class AutoDiscovery {\n // Dev note: the constants defined here are related to but not\n // exactly the same as those in the spec. This is to hopefully\n // translate the meaning of the states in the spec, but also\n // support our own if needed.\n\n public static readonly ERROR_INVALID = AutoDiscoveryError.Invalid;\n\n public static readonly ERROR_GENERIC_FAILURE = AutoDiscoveryError.GenericFailure;\n\n public static readonly ERROR_INVALID_HS_BASE_URL = AutoDiscoveryError.InvalidHsBaseUrl;\n\n public static readonly ERROR_INVALID_HOMESERVER = AutoDiscoveryError.InvalidHomeserver;\n\n public static readonly ERROR_INVALID_IS_BASE_URL = AutoDiscoveryError.InvalidIsBaseUrl;\n\n public static readonly ERROR_INVALID_IDENTITY_SERVER = AutoDiscoveryError.InvalidIdentityServer;\n\n public static readonly ERROR_INVALID_IS = AutoDiscoveryError.InvalidIs;\n\n public static readonly ERROR_MISSING_WELLKNOWN = AutoDiscoveryError.MissingWellknown;\n\n public static readonly ERROR_INVALID_JSON = AutoDiscoveryError.InvalidJson;\n\n public static readonly ERROR_UNSUPPORTED_HOMESERVER_SPEC_VERSION =\n AutoDiscoveryError.UnsupportedHomeserverSpecVersion;\n\n public static readonly ALL_ERRORS = Object.keys(AutoDiscoveryError) as AutoDiscoveryError[];\n\n /**\n * The auto discovery failed. The client is expected to communicate\n * the error to the user and refuse logging in.\n */\n public static readonly FAIL_ERROR = AutoDiscoveryAction.FAIL_ERROR;\n\n /**\n * The auto discovery failed, however the client may still recover\n * from the problem. The client is recommended to that the same\n * action it would for PROMPT while also warning the user about\n * what went wrong. The client may also treat this the same as\n * a FAIL_ERROR state.\n */\n public static readonly FAIL_PROMPT = AutoDiscoveryAction.FAIL_PROMPT;\n\n /**\n * The auto discovery didn't fail but did not find anything of\n * interest. The client is expected to prompt the user for more\n * information, or fail if it prefers.\n */\n public static readonly PROMPT = AutoDiscoveryAction.PROMPT;\n\n /**\n * The auto discovery was successful.\n */\n public static readonly SUCCESS = AutoDiscoveryAction.SUCCESS;\n\n /**\n * Validates and verifies client configuration information for purposes\n * of logging in. Such information includes the homeserver URL\n * and identity server URL the client would want. Additional details\n * may also be included, and will be transparently brought into the\n * response object unaltered.\n * @param wellknown - The configuration object itself, as returned\n * by the .well-known auto-discovery endpoint.\n * @returns Promise which resolves to the verified\n * configuration, which may include error states. Rejects on unexpected\n * failure, not when verification fails.\n */\n public static async fromDiscoveryConfig(wellknown?: IClientWellKnown): Promise<ClientConfig> {\n // Step 1 is to get the config, which is provided to us here.\n\n // We default to an error state to make the first few checks easier to\n // write. We'll update the properties of this object over the duration\n // of this function.\n const clientConfig: ClientConfig = {\n \"m.homeserver\": {\n state: AutoDiscovery.FAIL_ERROR,\n error: AutoDiscovery.ERROR_INVALID,\n base_url: null,\n },\n \"m.identity_server\": {\n // Technically, we don't have a problem with the identity server\n // config at this point.\n state: AutoDiscovery.PROMPT,\n error: null,\n base_url: null,\n },\n };\n\n if (!wellknown?.[\"m.homeserver\"]) {\n logger.error(\"No m.homeserver key in config\");\n\n clientConfig[\"m.homeserver\"].state = AutoDiscovery.FAIL_PROMPT;\n clientConfig[\"m.homeserver\"].error = AutoDiscovery.ERROR_INVALID;\n\n return Promise.resolve(clientConfig);\n }\n\n if (!wellknown[\"m.homeserver\"][\"base_url\"]) {\n logger.error(\"No m.homeserver base_url in config\");\n\n clientConfig[\"m.homeserver\"].state = AutoDiscovery.FAIL_PROMPT;\n clientConfig[\"m.homeserver\"].error = AutoDiscovery.ERROR_INVALID_HS_BASE_URL;\n\n return Promise.resolve(clientConfig);\n }\n\n // Step 2: Make sure the homeserver URL is valid *looking*. We'll make\n // sure it points to a homeserver in Step 3.\n const hsUrl = this.sanitizeWellKnownUrl(wellknown[\"m.homeserver\"][\"base_url\"]);\n if (!hsUrl) {\n logger.error(\"Invalid base_url for m.homeserver\");\n clientConfig[\"m.homeserver\"].error = AutoDiscovery.ERROR_INVALID_HS_BASE_URL;\n return Promise.resolve(clientConfig);\n }\n\n // Step 3: Make sure the homeserver URL points to a homeserver.\n const hsVersions = await this.fetchWellKnownObject<IServerVersions>(`${hsUrl}/_matrix/client/versions`);\n if (!hsVersions || !Array.isArray(hsVersions.raw?.[\"versions\"])) {\n logger.error(\"Invalid /versions response\");\n clientConfig[\"m.homeserver\"].error = AutoDiscovery.ERROR_INVALID_HOMESERVER;\n\n // Supply the base_url to the caller because they may be ignoring liveliness\n // errors, like this one.\n clientConfig[\"m.homeserver\"].base_url = hsUrl;\n\n return Promise.resolve(clientConfig);\n }\n\n // Step 3.1: Non-spec check to ensure the server will actually work for us. We need to check if\n // any of the versions in `SUPPORTED_MATRIX_VERSIONS` are listed in the /versions response.\n const hsVersionSet = new Set(hsVersions.raw[\"versions\"]);\n let supportedVersionFound = false;\n for (const version of SUPPORTED_MATRIX_VERSIONS) {\n if (hsVersionSet.has(version)) {\n supportedVersionFound = true;\n break;\n }\n }\n if (!supportedVersionFound) {\n logger.error(\"Homeserver does not meet version requirements\");\n clientConfig[\"m.homeserver\"].error = AutoDiscovery.ERROR_UNSUPPORTED_HOMESERVER_SPEC_VERSION;\n\n // Supply the base_url to the caller because they may be ignoring liveliness\n // errors, like this one.\n clientConfig[\"m.homeserver\"].base_url = hsUrl;\n\n return Promise.resolve(clientConfig);\n }\n\n // Step 4: Now that the homeserver looks valid, update our client config.\n clientConfig[\"m.homeserver\"] = {\n state: AutoDiscovery.SUCCESS,\n error: null,\n base_url: hsUrl,\n };\n\n // Step 5: Try to pull out the identity server configuration\n let isUrl: string | boolean = \"\";\n if (wellknown[\"m.identity_server\"]) {\n // We prepare a failing identity server response to save lines later\n // in this branch.\n const failingClientConfig: ClientConfig = {\n \"m.homeserver\": clientConfig[\"m.homeserver\"],\n \"m.identity_server\": {\n state: AutoDiscovery.FAIL_PROMPT,\n error: AutoDiscovery.ERROR_INVALID_IS,\n base_url: null,\n },\n };\n\n // Step 5a: Make sure the URL is valid *looking*. We'll make sure it\n // points to an identity server in Step 5b.\n isUrl = this.sanitizeWellKnownUrl(wellknown[\"m.identity_server\"][\"base_url\"]);\n if (!isUrl) {\n logger.error(\"Invalid base_url for m.identity_server\");\n failingClientConfig[\"m.identity_server\"].error = AutoDiscovery.ERROR_INVALID_IS_BASE_URL;\n return Promise.resolve(failingClientConfig);\n }\n\n // Step 5b: Verify there is an identity server listening on the provided\n // URL.\n const isResponse = await this.fetchWellKnownObject(`${isUrl}/_matrix/identity/v2`);\n if (!isResponse?.raw || isResponse.action !== AutoDiscoveryAction.SUCCESS) {\n logger.error(\"Invalid /v2 response\");\n failingClientConfig[\"m.identity_server\"].error = AutoDiscovery.ERROR_INVALID_IDENTITY_SERVER;\n\n // Supply the base_url to the caller because they may be ignoring\n // liveliness errors, like this one.\n failingClientConfig[\"m.identity_server\"].base_url = isUrl;\n\n return Promise.resolve(failingClientConfig);\n }\n }\n\n // Step 6: Now that the identity server is valid, or never existed,\n // populate the IS section.\n if (isUrl && isUrl.toString().length > 0) {\n clientConfig[\"m.identity_server\"] = {\n state: AutoDiscovery.SUCCESS,\n error: null,\n base_url: isUrl,\n };\n }\n\n // Step 7: Copy any other keys directly into the clientConfig. This is for\n // things like custom configuration of services.\n Object.keys(wellknown).forEach((k: keyof IClientWellKnown) => {\n if (k === \"m.homeserver\" || k === \"m.identity_server\") {\n // Only copy selected parts of the config to avoid overwriting\n // properties computed by the validation logic above.\n const notProps = [\"error\", \"state\", \"base_url\"];\n for (const prop of Object.keys(wellknown[k]!)) {\n if (notProps.includes(prop)) continue;\n type Prop = Exclude<keyof IWellKnownConfig, \"error\" | \"state\" | \"base_url\">;\n // @ts-ignore - ts gets unhappy as we're mixing types here\n clientConfig[k][prop as Prop] = wellknown[k]![prop as Prop];\n }\n } else {\n // Just copy the whole thing over otherwise\n clientConfig[k] = wellknown[k];\n }\n });\n\n // Step 8: Give the config to the caller (finally)\n return Promise.resolve(clientConfig);\n }\n\n /**\n * Attempts to automatically discover client configuration information\n * prior to logging in. Such information includes the homeserver URL\n * and identity server URL the client would want. Additional details\n * may also be discovered, and will be transparently included in the\n * response object unaltered.\n * @param domain - The homeserver domain to perform discovery\n * on. For example, \"matrix.org\".\n * @returns Promise which resolves to the discovered\n * configuration, which may include error states. Rejects on unexpected\n * failure, not when discovery fails.\n */\n public static async findClientConfig(domain: string): Promise<ClientConfig> {\n if (!domain || typeof domain !== \"string\" || domain.length === 0) {\n throw new Error(\"'domain' must be a string of non-zero length\");\n }\n\n // We use a .well-known lookup for all cases. According to the spec, we\n // can do other discovery mechanisms if we want such as custom lookups\n // however we won't bother with that here (mostly because the spec only\n // supports .well-known right now).\n //\n // By using .well-known, we need to ensure we at least pull out a URL\n // for the homeserver. We don't really need an identity server configuration\n // but will return one anyways (with state PROMPT) to make development\n // easier for clients. If we can't get a homeserver URL, all bets are\n // off on the rest of the config and we'll assume it is invalid too.\n\n // We default to an error state to make the first few checks easier to\n // write. We'll update the properties of this object over the duration\n // of this function.\n const clientConfig: ClientConfig = {\n \"m.homeserver\": {\n state: AutoDiscovery.FAIL_ERROR,\n error: AutoDiscovery.ERROR_INVALID,\n base_url: null,\n },\n \"m.identity_server\": {\n // Technically, we don't have a problem with the identity server\n // config at this point.\n state: AutoDiscovery.PROMPT,\n error: null,\n base_url: null,\n },\n };\n\n // Step 1: Actually request the .well-known JSON file and make sure it\n // at least has a homeserver definition.\n const domainWithProtocol = domain.includes(\"://\") ? domain : `https://${domain}`;\n const wellknown = await this.fetchWellKnownObject(`${domainWithProtocol}/.well-known/matrix/client`);\n if (!wellknown || wellknown.action !== AutoDiscoveryAction.SUCCESS) {\n logger.error(\"No response or error when parsing .well-known\");\n if (wellknown.reason) logger.error(wellknown.reason);\n if (wellknown.action === AutoDiscoveryAction.IGNORE) {\n clientConfig[\"m.homeserver\"] = {\n state: AutoDiscovery.PROMPT,\n error: null,\n base_url: null,\n };\n } else {\n // this can only ever be FAIL_PROMPT at this point.\n clientConfig[\"m.homeserver\"].state = AutoDiscovery.FAIL_PROMPT;\n clientConfig[\"m.homeserver\"].error = AutoDiscovery.ERROR_INVALID;\n }\n return Promise.resolve(clientConfig);\n }\n\n // Step 2: Validate and parse the config\n return AutoDiscovery.fromDiscoveryConfig(wellknown.raw);\n }\n\n /**\n * Gets the raw discovery client configuration for the given domain name.\n * Should only be used if there's no validation to be done on the resulting\n * object, otherwise use findClientConfig().\n * @param domain - The domain to get the client config for.\n * @returns Promise which resolves to the domain's client config. Can\n * be an empty object.\n */\n public static async getRawClientConfig(domain?: string): Promise<IClientWellKnown> {\n if (!domain || typeof domain !== \"string\" || domain.length === 0) {\n throw new Error(\"'domain' must be a string of non-zero length\");\n }\n\n const response = await this.fetchWellKnownObject(`https://${domain}/.well-known/matrix/client`);\n if (!response) return {};\n return response.raw ?? {};\n }\n\n /**\n * Sanitizes a given URL to ensure it is either an HTTP or HTTP URL and\n * is suitable for the requirements laid out by .well-known auto discovery.\n * If valid, the URL will also be stripped of any trailing slashes.\n * @param url - The potentially invalid URL to sanitize.\n * @returns The sanitized URL or a falsey value if the URL is invalid.\n * @internal\n */\n private static sanitizeWellKnownUrl(url?: string | null): string | false {\n if (!url) return false;\n\n try {\n let parsed: URL | undefined;\n try {\n parsed = new URL(url);\n } catch (e) {\n logger.error(\"Could not parse url\", e);\n }\n\n if (!parsed?.hostname) return false;\n if (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") return false;\n\n const port = parsed.port ? `:${parsed.port}` : \"\";\n const path = parsed.pathname ? parsed.pathname : \"\";\n let saferUrl = `${parsed.protocol}//${parsed.hostname}${port}${path}`;\n if (saferUrl.endsWith(\"/\")) {\n saferUrl = saferUrl.substring(0, saferUrl.length - 1);\n }\n return saferUrl;\n } catch (e) {\n logger.error(e);\n return false;\n }\n }\n\n private static fetch(resource: URL | string, options?: RequestInit): ReturnType<typeof globalThis.fetch> {\n if (this.fetchFn) {\n return this.fetchFn(resource, options);\n }\n return globalThis.fetch(resource, options);\n }\n\n private static fetchFn?: typeof globalThis.fetch;\n\n public static setFetchFn(fetchFn: typeof globalThis.fetch): void {\n AutoDiscovery.fetchFn = fetchFn;\n }\n\n /**\n * Fetches a JSON object from a given URL, as expected by all .well-known\n * related lookups. If the server gives a 404 then the `action` will be\n * IGNORE. If the server returns something that isn't JSON, the `action`\n * will be FAIL_PROMPT. For any other failure the `action` will be FAIL_PROMPT.\n *\n * The returned object will be a result of the call in object form with\n * the following properties:\n * raw: The JSON object returned by the server.\n * action: One of SUCCESS, IGNORE, or FAIL_PROMPT.\n * reason: Relatively human-readable description of what went wrong.\n * error: The actual Error, if one exists.\n * @param url - The URL to fetch a JSON object from.\n * @returns Promise which resolves to the returned state.\n * @internal\n */\n private static async fetchWellKnownObject<T = IWellKnownConfig>(\n url: string,\n ): Promise<IWellKnownConfig<Partial<T>>> {\n let response: Response;\n\n try {\n response = await AutoDiscovery.fetch(url, {\n method: Method.Get,\n signal: timeoutSignal(5000),\n });\n\n if (response.status === 404) {\n return {\n raw: {},\n action: AutoDiscoveryAction.IGNORE,\n reason: AutoDiscovery.ERROR_MISSING_WELLKNOWN,\n };\n }\n\n if (response.status !== 200) {\n return {\n raw: {},\n action: AutoDiscoveryAction.FAIL_PROMPT,\n reason: \"General failure\",\n };\n }\n } catch (err) {\n const error = err as AutoDiscoveryError | string | undefined;\n let reason = \"\";\n if (typeof error === \"object\") {\n reason = (<Error>error)?.message;\n }\n\n return {\n error,\n raw: {},\n action: AutoDiscoveryAction.FAIL_PROMPT,\n reason: reason || \"General failure\",\n };\n }\n\n try {\n return {\n raw: await response.json(),\n action: AutoDiscoveryAction.SUCCESS,\n };\n } catch (err) {\n const error = err as Error;\n return {\n error,\n raw: {},\n action: AutoDiscoveryAction.FAIL_PROMPT,\n reason:\n (error as MatrixError)?.name === \"SyntaxError\"\n ? AutoDiscovery.ERROR_INVALID_JSON\n : AutoDiscovery.ERROR_INVALID,\n };\n }\n }\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAAS,MAAM,QAAQ,aAAa;AACpC,SAA2B,MAAM,EAAE,aAAa,QAAQ,qBAAqB;AAC7E,SAAS,yBAAyB,QAAQ,sBAAsB;;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jE,aAAa,+CAyBlB,kBAAkB,CAAC,gCAAgC;AAAA,gBAzB9C,aAAa,gBA2Bc,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC;AAEnE;AACJ;AACA;AACA;AAHI,gBA7BS,aAAa,gBAiCc,mBAAmB,CAAC,UAAU;AAElE;AACJ;AACA;AACA;AACA;AACA;AACA;AANI,gBAnCS,aAAa,iBA0Ce,mBAAmB,CAAC,WAAW;AAEpE;AACJ;AACA;AACA;AACA;AAJI,gBA5CS,aAAa,YAiDU,mBAAmB,CAAC,MAAM;AAE1D;AACJ;AACA;AAFI,gBAnDS,aAAa,aAsDW,mBAAmB,CAAC,OAAO;AAAA,gBAtDnD,aAAa","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"browser-index.js","names":[],"sources":["../src/browser-index.ts"],"sourcesContent":["/*\nCopyright 2019 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as sdk from \"./matrix.ts\";\n\ntype BrowserMatrix = typeof sdk;\ndeclare global {\n var __js_sdk_entrypoint: boolean;\n var matrixcs: BrowserMatrix;\n}\n\nif (globalThis.__js_sdk_entrypoint) {\n throw new Error(\"Multiple matrix-js-sdk entrypoints detected!\");\n}\nglobalThis.__js_sdk_entrypoint = true;\n\n// just *accessing* indexedDB throws an exception in firefox with indexeddb disabled.\nlet indexedDB: IDBFactory | undefined;\ntry {\n indexedDB = globalThis.indexedDB;\n} catch {\n // Do nothing\n}\n\n// if our browser (appears to) support indexeddb, use an indexeddb crypto store.\nif (indexedDB) {\n sdk.setCryptoStoreFactory(() => new sdk.IndexedDBCryptoStore(indexedDB!, \"matrix-js-sdk:crypto\"));\n}\n\nexport * from \"./matrix.ts\";\nglobalThis.matrixcs = sdk;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,KAAK,GAAG,MAAM,aAAa;AAQlC,IAAI,UAAU,CAAC,mBAAmB,EAAE;EAChC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC;AACnE;AACA,UAAU,CAAC,mBAAmB,GAAG,IAAI;;AAErC;AACA,IAAI,SAAiC;AACrC,IAAI;EACA,SAAS,GAAG,UAAU,CAAC,SAAS;AACpC,CAAC,CAAC,MAAM;EACJ;AAAA;;AAGJ;AACA,IAAI,SAAS,EAAE;EACX,GAAG,CAAC,qBAAqB,CAAC,MAAM,IAAI,GAAG,CAAC,oBAAoB,CAAC,SAAS,EAAG,sBAAsB,CAAC,CAAC;AACrG;AAEA,cAAc,aAAa;AAC3B,UAAU,CAAC,QAAQ,GAAG,GAAG","ignoreList":[]}
1
+ {"version":3,"file":"browser-index.js","names":[],"sources":["../src/browser-index.ts"],"sourcesContent":["/*\nCopyright 2019 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as sdk from \"./matrix.ts\";\n\ntype BrowserMatrix = typeof sdk;\ndeclare global {\n var __js_sdk_entrypoint: boolean;\n var matrixcs: BrowserMatrix;\n}\n\nif (globalThis.__js_sdk_entrypoint) {\n throw new Error(\"Multiple matrix-js-sdk entrypoints detected!\");\n}\nglobalThis.__js_sdk_entrypoint = true;\n\n// just *accessing* indexedDB throws an exception in firefox with indexeddb disabled.\nlet indexedDB: IDBFactory | undefined;\ntry {\n indexedDB = globalThis.indexedDB;\n} catch {\n // Do nothing\n}\n\n// if our browser (appears to) support indexeddb, use an indexeddb crypto store.\nif (indexedDB) {\n sdk.setCryptoStoreFactory(() => new sdk.IndexedDBCryptoStore(indexedDB, \"matrix-js-sdk:crypto\"));\n}\n\nexport * from \"./matrix.ts\";\nglobalThis.matrixcs = sdk;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,KAAK,GAAG,MAAM,aAAa;AAQlC,IAAI,UAAU,CAAC,mBAAmB,EAAE;EAChC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC;AACnE;AACA,UAAU,CAAC,mBAAmB,GAAG,IAAI;;AAErC;AACA,IAAI,SAAiC;AACrC,IAAI;EACA,SAAS,GAAG,UAAU,CAAC,SAAS;AACpC,CAAC,CAAC,MAAM;EACJ;AAAA;;AAGJ;AACA,IAAI,SAAS,EAAE;EACX,GAAG,CAAC,qBAAqB,CAAC,MAAM,IAAI,GAAG,CAAC,oBAAoB,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC;AACpG;AAEA,cAAc,aAAa;AAC3B,UAAU,CAAC,QAAQ,GAAG,GAAG","ignoreList":[]}
package/lib/client.d.ts CHANGED
@@ -65,6 +65,7 @@ import { type ValidatedAuthMetadata } from "./oauth/index.ts";
65
65
  import { type EmptyObject } from "./@types/common.ts";
66
66
  import { type Transport } from "./matrixrtc/index.ts";
67
67
  import { RetentionPolicyService } from "./retentionPolicy.ts";
68
+ import { type PollingCachedValue } from "./pollingCachedValue.ts";
68
69
  export type Store = IStore;
69
70
  export type ResetTimelineCallback = (roomId: string) => boolean;
70
71
  export interface IKeysUploadResponse {
@@ -789,7 +790,8 @@ export declare enum ClientEvent {
789
790
  ReceivedVoipEvent = "received_voip_event",
790
791
  TurnServers = "turnServers",
791
792
  TurnServersError = "turnServers.error",
792
- UserProfileUpdate = "userProfileUpdate"
793
+ UserProfileUpdate = "userProfileUpdate",
794
+ RtcTransportsUpdated = "rtcTransportsUpdated"
793
795
  }
794
796
  type RoomEvents = RoomEvent.Name | RoomEvent.Redaction | RoomEvent.RedactionCancelled | RoomEvent.Receipt | RoomEvent.Tags | RoomEvent.LocalEchoUpdated | RoomEvent.HistoryImportedWithinTimeline | RoomEvent.AccountData | RoomEvent.MyMembership | RoomEvent.Timeline | RoomEvent.TimelineReset;
795
797
  type RoomStateEvents = RoomStateEvent.Events | RoomStateEvent.Members | RoomStateEvent.NewMember | RoomStateEvent.Update | RoomStateEvent.Marker;
@@ -811,6 +813,7 @@ export type ClientEventHandlerMap = {
811
813
  [ClientEvent.ReceivedVoipEvent]: (event: MatrixEvent) => void;
812
814
  [ClientEvent.TurnServers]: (servers: ITurnServer[]) => void;
813
815
  [ClientEvent.TurnServersError]: (error: Error, fatal: boolean) => void;
816
+ [ClientEvent.RtcTransportsUpdated]: (transports: Transport[]) => void;
814
817
  /**
815
818
  *
816
819
  * @param userId - the user ID of the profile which was updated
@@ -904,13 +907,10 @@ export declare class MatrixClient extends TypedEventEmitter<EmittedEvents, Clien
904
907
  protected syncLeftRoomsPromise?: Promise<Room[]>;
905
908
  protected syncedLeftRooms: boolean;
906
909
  protected clientOpts?: IStoredClientOpts;
907
- protected clientWellKnownIntervalID?: ReturnType<typeof setInterval>;
908
910
  protected canResetTimelineCallback?: ResetTimelineCallback;
909
911
  canSupport: Map<Feature, ServerSupport>;
910
912
  readonly pushProcessor: PushProcessor;
911
913
  protected serverVersionsPromise?: Promise<IServerVersions>;
912
- protected clientWellKnown?: IClientWellKnown;
913
- protected clientWellKnownPromise?: Promise<IClientWellKnown>;
914
914
  protected turnServers: ITurnServer[];
915
915
  protected turnServersExpiry: number;
916
916
  protected checkTurnServersIntervalID?: ReturnType<typeof setInterval>;
@@ -932,6 +932,8 @@ export declare class MatrixClient extends TypedEventEmitter<EmittedEvents, Clien
932
932
  private serverCapabilitiesService;
933
933
  readonly retentionPolicyService: RetentionPolicyService;
934
934
  readonly _unstable_shouldApplyMessageRetention: boolean;
935
+ cachedRtcTransports: PollingCachedValue<Transport[]>;
936
+ protected cachedWellKnown: PollingCachedValue<IClientWellKnown>;
935
937
  constructor(opts: IMatrixClientCreateOpts);
936
938
  set store(newStore: Store);
937
939
  get store(): Store;
@@ -1149,6 +1151,11 @@ export declare class MatrixClient extends TypedEventEmitter<EmittedEvents, Clien
1149
1151
  * @param args.storagePassword - An alternative to `storageKey`. A password which will be used to derive a key to
1150
1152
  * encrypt the store with. Deriving a key from a password is (deliberately) a slow operation, so prefer
1151
1153
  * to pass a `storageKey` directly where possible.
1154
+ * @param args.caCertsPem - Optional PEM-formatted string that provides CA certificates. These will be used to check
1155
+ * X.509 signatures on user identities. Any user identity that has a valid signature according to the supplied
1156
+ * CAs will be considered verified, without any manual verification taking place.
1157
+ *
1158
+ * NOTE: this is an unspecified extension to Matrix. Applications should exercise caution when using it.
1152
1159
  *
1153
1160
  * @returns a Promise which will resolve when the crypto layer has been
1154
1161
  * successfully initialised.
@@ -1158,6 +1165,7 @@ export declare class MatrixClient extends TypedEventEmitter<EmittedEvents, Clien
1158
1165
  cryptoDatabasePrefix?: string;
1159
1166
  storageKey?: Uint8Array;
1160
1167
  storagePassword?: string;
1168
+ caCertsPem?: string;
1161
1169
  }): Promise<void>;
1162
1170
  /**
1163
1171
  * Access the server-side secret storage API for this client.
@@ -2249,7 +2257,6 @@ export declare class MatrixClient extends TypedEventEmitter<EmittedEvents, Clien
2249
2257
  * @returns the deactivate response - see Synapse docs for information.
2250
2258
  */
2251
2259
  deactivateSynapseUser(userId: string): Promise<ISynapseAdminDeactivateResponse>;
2252
- protected fetchClientWellKnown(): Promise<void>;
2253
2260
  getClientWellKnown(): IClientWellKnown | undefined;
2254
2261
  waitForClientWellKnown(): Promise<IClientWellKnown>;
2255
2262
  /**