Skip to content

Commit

Permalink
improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry Archibald committed Jun 1, 2023
1 parent f66eebf commit 48b0160
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/autodiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,18 @@ enum AutoDiscoveryError {
InvalidJson = "Invalid JSON",
}

interface WellKnownConfig extends Omit<IWellKnownConfig, "error"> {
state: AutoDiscoveryAction;
error?: IWellKnownConfig["error"] | null;
}
interface DelegatedAuthConfig extends IDelegatedAuthConfig, ValidatedIssuerConfig {
interface AutoDiscoveryState {
state: AutoDiscoveryAction;
error?: IWellKnownConfig["error"] | null;
}
interface WellKnownConfig extends Omit<IWellKnownConfig, "error">, AutoDiscoveryState {}

interface DelegatedAuthConfig extends IDelegatedAuthConfig, ValidatedIssuerConfig, AutoDiscoveryState {}

export interface ClientConfig extends Omit<IClientWellKnown, "m.homeserver" | "m.identity_server"> {
"m.homeserver": WellKnownConfig;
"m.identity_server": WellKnownConfig;
"m.authentication"?: DelegatedAuthConfig;
"m.authentication"?: DelegatedAuthConfig | AutoDiscoveryState;
}

/**
Expand Down Expand Up @@ -276,7 +275,7 @@ export class AutoDiscovery {

public static async validateDiscoveryAuthenticationConfig(
wellKnown: IClientWellKnown,
): Promise<DelegatedAuthConfig> {
): Promise<DelegatedAuthConfig | AutoDiscoveryState> {
try {
const homeserverAuthenticationConfig = validateWellKnownAuthentication(wellKnown);

Expand Down Expand Up @@ -310,11 +309,10 @@ export class AutoDiscovery {
? AutoDiscoveryAction.IGNORE
: AutoDiscoveryAction.FAIL_ERROR;

// @TODO(kerrya) better way to handle this fail type
return {
state,
error: errorType,
} as unknown as DelegatedAuthConfig;
};
}
}

Expand Down

0 comments on commit 48b0160

Please sign in to comment.