@jeongsu816/matrix-bot-sdk 0.0.0-stage → 0.8.1

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 (377) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -2
  3. package/lib/AdminApis.d.ts +52 -0
  4. package/lib/AdminApis.js +29 -0
  5. package/lib/AdminApis.js.map +1 -0
  6. package/lib/DMs.d.ts +48 -0
  7. package/lib/DMs.js +160 -0
  8. package/lib/DMs.js.map +1 -0
  9. package/lib/IFilter.d.ts +7 -0
  10. package/lib/IFilter.js +3 -0
  11. package/lib/IFilter.js.map +1 -0
  12. package/lib/MatrixAuth.d.ts +45 -0
  13. package/lib/MatrixAuth.js +125 -0
  14. package/lib/MatrixAuth.js.map +1 -0
  15. package/lib/MatrixClient.d.ts +834 -0
  16. package/lib/MatrixClient.js +2268 -0
  17. package/lib/MatrixClient.js.map +1 -0
  18. package/lib/PantalaimonClient.d.ts +42 -0
  19. package/lib/PantalaimonClient.js +44 -0
  20. package/lib/PantalaimonClient.js.map +1 -0
  21. package/lib/SynapseAdminApis.d.ts +350 -0
  22. package/lib/SynapseAdminApis.js +244 -0
  23. package/lib/SynapseAdminApis.js.map +1 -0
  24. package/lib/SynchronousMatrixClient.d.ts +82 -0
  25. package/lib/SynchronousMatrixClient.js +130 -0
  26. package/lib/SynchronousMatrixClient.js.map +1 -0
  27. package/lib/UnstableApis.d.ts +43 -0
  28. package/lib/UnstableApis.js +74 -0
  29. package/lib/UnstableApis.js.map +1 -0
  30. package/lib/appservice/Appservice.d.ts +328 -0
  31. package/lib/appservice/Appservice.js +803 -0
  32. package/lib/appservice/Appservice.js.map +1 -0
  33. package/lib/appservice/Intent.d.ts +113 -0
  34. package/lib/appservice/Intent.js +363 -0
  35. package/lib/appservice/Intent.js.map +1 -0
  36. package/lib/appservice/MatrixBridge.d.ts +85 -0
  37. package/lib/appservice/MatrixBridge.js +111 -0
  38. package/lib/appservice/MatrixBridge.js.map +1 -0
  39. package/lib/appservice/UnstableAppserviceApis.d.ts +41 -0
  40. package/lib/appservice/UnstableAppserviceApis.js +62 -0
  41. package/lib/appservice/UnstableAppserviceApis.js.map +1 -0
  42. package/lib/appservice/http_responses.d.ts +77 -0
  43. package/lib/appservice/http_responses.js +3 -0
  44. package/lib/appservice/http_responses.js.map +1 -0
  45. package/lib/b64.d.ts +42 -0
  46. package/lib/b64.js +68 -0
  47. package/lib/b64.js.map +1 -0
  48. package/lib/e2ee/CrossSigningBootstrap.d.ts +73 -0
  49. package/lib/e2ee/CrossSigningBootstrap.js +86 -0
  50. package/lib/e2ee/CrossSigningBootstrap.js.map +1 -0
  51. package/lib/e2ee/CryptoClient.d.ts +163 -0
  52. package/lib/e2ee/CryptoClient.js +382 -0
  53. package/lib/e2ee/CryptoClient.js.map +1 -0
  54. package/lib/e2ee/ICryptoRoomInformation.d.ts +8 -0
  55. package/lib/e2ee/ICryptoRoomInformation.js +3 -0
  56. package/lib/e2ee/ICryptoRoomInformation.js.map +1 -0
  57. package/lib/e2ee/RoomTracker.d.ts +41 -0
  58. package/lib/e2ee/RoomTracker.js +96 -0
  59. package/lib/e2ee/RoomTracker.js.map +1 -0
  60. package/lib/e2ee/RustEngine.d.ts +149 -0
  61. package/lib/e2ee/RustEngine.js +467 -0
  62. package/lib/e2ee/RustEngine.js.map +1 -0
  63. package/lib/e2ee/decorators.d.ts +10 -0
  64. package/lib/e2ee/decorators.js +37 -0
  65. package/lib/e2ee/decorators.js.map +1 -0
  66. package/lib/helpers/MatrixEntity.d.ts +37 -0
  67. package/lib/helpers/MatrixEntity.js +67 -0
  68. package/lib/helpers/MatrixEntity.js.map +1 -0
  69. package/lib/helpers/MatrixGlob.d.ts +22 -0
  70. package/lib/helpers/MatrixGlob.js +35 -0
  71. package/lib/helpers/MatrixGlob.js.map +1 -0
  72. package/lib/helpers/MentionPill.d.ts +40 -0
  73. package/lib/helpers/MentionPill.js +91 -0
  74. package/lib/helpers/MentionPill.js.map +1 -0
  75. package/lib/helpers/Permalinks.d.ts +58 -0
  76. package/lib/helpers/Permalinks.js +73 -0
  77. package/lib/helpers/Permalinks.js.map +1 -0
  78. package/lib/helpers/ProfileCache.d.ts +48 -0
  79. package/lib/helpers/ProfileCache.js +114 -0
  80. package/lib/helpers/ProfileCache.js.map +1 -0
  81. package/lib/helpers/RichReply.d.ts +17 -0
  82. package/lib/helpers/RichReply.js +47 -0
  83. package/lib/helpers/RichReply.js.map +1 -0
  84. package/lib/helpers/UnpaddedBase64.d.ts +31 -0
  85. package/lib/helpers/UnpaddedBase64.js +45 -0
  86. package/lib/helpers/UnpaddedBase64.js.map +1 -0
  87. package/lib/http.d.ts +17 -0
  88. package/lib/http.js +147 -0
  89. package/lib/http.js.map +1 -0
  90. package/lib/identity/IdentityClient.d.ts +93 -0
  91. package/lib/identity/IdentityClient.js +248 -0
  92. package/lib/identity/IdentityClient.js.map +1 -0
  93. package/lib/index.d.ts +91 -0
  94. package/lib/index.js +125 -0
  95. package/lib/index.js.map +1 -0
  96. package/lib/logging/ConsoleLogger.d.ts +12 -0
  97. package/lib/logging/ConsoleLogger.js +28 -0
  98. package/lib/logging/ConsoleLogger.js.map +1 -0
  99. package/lib/logging/ILogger.d.ts +36 -0
  100. package/lib/logging/ILogger.js +3 -0
  101. package/lib/logging/ILogger.js.map +1 -0
  102. package/lib/logging/LogService.d.ts +100 -0
  103. package/lib/logging/LogService.js +169 -0
  104. package/lib/logging/LogService.js.map +1 -0
  105. package/lib/logging/RichConsoleLogger.d.ts +20 -0
  106. package/lib/logging/RichConsoleLogger.js +41 -0
  107. package/lib/logging/RichConsoleLogger.js.map +1 -0
  108. package/lib/metrics/IMetricListener.d.ts +52 -0
  109. package/lib/metrics/IMetricListener.js +3 -0
  110. package/lib/metrics/IMetricListener.js.map +1 -0
  111. package/lib/metrics/Metrics.d.ts +66 -0
  112. package/lib/metrics/Metrics.js +128 -0
  113. package/lib/metrics/Metrics.js.map +1 -0
  114. package/lib/metrics/contexts.d.ts +51 -0
  115. package/lib/metrics/contexts.js +3 -0
  116. package/lib/metrics/contexts.js.map +1 -0
  117. package/lib/metrics/decorators.d.ts +15 -0
  118. package/lib/metrics/decorators.js +92 -0
  119. package/lib/metrics/decorators.js.map +1 -0
  120. package/lib/metrics/names.d.ts +45 -0
  121. package/lib/metrics/names.js +49 -0
  122. package/lib/metrics/names.js.map +1 -0
  123. package/lib/mixins/AutojoinRoomsMixin.d.ts +10 -0
  124. package/lib/mixins/AutojoinRoomsMixin.js +25 -0
  125. package/lib/mixins/AutojoinRoomsMixin.js.map +1 -0
  126. package/lib/mixins/AutojoinUpgradedRoomsMixin.d.ts +10 -0
  127. package/lib/mixins/AutojoinUpgradedRoomsMixin.js +40 -0
  128. package/lib/mixins/AutojoinUpgradedRoomsMixin.js.map +1 -0
  129. package/lib/models/Account.d.ts +8 -0
  130. package/lib/models/Account.js +3 -0
  131. package/lib/models/Account.js.map +1 -0
  132. package/lib/models/CreateRoom.d.ts +125 -0
  133. package/lib/models/CreateRoom.js +3 -0
  134. package/lib/models/CreateRoom.js.map +1 -0
  135. package/lib/models/Crypto.d.ts +167 -0
  136. package/lib/models/Crypto.js +31 -0
  137. package/lib/models/Crypto.js.map +1 -0
  138. package/lib/models/EventContext.d.ts +19 -0
  139. package/lib/models/EventContext.js +3 -0
  140. package/lib/models/EventContext.js.map +1 -0
  141. package/lib/models/IdentityServerModels.d.ts +20 -0
  142. package/lib/models/IdentityServerModels.js +3 -0
  143. package/lib/models/IdentityServerModels.js.map +1 -0
  144. package/lib/models/MSC2176.d.ts +42 -0
  145. package/lib/models/MSC2176.js +3 -0
  146. package/lib/models/MSC2176.js.map +1 -0
  147. package/lib/models/MatrixError.d.ts +38 -0
  148. package/lib/models/MatrixError.js +30 -0
  149. package/lib/models/MatrixError.js.map +1 -0
  150. package/lib/models/MatrixProfile.d.ts +43 -0
  151. package/lib/models/MatrixProfile.js +43 -0
  152. package/lib/models/MatrixProfile.js.map +1 -0
  153. package/lib/models/OpenIDConnect.d.ts +10 -0
  154. package/lib/models/OpenIDConnect.js +3 -0
  155. package/lib/models/OpenIDConnect.js.map +1 -0
  156. package/lib/models/Policies.d.ts +25 -0
  157. package/lib/models/Policies.js +3 -0
  158. package/lib/models/Policies.js.map +1 -0
  159. package/lib/models/PowerLevelAction.d.ts +27 -0
  160. package/lib/models/PowerLevelAction.js +32 -0
  161. package/lib/models/PowerLevelAction.js.map +1 -0
  162. package/lib/models/PowerLevelBounds.d.ts +15 -0
  163. package/lib/models/PowerLevelBounds.js +3 -0
  164. package/lib/models/PowerLevelBounds.js.map +1 -0
  165. package/lib/models/Presence.d.ts +25 -0
  166. package/lib/models/Presence.js +38 -0
  167. package/lib/models/Presence.js.map +1 -0
  168. package/lib/models/ServerVersions.d.ts +8 -0
  169. package/lib/models/ServerVersions.js +3 -0
  170. package/lib/models/ServerVersions.js.map +1 -0
  171. package/lib/models/Spaces.d.ts +116 -0
  172. package/lib/models/Spaces.js +91 -0
  173. package/lib/models/Spaces.js.map +1 -0
  174. package/lib/models/Threepid.d.ts +8 -0
  175. package/lib/models/Threepid.js +3 -0
  176. package/lib/models/Threepid.js.map +1 -0
  177. package/lib/models/events/AliasesEvent.d.ts +27 -0
  178. package/lib/models/events/AliasesEvent.js +27 -0
  179. package/lib/models/events/AliasesEvent.js.map +1 -0
  180. package/lib/models/events/CanonicalAliasEvent.d.ts +23 -0
  181. package/lib/models/events/CanonicalAliasEvent.js +21 -0
  182. package/lib/models/events/CanonicalAliasEvent.js.map +1 -0
  183. package/lib/models/events/CreateEvent.d.ts +63 -0
  184. package/lib/models/events/CreateEvent.js +33 -0
  185. package/lib/models/events/CreateEvent.js.map +1 -0
  186. package/lib/models/events/EncryptedRoomEvent.d.ts +42 -0
  187. package/lib/models/events/EncryptedRoomEvent.js +28 -0
  188. package/lib/models/events/EncryptedRoomEvent.js.map +1 -0
  189. package/lib/models/events/EncryptionEvent.d.ts +47 -0
  190. package/lib/models/events/EncryptionEvent.js +42 -0
  191. package/lib/models/events/EncryptionEvent.js.map +1 -0
  192. package/lib/models/events/Event.d.ts +26 -0
  193. package/lib/models/events/Event.js +40 -0
  194. package/lib/models/events/Event.js.map +1 -0
  195. package/lib/models/events/EventKind.d.ts +15 -0
  196. package/lib/models/events/EventKind.js +20 -0
  197. package/lib/models/events/EventKind.js.map +1 -0
  198. package/lib/models/events/InvalidEventError.d.ts +14 -0
  199. package/lib/models/events/InvalidEventError.js +24 -0
  200. package/lib/models/events/InvalidEventError.js.map +1 -0
  201. package/lib/models/events/JoinRulesEvent.d.ts +29 -0
  202. package/lib/models/events/JoinRulesEvent.js +21 -0
  203. package/lib/models/events/JoinRulesEvent.js.map +1 -0
  204. package/lib/models/events/MembershipEvent.d.ts +54 -0
  205. package/lib/models/events/MembershipEvent.js +49 -0
  206. package/lib/models/events/MembershipEvent.js.map +1 -0
  207. package/lib/models/events/MessageEvent.d.ts +233 -0
  208. package/lib/models/events/MessageEvent.js +49 -0
  209. package/lib/models/events/MessageEvent.js.map +1 -0
  210. package/lib/models/events/PinnedEventsEvent.d.ts +23 -0
  211. package/lib/models/events/PinnedEventsEvent.js +21 -0
  212. package/lib/models/events/PinnedEventsEvent.js.map +1 -0
  213. package/lib/models/events/PowerLevelsEvent.d.ts +96 -0
  214. package/lib/models/events/PowerLevelsEvent.js +70 -0
  215. package/lib/models/events/PowerLevelsEvent.js.map +1 -0
  216. package/lib/models/events/PresenceEvent.d.ts +56 -0
  217. package/lib/models/events/PresenceEvent.js +21 -0
  218. package/lib/models/events/PresenceEvent.js.map +1 -0
  219. package/lib/models/events/RedactionEvent.d.ts +28 -0
  220. package/lib/models/events/RedactionEvent.js +36 -0
  221. package/lib/models/events/RedactionEvent.js.map +1 -0
  222. package/lib/models/events/RoomAvatarEvent.d.ts +28 -0
  223. package/lib/models/events/RoomAvatarEvent.js +21 -0
  224. package/lib/models/events/RoomAvatarEvent.js.map +1 -0
  225. package/lib/models/events/RoomEvent.d.ts +58 -0
  226. package/lib/models/events/RoomEvent.js +57 -0
  227. package/lib/models/events/RoomEvent.js.map +1 -0
  228. package/lib/models/events/RoomNameEvent.d.ts +20 -0
  229. package/lib/models/events/RoomNameEvent.js +21 -0
  230. package/lib/models/events/RoomNameEvent.js.map +1 -0
  231. package/lib/models/events/RoomTopicEvent.d.ts +20 -0
  232. package/lib/models/events/RoomTopicEvent.js +21 -0
  233. package/lib/models/events/RoomTopicEvent.js.map +1 -0
  234. package/lib/models/events/SpaceChildEvent.d.ts +53 -0
  235. package/lib/models/events/SpaceChildEvent.js +49 -0
  236. package/lib/models/events/SpaceChildEvent.js.map +1 -0
  237. package/lib/models/events/converter.d.ts +8 -0
  238. package/lib/models/events/converter.js +50 -0
  239. package/lib/models/events/converter.js.map +1 -0
  240. package/lib/models/unstable/MediaInfo.d.ts +16 -0
  241. package/lib/models/unstable/MediaInfo.js +3 -0
  242. package/lib/models/unstable/MediaInfo.js.map +1 -0
  243. package/lib/preprocessors/IPreprocessor.d.ts +22 -0
  244. package/lib/preprocessors/IPreprocessor.js +3 -0
  245. package/lib/preprocessors/IPreprocessor.js.map +1 -0
  246. package/lib/preprocessors/RichRepliesPreprocessor.d.ts +67 -0
  247. package/lib/preprocessors/RichRepliesPreprocessor.js +112 -0
  248. package/lib/preprocessors/RichRepliesPreprocessor.js.map +1 -0
  249. package/lib/request.d.ts +13 -0
  250. package/lib/request.js +23 -0
  251. package/lib/request.js.map +1 -0
  252. package/lib/simple-validation.d.ts +10 -0
  253. package/lib/simple-validation.js +30 -0
  254. package/lib/simple-validation.js.map +1 -0
  255. package/lib/storage/IAppserviceStorageProvider.d.ts +48 -0
  256. package/lib/storage/IAppserviceStorageProvider.js +3 -0
  257. package/lib/storage/IAppserviceStorageProvider.js.map +1 -0
  258. package/lib/storage/ICryptoStorageProvider.d.ts +32 -0
  259. package/lib/storage/ICryptoStorageProvider.js +3 -0
  260. package/lib/storage/ICryptoStorageProvider.js.map +1 -0
  261. package/lib/storage/IStorageProvider.d.ts +47 -0
  262. package/lib/storage/IStorageProvider.js +3 -0
  263. package/lib/storage/IStorageProvider.js.map +1 -0
  264. package/lib/storage/MemoryStorageProvider.d.ts +26 -0
  265. package/lib/storage/MemoryStorageProvider.js +55 -0
  266. package/lib/storage/MemoryStorageProvider.js.map +1 -0
  267. package/lib/storage/RustSdkCryptoStorageProvider.d.ts +38 -0
  268. package/lib/storage/RustSdkCryptoStorageProvider.js +69 -0
  269. package/lib/storage/RustSdkCryptoStorageProvider.js.map +1 -0
  270. package/lib/storage/SimpleFsStorageProvider.d.ts +31 -0
  271. package/lib/storage/SimpleFsStorageProvider.js +122 -0
  272. package/lib/storage/SimpleFsStorageProvider.js.map +1 -0
  273. package/lib/storage/SimplePostgresStorageProvider.d.ts +32 -0
  274. package/lib/storage/SimplePostgresStorageProvider.js +148 -0
  275. package/lib/storage/SimplePostgresStorageProvider.js.map +1 -0
  276. package/lib/strategies/AppserviceJoinRoomStrategy.d.ts +14 -0
  277. package/lib/strategies/AppserviceJoinRoomStrategy.js +54 -0
  278. package/lib/strategies/AppserviceJoinRoomStrategy.js.map +1 -0
  279. package/lib/strategies/JoinRoomStrategy.d.ts +11 -0
  280. package/lib/strategies/JoinRoomStrategy.js +44 -0
  281. package/lib/strategies/JoinRoomStrategy.js.map +1 -0
  282. package/package.json +136 -4
  283. package/src/AdminApis.ts +60 -0
  284. package/src/DMs.ts +164 -0
  285. package/src/IFilter.ts +7 -0
  286. package/src/MatrixAuth.ts +129 -0
  287. package/src/MatrixClient.ts +2046 -0
  288. package/src/PantalaimonClient.ts +62 -0
  289. package/src/SynapseAdminApis.ts +482 -0
  290. package/src/SynchronousMatrixClient.ts +129 -0
  291. package/src/UnstableApis.ts +75 -0
  292. package/src/appservice/Appservice.ts +1089 -0
  293. package/src/appservice/Intent.ts +342 -0
  294. package/src/appservice/MatrixBridge.ts +139 -0
  295. package/src/appservice/UnstableAppserviceApis.ts +63 -0
  296. package/src/appservice/http_responses.ts +77 -0
  297. package/src/b64.ts +63 -0
  298. package/src/e2ee/CrossSigningBootstrap.ts +141 -0
  299. package/src/e2ee/CryptoClient.ts +378 -0
  300. package/src/e2ee/ICryptoRoomInformation.ts +9 -0
  301. package/src/e2ee/RoomTracker.ts +99 -0
  302. package/src/e2ee/RustEngine.ts +580 -0
  303. package/src/e2ee/decorators.ts +38 -0
  304. package/src/helpers/MatrixEntity.ts +65 -0
  305. package/src/helpers/MatrixGlob.ts +38 -0
  306. package/src/helpers/MentionPill.ts +95 -0
  307. package/src/helpers/Permalinks.ts +101 -0
  308. package/src/helpers/ProfileCache.ts +119 -0
  309. package/src/helpers/RichReply.ts +46 -0
  310. package/src/helpers/UnpaddedBase64.ts +44 -0
  311. package/src/http.ts +166 -0
  312. package/src/identity/IdentityClient.ts +225 -0
  313. package/src/index.ts +125 -0
  314. package/src/logging/ConsoleLogger.ts +31 -0
  315. package/src/logging/ILogger.ts +40 -0
  316. package/src/logging/LogService.ts +167 -0
  317. package/src/logging/RichConsoleLogger.ts +70 -0
  318. package/src/metrics/IMetricListener.ts +57 -0
  319. package/src/metrics/Metrics.ts +134 -0
  320. package/src/metrics/contexts.ts +56 -0
  321. package/src/metrics/decorators.ts +94 -0
  322. package/src/metrics/names.ts +53 -0
  323. package/src/mixins/AutojoinRoomsMixin.ts +24 -0
  324. package/src/mixins/AutojoinUpgradedRoomsMixin.ts +37 -0
  325. package/src/models/Account.ts +8 -0
  326. package/src/models/CreateRoom.ts +144 -0
  327. package/src/models/Crypto.ts +188 -0
  328. package/src/models/EventContext.ts +23 -0
  329. package/src/models/IdentityServerModels.ts +18 -0
  330. package/src/models/MSC2176.ts +47 -0
  331. package/src/models/MatrixError.ts +39 -0
  332. package/src/models/MatrixProfile.ts +55 -0
  333. package/src/models/OpenIDConnect.ts +10 -0
  334. package/src/models/Policies.ts +28 -0
  335. package/src/models/PowerLevelAction.ts +31 -0
  336. package/src/models/PowerLevelBounds.ts +16 -0
  337. package/src/models/Presence.ts +38 -0
  338. package/src/models/ServerVersions.ts +8 -0
  339. package/src/models/Spaces.ts +167 -0
  340. package/src/models/Threepid.ts +8 -0
  341. package/src/models/events/AliasesEvent.ts +37 -0
  342. package/src/models/events/CanonicalAliasEvent.ts +30 -0
  343. package/src/models/events/CreateEvent.ts +82 -0
  344. package/src/models/events/EncryptedRoomEvent.ts +58 -0
  345. package/src/models/events/EncryptionEvent.ts +63 -0
  346. package/src/models/events/Event.ts +38 -0
  347. package/src/models/events/EventKind.ts +16 -0
  348. package/src/models/events/InvalidEventError.ts +19 -0
  349. package/src/models/events/JoinRulesEvent.ts +37 -0
  350. package/src/models/events/MembershipEvent.ts +77 -0
  351. package/src/models/events/MessageEvent.ts +292 -0
  352. package/src/models/events/PinnedEventsEvent.ts +30 -0
  353. package/src/models/events/PowerLevelsEvent.ts +135 -0
  354. package/src/models/events/PresenceEvent.ts +69 -0
  355. package/src/models/events/RedactionEvent.ts +44 -0
  356. package/src/models/events/RoomAvatarEvent.ts +36 -0
  357. package/src/models/events/RoomEvent.ts +83 -0
  358. package/src/models/events/RoomNameEvent.ts +27 -0
  359. package/src/models/events/RoomTopicEvent.ts +27 -0
  360. package/src/models/events/SpaceChildEvent.ts +74 -0
  361. package/src/models/events/_MissingEvents.md +35 -0
  362. package/src/models/events/converter.ts +47 -0
  363. package/src/models/unstable/MediaInfo.ts +16 -0
  364. package/src/preprocessors/IPreprocessor.ts +24 -0
  365. package/src/preprocessors/RichRepliesPreprocessor.ts +159 -0
  366. package/src/request.ts +21 -0
  367. package/src/simple-validation.ts +30 -0
  368. package/src/storage/IAppserviceStorageProvider.ts +54 -0
  369. package/src/storage/ICryptoStorageProvider.ts +36 -0
  370. package/src/storage/IStorageProvider.ts +53 -0
  371. package/src/storage/MemoryStorageProvider.ts +65 -0
  372. package/src/storage/RustSdkCryptoStorageProvider.ts +81 -0
  373. package/src/storage/SimpleFsStorageProvider.ts +142 -0
  374. package/src/storage/SimplePostgresStorageProvider.ts +168 -0
  375. package/src/strategies/AppserviceJoinRoomStrategy.ts +47 -0
  376. package/src/strategies/JoinRoomStrategy.ts +45 -0
  377. package/tsconfig.json +22 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 - 2023 Travis Ralston
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,51 @@
1
- # Temporary Holding Version
1
+ # matrix-bot-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **This is a fork**, published as [`@jeongsu816/matrix-bot-sdk`](https://www.npmjs.com/package/@jeongsu816/matrix-bot-sdk).
4
+ > It is based on upstream [`turt2live/matrix-bot-sdk`](https://github.com/turt2live/matrix-bot-sdk) `main` and adds:
5
+ >
6
+ > - Cross-signing, secret storage (4S) and key backup from upstream PR
7
+ > [#396](https://github.com/turt2live/matrix-bot-sdk/pull/396), exposed as public `CryptoClient` methods.
8
+ > - Idempotent startup helpers: `client.crypto.ensureCrossSigning()` and `client.crypto.ensureSecretStorage()`.
9
+ > - `@matrix-org/matrix-sdk-crypto-nodejs` pinned to `0.6.1` (required for 4S).
10
+ > - Dependency security fixes: `request` replaced by `@cypress/request`, `sanitize-html` ≥ 2.18.1.
11
+ > Requires Node.js ≥ 22.12.
12
+ >
13
+ > ```ts
14
+ > import { passwordUiaCallback } from "@jeongsu816/matrix-bot-sdk";
15
+ >
16
+ > // "already-signed" | "restored" | "bootstrapped" | "skipped-no-auth"
17
+ > const result = await client.crypto.ensureCrossSigning({
18
+ > uiaCallback: password ? passwordUiaCallback(userId, password) : undefined,
19
+ > recoveryPassphrase,
20
+ > });
21
+ > if (recoveryPassphrase) {
22
+ > await client.crypto.ensureSecretStorage(recoveryPassphrase); // also sets up key backup
23
+ > }
24
+ > ```
25
+ >
26
+ > `ensureCrossSigning` creates a new identity (replacing the account's existing cross-signing keys) only when
27
+ > this device is not signed and the keys can't be restored from secret storage. Errors are thrown, so wrap it
28
+ > if cross-signing should not be fatal for your bot.
29
+ >
30
+ > The rest of this README is from upstream.
31
+
32
+ [![npm version](https://badge.fury.io/js/matrix-bot-sdk.svg)](https://www.npmjs.com/package/matrix-bot-sdk)
33
+
34
+ TypeScript/JavaScript SDK for Matrix bots. For help and support, visit [#matrix-bot-sdk:t2bot.io](https://matrix.to/#/#matrix-bot-sdk:t2bot.io)
35
+
36
+ # Documentation
37
+
38
+ Documentation for the project is available [here](https://turt2live.github.io/matrix-bot-sdk/index.html).
39
+
40
+ # Matrix version support
41
+
42
+ The Matrix protocol is [versioned](https://spec.matrix.org/latest/#specification-versions) to ensure endpoints and
43
+ functionality can safely rotate in and out of the ecosystem. The bot-sdk will assume it is connected to a homeserver
44
+ with support for at least one of the last 2 versions, at the time of the bot-sdk's release. This means that if you
45
+ connect the bot-sdk to a homeserver which is 3 or more Matrix versions out of date, things might not work for you.
46
+
47
+ It is recommended to update the bot-sdk as frequently as spec releases themselves (or faster) to avoid this situation,
48
+ and watch the repo for updates in the event a release is delayed.
49
+
50
+ **Note**: Currently the bot-sdk does not throw an error if the server appears to be incompatible, however this might
51
+ change in the future.
@@ -0,0 +1,52 @@
1
+ import { MatrixClient } from "./MatrixClient";
2
+ import { SynapseAdminApis } from "./SynapseAdminApis";
3
+ /**
4
+ * Whois information about a user.
5
+ * See https://matrix.org/docs/spec/client_server/r0.5.0#get-matrix-client-r0-admin-whois-userid for more information.
6
+ * @category Admin APIs
7
+ */
8
+ export interface WhoisInfo {
9
+ user_id: string;
10
+ devices: {
11
+ [device_id: string]: {
12
+ sessions: [
13
+ {
14
+ connections: WhoisConnectionInfo[];
15
+ }
16
+ ];
17
+ };
18
+ };
19
+ }
20
+ interface WhoisConnectionInfo {
21
+ /**
22
+ * Most recently seen IP address of the session.
23
+ */
24
+ ip: string;
25
+ /**
26
+ * Unix timestamp that the session was last active.
27
+ */
28
+ last_seen: number;
29
+ /**
30
+ * User agent string last seen in the session.
31
+ */
32
+ user_agent: string;
33
+ }
34
+ /**
35
+ * Access to various administrative APIs.
36
+ * @category Admin APIs
37
+ */
38
+ export declare class AdminApis {
39
+ private client;
40
+ constructor(client: MatrixClient);
41
+ /**
42
+ * Gets access to the Synapse administrative APIs object.
43
+ */
44
+ get synapse(): SynapseAdminApis;
45
+ /**
46
+ * Gets information about a particular user.
47
+ * @param {string} userId the user ID to lookup
48
+ * @returns {Promise<WhoisInfo>} resolves to the whois information
49
+ */
50
+ whoisUser(userId: string): Promise<WhoisInfo>;
51
+ }
52
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdminApis = void 0;
4
+ const SynapseAdminApis_1 = require("./SynapseAdminApis");
5
+ /**
6
+ * Access to various administrative APIs.
7
+ * @category Admin APIs
8
+ */
9
+ class AdminApis {
10
+ constructor(client) {
11
+ this.client = client;
12
+ }
13
+ /**
14
+ * Gets access to the Synapse administrative APIs object.
15
+ */
16
+ get synapse() {
17
+ return new SynapseAdminApis_1.SynapseAdminApis(this.client);
18
+ }
19
+ /**
20
+ * Gets information about a particular user.
21
+ * @param {string} userId the user ID to lookup
22
+ * @returns {Promise<WhoisInfo>} resolves to the whois information
23
+ */
24
+ whoisUser(userId) {
25
+ return this.client.doRequest("GET", "/_matrix/client/v3/admin/whois/" + encodeURIComponent(userId));
26
+ }
27
+ }
28
+ exports.AdminApis = AdminApis;
29
+ //# sourceMappingURL=AdminApis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AdminApis.js","sourceRoot":"","sources":["../src/AdminApis.ts"],"names":[],"mappings":";;;AACA,yDAAsD;AAmCtD;;;GAGG;AACH,MAAa,SAAS;IAClB,YAAoB,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;IACxC,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QACd,OAAO,IAAI,mCAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,MAAc;QAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,iCAAiC,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC;IACxG,CAAC;CACJ;AAnBD,8BAmBC"}
package/lib/DMs.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ import { MatrixClient } from "./MatrixClient";
2
+ /**
3
+ * Handles DM (direct messages) matching between users. Note that bots which
4
+ * existed prior to this might not have DM rooms populated correctly - the
5
+ * account data can be populated externally and that will be reflected here.
6
+ *
7
+ * Note that DM status is persisted across all access tokens for a user and
8
+ * is not persisted with the regular stores. The DM map is instead tracked
9
+ * on the homeserver as account data and thus survives the bot's own storage
10
+ * being wiped.
11
+ * @category Utilities
12
+ */
13
+ export declare class DMs {
14
+ private client;
15
+ private cached;
16
+ private ready;
17
+ /**
18
+ * Creates a new DM map.
19
+ * @param {MatrixClient} client The client the DM map is for.
20
+ */
21
+ constructor(client: MatrixClient);
22
+ private updateFromAccountData;
23
+ private handleInvite;
24
+ private persistCache;
25
+ private fixDms;
26
+ /**
27
+ * Forces an update of the DM cache.
28
+ * @returns {Promise<void>} Resolves when complete.
29
+ */
30
+ update(): Promise<void>;
31
+ /**
32
+ * Gets or creates a DM with a given user. If a DM needs to be created, it will
33
+ * be created as an encrypted DM (if both the MatrixClient and target user support
34
+ * crypto). Otherwise, the createFn can be used to override the call. Note that
35
+ * when creating a DM room the room should have `is_direct: true` set.
36
+ * @param {string} userId The user ID to get/create a DM for.
37
+ * @param {Function} createFn Optional function to use to create the room. Resolves
38
+ * to the created room ID.
39
+ * @returns {Promise<string>} Resolves to the DM room ID.
40
+ */
41
+ getOrCreateDm(userId: string, createFn?: (targetUserId: string) => Promise<string>): Promise<string>;
42
+ /**
43
+ * Determines if a given room is a DM according to the cache.
44
+ * @param {string} roomId The room ID.
45
+ * @returns {boolean} True if the room ID is a cached DM room ID.
46
+ */
47
+ isDm(roomId: string): boolean;
48
+ }
package/lib/DMs.js ADDED
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DMs = void 0;
4
+ const Crypto_1 = require("./models/Crypto");
5
+ const LogService_1 = require("./logging/LogService");
6
+ /**
7
+ * Handles DM (direct messages) matching between users. Note that bots which
8
+ * existed prior to this might not have DM rooms populated correctly - the
9
+ * account data can be populated externally and that will be reflected here.
10
+ *
11
+ * Note that DM status is persisted across all access tokens for a user and
12
+ * is not persisted with the regular stores. The DM map is instead tracked
13
+ * on the homeserver as account data and thus survives the bot's own storage
14
+ * being wiped.
15
+ * @category Utilities
16
+ */
17
+ class DMs {
18
+ /**
19
+ * Creates a new DM map.
20
+ * @param {MatrixClient} client The client the DM map is for.
21
+ */
22
+ constructor(client) {
23
+ this.client = client;
24
+ this.cached = new Map();
25
+ this.client.on("account_data", (ev) => {
26
+ if (ev['type'] !== 'm.direct')
27
+ return;
28
+ // noinspection JSIgnoredPromiseFromCall
29
+ this.updateFromAccountData();
30
+ });
31
+ this.client.on("room.invite", (rid, ev) => this.handleInvite(rid, ev));
32
+ }
33
+ async updateFromAccountData() {
34
+ // Don't trust the sync update
35
+ let map = {};
36
+ try {
37
+ map = await this.client.getAccountData("m.direct");
38
+ }
39
+ catch (e) {
40
+ if (e.body?.errcode !== "M_NOT_FOUND" && e.statusCode !== 404) {
41
+ LogService_1.LogService.warn("DMs", "Error getting m.direct account data: ", e);
42
+ }
43
+ }
44
+ this.cached = new Map();
45
+ for (const [userId, roomIds] of Object.entries(map)) {
46
+ this.cached.set(userId, roomIds);
47
+ }
48
+ }
49
+ async handleInvite(roomId, ev) {
50
+ if (ev['content']?.['is_direct'] === true) {
51
+ const userId = ev['sender'];
52
+ if (!this.cached.has(userId))
53
+ this.cached.set(userId, []);
54
+ this.cached.set(userId, [roomId, ...this.cached.get(userId)]);
55
+ await this.persistCache();
56
+ }
57
+ }
58
+ async persistCache() {
59
+ const obj = {};
60
+ for (const [uid, rids] of this.cached.entries()) {
61
+ obj[uid] = rids;
62
+ }
63
+ await this.client.setAccountData("m.direct", obj);
64
+ }
65
+ async fixDms(userId) {
66
+ const currentRooms = this.cached.get(userId);
67
+ if (!currentRooms)
68
+ return;
69
+ const toKeep = [];
70
+ for (const roomId of currentRooms) {
71
+ try {
72
+ const members = await this.client.getAllRoomMembers(roomId);
73
+ const joined = members.filter(m => m.effectiveMembership === "join" || m.effectiveMembership === "invite");
74
+ if (joined.some(m => m.membershipFor === userId)) {
75
+ toKeep.push(roomId);
76
+ }
77
+ }
78
+ catch (e) {
79
+ LogService_1.LogService.warn("DMs", `Unable to check ${roomId} for room members - assuming invalid DM`);
80
+ }
81
+ }
82
+ if (toKeep.length === currentRooms.length)
83
+ return; // no change
84
+ if (toKeep.length > 0) {
85
+ this.cached.set(userId, toKeep);
86
+ }
87
+ else {
88
+ this.cached.delete(userId);
89
+ }
90
+ await this.persistCache();
91
+ }
92
+ /**
93
+ * Forces an update of the DM cache.
94
+ * @returns {Promise<void>} Resolves when complete.
95
+ */
96
+ async update() {
97
+ await this.ready; // finish the existing call if present
98
+ this.ready = this.updateFromAccountData();
99
+ return this.ready;
100
+ }
101
+ /**
102
+ * Gets or creates a DM with a given user. If a DM needs to be created, it will
103
+ * be created as an encrypted DM (if both the MatrixClient and target user support
104
+ * crypto). Otherwise, the createFn can be used to override the call. Note that
105
+ * when creating a DM room the room should have `is_direct: true` set.
106
+ * @param {string} userId The user ID to get/create a DM for.
107
+ * @param {Function} createFn Optional function to use to create the room. Resolves
108
+ * to the created room ID.
109
+ * @returns {Promise<string>} Resolves to the DM room ID.
110
+ */
111
+ async getOrCreateDm(userId, createFn) {
112
+ await this.ready;
113
+ await this.fixDms(userId);
114
+ const rooms = this.cached.get(userId);
115
+ if (rooms?.length)
116
+ return rooms[0];
117
+ let roomId;
118
+ if (createFn) {
119
+ roomId = await createFn(userId);
120
+ }
121
+ else {
122
+ let hasKeys = false;
123
+ if (!!this.client.crypto) {
124
+ const keys = await this.client.getUserDevices([userId]);
125
+ const userKeys = keys?.device_keys?.[userId] ?? {};
126
+ hasKeys = Object.values(userKeys).filter(device => Object.values(device).length > 0).length > 0;
127
+ }
128
+ roomId = await this.client.createRoom({
129
+ invite: [userId],
130
+ is_direct: true,
131
+ preset: "trusted_private_chat",
132
+ initial_state: hasKeys ? [{
133
+ type: "m.room.encryption",
134
+ state_key: "",
135
+ content: { algorithm: Crypto_1.EncryptionAlgorithm.MegolmV1AesSha2 },
136
+ }] : [],
137
+ });
138
+ }
139
+ if (!this.cached.has(userId))
140
+ this.cached.set(userId, []);
141
+ this.cached.set(userId, [roomId, ...this.cached.get(userId)]);
142
+ await this.persistCache();
143
+ return roomId;
144
+ }
145
+ /**
146
+ * Determines if a given room is a DM according to the cache.
147
+ * @param {string} roomId The room ID.
148
+ * @returns {boolean} True if the room ID is a cached DM room ID.
149
+ */
150
+ isDm(roomId) {
151
+ for (const val of this.cached.values()) {
152
+ if (val.includes(roomId)) {
153
+ return true;
154
+ }
155
+ }
156
+ return false;
157
+ }
158
+ }
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ACP,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;YAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC9D,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAE1B,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACI,IAAI,CAAC,MAAc;QACtB,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;YACrC,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBACvB,OAAO,IAAI,CAAC;YAChB,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AApJD,kBAoJC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Sync filter information.
3
+ */
4
+ export interface IFilterInfo {
5
+ id: number;
6
+ filter: any;
7
+ }
package/lib/IFilter.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IFilter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IFilter.js","sourceRoot":"","sources":["../src/IFilter.ts"],"names":[],"mappings":""}
@@ -0,0 +1,45 @@
1
+ import { MatrixClient } from "./MatrixClient";
2
+ /**
3
+ * Functions for interacting with Matrix prior to having an access token. Intended
4
+ * to be used for logging in/registering to get a MatrixClient instance.
5
+ *
6
+ * By design, this limits the options used to create the MatrixClient. To specify
7
+ * custom elements to the client, get the access token from the returned client
8
+ * and create a new MatrixClient instance. Due to the nature of Matrix, it is
9
+ * also recommended to use the homeserverUrl from the generated MatrixClient as
10
+ * it may be different from that given to the MatrixAuth class.
11
+ */
12
+ export declare class MatrixAuth {
13
+ private homeserverUrl;
14
+ /**
15
+ * Creates a new MatrixAuth class for creating a MatrixClient
16
+ * @param {string} homeserverUrl The homeserver URL to authenticate against.
17
+ */
18
+ constructor(homeserverUrl: string);
19
+ /**
20
+ * Generate a client with no access token so we can reuse the doRequest
21
+ * logic already written.
22
+ */
23
+ private createTemplateClient;
24
+ /**
25
+ * Performs simple registration using a password for the account. This will
26
+ * assume the server supports the m.login.password flow for registration, and
27
+ * will attempt to complete only that stage. The caller is expected to determine
28
+ * if the homeserver supports registration prior to invocation.
29
+ * @param {string} localpart The localpart (username) to register
30
+ * @param {string} password The password to register with
31
+ * @param {string} deviceName The name of the newly created device. Optional.
32
+ * @returns {Promise<MatrixClient>} Resolves to a logged-in MatrixClient
33
+ */
34
+ passwordRegister(localpart: string, password: string, deviceName?: string): Promise<MatrixClient>;
35
+ /**
36
+ * Performs simple password login with the homeserver. The caller is
37
+ * expected to confirm if the homeserver supports this login flow prior
38
+ * to invocation.
39
+ * @param {string} username The username (localpart or user ID) to log in with
40
+ * @param {string} password The password for the account
41
+ * @param {string} deviceName The name of the newly created device. Optional.
42
+ * @returns {Promise<MatrixClient>} Resolves to a logged-in MatrixClient
43
+ */
44
+ passwordLogin(username: string, password: string, deviceName?: string): Promise<MatrixClient>;
45
+ }
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MatrixAuth = void 0;
4
+ const MatrixClient_1 = require("./MatrixClient");
5
+ /**
6
+ * Functions for interacting with Matrix prior to having an access token. Intended
7
+ * to be used for logging in/registering to get a MatrixClient instance.
8
+ *
9
+ * By design, this limits the options used to create the MatrixClient. To specify
10
+ * custom elements to the client, get the access token from the returned client
11
+ * and create a new MatrixClient instance. Due to the nature of Matrix, it is
12
+ * also recommended to use the homeserverUrl from the generated MatrixClient as
13
+ * it may be different from that given to the MatrixAuth class.
14
+ */
15
+ class MatrixAuth {
16
+ /**
17
+ * Creates a new MatrixAuth class for creating a MatrixClient
18
+ * @param {string} homeserverUrl The homeserver URL to authenticate against.
19
+ */
20
+ constructor(homeserverUrl) {
21
+ this.homeserverUrl = homeserverUrl;
22
+ // nothing to do
23
+ }
24
+ /**
25
+ * Generate a client with no access token so we can reuse the doRequest
26
+ * logic already written.
27
+ */
28
+ createTemplateClient() {
29
+ return new MatrixClient_1.MatrixClient(this.homeserverUrl, "");
30
+ }
31
+ /**
32
+ * Performs simple registration using a password for the account. This will
33
+ * assume the server supports the m.login.password flow for registration, and
34
+ * will attempt to complete only that stage. The caller is expected to determine
35
+ * if the homeserver supports registration prior to invocation.
36
+ * @param {string} localpart The localpart (username) to register
37
+ * @param {string} password The password to register with
38
+ * @param {string} deviceName The name of the newly created device. Optional.
39
+ * @returns {Promise<MatrixClient>} Resolves to a logged-in MatrixClient
40
+ */
41
+ async passwordRegister(localpart, password, deviceName) {
42
+ // First try and complete the stage without UIA in hopes the server is kind to us:
43
+ const body = {
44
+ username: localpart,
45
+ password: password,
46
+ initial_device_display_name: deviceName,
47
+ };
48
+ let response;
49
+ try {
50
+ response = await this.createTemplateClient().doRequest("POST", "/_matrix/client/v3/register", null, body);
51
+ }
52
+ catch (e) {
53
+ if (e.statusCode === 401) {
54
+ if (typeof (e.body) === "string")
55
+ e.body = JSON.parse(e.body);
56
+ if (!e.body)
57
+ throw new Error(JSON.stringify(Object.keys(e)));
58
+ // 401 means we need to do UIA, so try and complete a stage
59
+ const sessionId = e.body['session'];
60
+ const expectedFlow = ["m.login.dummy"];
61
+ let hasFlow = false;
62
+ for (const flow of e.body['flows']) {
63
+ const stages = flow['stages'];
64
+ if (stages.length !== expectedFlow.length)
65
+ continue;
66
+ let stagesMatch = true;
67
+ for (let i = 0; i < stages.length; i++) {
68
+ if (stages[i] !== expectedFlow[i]) {
69
+ stagesMatch = false;
70
+ break;
71
+ }
72
+ }
73
+ if (stagesMatch) {
74
+ hasFlow = true;
75
+ break;
76
+ }
77
+ }
78
+ if (!hasFlow)
79
+ throw new Error("Failed to find appropriate login flow in User-Interactive Authentication");
80
+ body['auth'] = {
81
+ type: expectedFlow[0], // HACK: We assume we only have one entry here
82
+ session: sessionId,
83
+ };
84
+ response = await this.createTemplateClient().doRequest("POST", "/_matrix/client/v3/register", null, body);
85
+ }
86
+ }
87
+ if (!response)
88
+ throw new Error("Failed to register");
89
+ const accessToken = response['access_token'];
90
+ if (!accessToken)
91
+ throw new Error("No access token returned");
92
+ return new MatrixClient_1.MatrixClient(this.homeserverUrl, accessToken);
93
+ }
94
+ /**
95
+ * Performs simple password login with the homeserver. The caller is
96
+ * expected to confirm if the homeserver supports this login flow prior
97
+ * to invocation.
98
+ * @param {string} username The username (localpart or user ID) to log in with
99
+ * @param {string} password The password for the account
100
+ * @param {string} deviceName The name of the newly created device. Optional.
101
+ * @returns {Promise<MatrixClient>} Resolves to a logged-in MatrixClient
102
+ */
103
+ async passwordLogin(username, password, deviceName) {
104
+ const body = {
105
+ type: "m.login.password",
106
+ identifier: {
107
+ type: "m.id.user",
108
+ user: username,
109
+ },
110
+ password: password,
111
+ initial_device_display_name: deviceName,
112
+ };
113
+ const response = await this.createTemplateClient().doRequest("POST", "/_matrix/client/v3/login", null, body);
114
+ const accessToken = response["access_token"];
115
+ if (!accessToken)
116
+ throw new Error("Expected access token in response - got nothing");
117
+ let homeserverUrl = this.homeserverUrl;
118
+ if (response['well_known'] && response['well_known']['m.homeserver'] && response['well_known']['m.homeserver']['base_url']) {
119
+ homeserverUrl = response['well_known']['m.homeserver']['base_url'];
120
+ }
121
+ return new MatrixClient_1.MatrixClient(homeserverUrl, accessToken);
122
+ }
123
+ }
124
+ exports.MatrixAuth = MatrixAuth;
125
+ //# sourceMappingURL=MatrixAuth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MatrixAuth.js","sourceRoot":"","sources":["../src/MatrixAuth.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAE9C;;;;;;;;;GASG;AAC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