- Introduced OAuthManualInputManager and routed callback-server logins to await pasted redirect URLs with a visible tip. - Extended /login slash command to submit redirect URLs, block overlapping logins, and covered manual callbacks in tests. - Propagated onManualCodeInput through OAuth provider login helpers with a default authorization prompt. - Resolved docs index generation paths using path.resolve relative to the script directory.
43 lines
975 B
TypeScript
43 lines
975 B
TypeScript
type PendingInput = {
|
|
providerId: string;
|
|
resolve: (value: string) => void;
|
|
reject: (error: Error) => void;
|
|
};
|
|
|
|
export class OAuthManualInputManager {
|
|
#pending?: PendingInput;
|
|
|
|
waitForInput(providerId: string): Promise<string> {
|
|
if (this.#pending) {
|
|
this.clear("Manual OAuth input superseded by a new login");
|
|
}
|
|
|
|
const { promise, resolve, reject } = Promise.withResolvers<string>();
|
|
this.#pending = { providerId, resolve, reject };
|
|
return promise;
|
|
}
|
|
|
|
submit(input: string): boolean {
|
|
if (!this.#pending) return false;
|
|
const { resolve } = this.#pending;
|
|
this.#pending = undefined;
|
|
resolve(input);
|
|
return true;
|
|
}
|
|
|
|
clear(reason = "Manual OAuth input cleared"): void {
|
|
if (!this.#pending) return;
|
|
const { reject } = this.#pending;
|
|
this.#pending = undefined;
|
|
reject(new Error(reason));
|
|
}
|
|
|
|
hasPending(): boolean {
|
|
return Boolean(this.#pending);
|
|
}
|
|
|
|
get pendingProviderId(): string | undefined {
|
|
return this.#pending?.providerId;
|
|
}
|
|
}
|