From f11e1910f57175d79c5da5b695311bca40b8c1f0 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 17 Feb 2025 09:53:22 +0000 Subject: [PATCH] Improve types around User Interactive Auth (#4709) * Remove confused type UIAResponse Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update uia.ts --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/@types/uia.ts | 5 +++-- src/client.ts | 6 +++--- src/interactive-auth.ts | 3 +-- src/rust-crypto/OutgoingRequestProcessor.ts | 3 +-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/@types/uia.ts b/src/@types/uia.ts index c840aaac4..7fb4c53cc 100644 --- a/src/@types/uia.ts +++ b/src/@types/uia.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { type AuthDict, type IAuthData } from "../interactive-auth.ts"; +import { type AuthDict } from "../interactive-auth.ts"; /** * Helper type to represent HTTP request body for a UIA enabled endpoint @@ -25,5 +25,6 @@ export type UIARequest = T & { /** * Helper type to represent HTTP response body for a UIA enabled endpoint + * @deprecated - a successful response for a UIA enabled endpoint is no different, UIA is signalled via an error */ -export type UIAResponse = T | IAuthData; +export type UIAResponse = T; diff --git a/src/client.ts b/src/client.ts index e5f22933b..93f3a6b9a 100644 --- a/src/client.ts +++ b/src/client.ts @@ -209,7 +209,7 @@ import { NamespacedValue, UnstableValue } from "./NamespacedValue.ts"; import { ToDeviceMessageQueue } from "./ToDeviceMessageQueue.ts"; import { type ToDeviceBatch } from "./models/ToDeviceMessage.ts"; import { IgnoredInvites } from "./models/invites-ignorer.ts"; -import { type UIARequest, type UIAResponse } from "./@types/uia.ts"; +import { type UIARequest } from "./@types/uia.ts"; import { type LocalNotificationSettings } from "./@types/local_notifications.ts"; import { buildFeatureSupportMap, Feature, ServerSupport } from "./feature.ts"; import { type CryptoBackend } from "./common-crypto/CryptoBackend.ts"; @@ -6363,9 +6363,9 @@ export class MatrixClient extends TypedEventEmitter> { + public async requestLoginToken(auth?: AuthDict): Promise { const body: UIARequest = { auth }; - return this.http.authedRequest>( + return this.http.authedRequest( Method.Post, "/login/get_token", undefined, // no query params diff --git a/src/interactive-auth.ts b/src/interactive-auth.ts index 79bb2aa39..0e02d2903 100644 --- a/src/interactive-auth.ts +++ b/src/interactive-auth.ts @@ -20,7 +20,6 @@ import { logger } from "./logger.ts"; import { type MatrixClient } from "./client.ts"; import { defer, type IDeferred } from "./utils.ts"; import { MatrixError } from "./http-api/index.ts"; -import { type UIAResponse } from "./@types/uia.ts"; import { type UserIdentifier } from "./@types/auth.ts"; const EMAIL_STAGE_TYPE = "m.login.email.identity"; @@ -159,7 +158,7 @@ export class NoAuthFlowFoundError extends Error { * * The generic parameter `T` is the type of the response of the endpoint, once it is eventually successful. */ -export type UIAuthCallback = (makeRequest: (authData: AuthDict | null) => Promise>) => Promise; +export type UIAuthCallback = (makeRequest: (authData: AuthDict | null) => Promise) => Promise; interface IOpts { /** diff --git a/src/rust-crypto/OutgoingRequestProcessor.ts b/src/rust-crypto/OutgoingRequestProcessor.ts index 9f3813b87..16031d63a 100644 --- a/src/rust-crypto/OutgoingRequestProcessor.ts +++ b/src/rust-crypto/OutgoingRequestProcessor.ts @@ -31,7 +31,6 @@ import { logger } from "../logger.ts"; import { calculateRetryBackoff, type IHttpOpts, type MatrixHttpApi, Method } from "../http-api/index.ts"; import { logDuration, type QueryDict, sleep } from "../utils.ts"; import { type AuthDict, type UIAuthCallback } from "../interactive-auth.ts"; -import { type UIAResponse } from "../@types/uia.ts"; import { ToDeviceMessageId } from "../@types/event.ts"; import { UnstablePrefix as DehydrationUnstablePrefix } from "./DehydratedDeviceManager.ts"; @@ -176,7 +175,7 @@ export class OutgoingRequestProcessor { } const parsedBody = JSON.parse(body); - const makeRequest = async (auth: AuthDict | null): Promise> => { + const makeRequest = async (auth: AuthDict | null): Promise => { const newBody: Record = { ...parsedBody, };