Skip to content

Commit f11e191

Browse files
authored
Improve types around User Interactive Auth (#4709)
* Remove confused type UIAResponse Signed-off-by: Michael Telatynski <[email protected]> * Update uia.ts --------- Signed-off-by: Michael Telatynski <[email protected]>
1 parent a1a0463 commit f11e191

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

src/@types/uia.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { type AuthDict, type IAuthData } from "../interactive-auth.ts";
17+
import { type AuthDict } from "../interactive-auth.ts";
1818

1919
/**
2020
* Helper type to represent HTTP request body for a UIA enabled endpoint
@@ -25,5 +25,6 @@ export type UIARequest<T> = T & {
2525

2626
/**
2727
* Helper type to represent HTTP response body for a UIA enabled endpoint
28+
* @deprecated - a successful response for a UIA enabled endpoint is no different, UIA is signalled via an error
2829
*/
29-
export type UIAResponse<T> = T | IAuthData;
30+
export type UIAResponse<T> = T;

src/client.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ import { NamespacedValue, UnstableValue } from "./NamespacedValue.ts";
209209
import { ToDeviceMessageQueue } from "./ToDeviceMessageQueue.ts";
210210
import { type ToDeviceBatch } from "./models/ToDeviceMessage.ts";
211211
import { IgnoredInvites } from "./models/invites-ignorer.ts";
212-
import { type UIARequest, type UIAResponse } from "./@types/uia.ts";
212+
import { type UIARequest } from "./@types/uia.ts";
213213
import { type LocalNotificationSettings } from "./@types/local_notifications.ts";
214214
import { buildFeatureSupportMap, Feature, ServerSupport } from "./feature.ts";
215215
import { type CryptoBackend } from "./common-crypto/CryptoBackend.ts";
@@ -6363,9 +6363,9 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
63636363
* @returns Promise which resolves: On success, the token response
63646364
* or UIA auth data.
63656365
*/
6366-
public async requestLoginToken(auth?: AuthDict): Promise<UIAResponse<LoginTokenPostResponse>> {
6366+
public async requestLoginToken(auth?: AuthDict): Promise<LoginTokenPostResponse> {
63676367
const body: UIARequest<unknown> = { auth };
6368-
return this.http.authedRequest<UIAResponse<LoginTokenPostResponse>>(
6368+
return this.http.authedRequest<LoginTokenPostResponse>(
63696369
Method.Post,
63706370
"/login/get_token",
63716371
undefined, // no query params

src/interactive-auth.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { logger } from "./logger.ts";
2020
import { type MatrixClient } from "./client.ts";
2121
import { defer, type IDeferred } from "./utils.ts";
2222
import { MatrixError } from "./http-api/index.ts";
23-
import { type UIAResponse } from "./@types/uia.ts";
2423
import { type UserIdentifier } from "./@types/auth.ts";
2524

2625
const EMAIL_STAGE_TYPE = "m.login.email.identity";
@@ -159,7 +158,7 @@ export class NoAuthFlowFoundError extends Error {
159158
*
160159
* The generic parameter `T` is the type of the response of the endpoint, once it is eventually successful.
161160
*/
162-
export type UIAuthCallback<T> = (makeRequest: (authData: AuthDict | null) => Promise<UIAResponse<T>>) => Promise<T>;
161+
export type UIAuthCallback<T> = (makeRequest: (authData: AuthDict | null) => Promise<T>) => Promise<T>;
163162

164163
interface IOpts<T> {
165164
/**

src/rust-crypto/OutgoingRequestProcessor.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { logger } from "../logger.ts";
3131
import { calculateRetryBackoff, type IHttpOpts, type MatrixHttpApi, Method } from "../http-api/index.ts";
3232
import { logDuration, type QueryDict, sleep } from "../utils.ts";
3333
import { type AuthDict, type UIAuthCallback } from "../interactive-auth.ts";
34-
import { type UIAResponse } from "../@types/uia.ts";
3534
import { ToDeviceMessageId } from "../@types/event.ts";
3635
import { UnstablePrefix as DehydrationUnstablePrefix } from "./DehydratedDeviceManager.ts";
3736

@@ -176,7 +175,7 @@ export class OutgoingRequestProcessor {
176175
}
177176

178177
const parsedBody = JSON.parse(body);
179-
const makeRequest = async (auth: AuthDict | null): Promise<UIAResponse<T>> => {
178+
const makeRequest = async (auth: AuthDict | null): Promise<T> => {
180179
const newBody: Record<string, any> = {
181180
...parsedBody,
182181
};

0 commit comments

Comments
 (0)