@@ -16,6 +16,10 @@ import type { Credentials, HomeserverInstance } from "../plugins/homeserver";
1616import type { GeneratedSecretStorageKey } from "matrix-js-sdk/src/crypto-api" ;
1717import { bootstrapCrossSigningForClient , Client } from "./client" ;
1818
19+ export interface CredentialsOptionalAccessToken extends Omit < Credentials , "accessToken" > {
20+ accessToken ?: string ;
21+ }
22+
1923export interface CreateBotOpts {
2024 /**
2125 * A prefix to use for the userid. If unspecified, "bot_" will be used.
@@ -58,7 +62,7 @@ const defaultCreateBotOptions = {
5862type ExtendedMatrixClient = MatrixClient & { __playwright_recovery_key : GeneratedSecretStorageKey } ;
5963
6064export class Bot extends Client {
61- public credentials ?: Credentials ;
65+ public credentials ?: CredentialsOptionalAccessToken ;
6266 private handlePromise : Promise < JSHandle < ExtendedMatrixClient > > ;
6367
6468 constructor (
@@ -73,13 +77,13 @@ export class Bot extends Client {
7377 /**
7478 * Set the credentials used by the bot.
7579 *
76- * If `credentials.accessToken` is set to the empty string, then
77- * `buildClient` will log in a new session. Note that `getCredentials`
78- * will return the credentials passed to this function, rather than
79- * the updated credentials from the new login. In particular, the
80- * `accessToken` and `deviceId` will not be updated.
80+ * If `credentials.accessToken` is unset, then `buildClient` will log in a
81+ * new session. Note that `getCredentials` will return the credentials
82+ * passed to this function, rather than the updated credentials from the new
83+ * login. In particular, the `accessToken` and `deviceId` will not be
84+ * updated.
8185 */
82- public setCredentials ( credentials : Credentials ) : void {
86+ public setCredentials ( credentials : CredentialsOptionalAccessToken ) : void {
8387 if ( this . credentials ) throw new Error ( "Bot has already started" ) ;
8488 this . credentials = credentials ;
8589 }
@@ -89,7 +93,7 @@ export class Bot extends Client {
8993 return client . evaluate ( ( cli ) => cli . __playwright_recovery_key ) ;
9094 }
9195
92- private async getCredentials ( ) : Promise < Credentials > {
96+ private async getCredentials ( ) : Promise < CredentialsOptionalAccessToken > {
9397 if ( this . credentials ) return this . credentials ;
9498 // We want to pad the uniqueId but not the prefix
9599 const username =
@@ -170,7 +174,7 @@ export class Bot extends Client {
170174 getSecretStorageKey,
171175 } ;
172176
173- if ( ! credentials . accessToken ) {
177+ if ( " accessToken" in credentials ) {
174178 const loginCli = new window . matrixcs . MatrixClient ( {
175179 baseUrl,
176180 store : new window . matrixcs . MemoryStore ( ) ,
0 commit comments