Fill in ts types + change names

This commit is contained in:
RMidhunSuresh 2022-02-02 12:45:49 +05:30
parent b482d478b4
commit 49ade61ef6
3 changed files with 14 additions and 11 deletions

View file

@ -18,7 +18,7 @@ import type {HomeServerApi} from "../net/HomeServerApi";
import {registrationStageFromType} from "./registrationStageFromType";
import type {BaseRegistrationStage} from "./stages/BaseRegistrationStage";
export type RegistrationParameters = {
export type RegistrationDetails = {
username: string | null;
password: string;
initialDeviceDisplayName: string;
@ -32,9 +32,9 @@ export type RegistrationResponse = {
export class Registration {
private _hsApi: HomeServerApi;
private _data: RegistrationParameters;
private _data: RegistrationDetails;
constructor(hsApi: HomeServerApi, data: RegistrationParameters) {
constructor(hsApi: HomeServerApi, data: RegistrationDetails) {
this._hsApi = hsApi;
this._data = data;
}

View file

@ -16,11 +16,11 @@ limitations under the License.
import type {BaseRegistrationStage} from "./stages/BaseRegistrationStage";
import type {HomeServerApi} from "../net/HomeServerApi";
import type {RegistrationParameters} from "./Registration";
import type {RegistrationDetails} from "./Registration";
import {DummyAuth} from "./stages/DummyAuth";
import {TermsAuth} from "./stages/TermsAuth";
type DerivedFromBaseRegistration = { new(hsApi: HomeServerApi, registrationData: RegistrationParameters, session: string, params?: Record<string, any>): BaseRegistrationStage } & typeof BaseRegistrationStage | undefined;
type DerivedFromBaseRegistration = { new(hsApi: HomeServerApi, registrationData: RegistrationDetails, session: string, params?: Record<string, any>): BaseRegistrationStage } & typeof BaseRegistrationStage | undefined;
export function registrationStageFromType(type: string): DerivedFromBaseRegistration {
switch (type) {

View file

@ -14,25 +14,28 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
type Auth = {
type AuthenticationData = {
type: string;
session: string;
[key: string]: any;
}
type Params = {
// contains data needed to complete this stage, eg: link to privacy policy
type RegistrationParams = {
[key: string]: any;
}
import type {HomeServerApi} from "../../net/HomeServerApi";
import type {RegistrationParameters, RegistrationResponse} from "../Registration";
import type {RegistrationDetails, RegistrationResponse} from "../Registration";
export abstract class BaseRegistrationStage {
protected _hsApi: HomeServerApi;
protected _registrationData: RegistrationParameters;
protected _registrationData: RegistrationDetails;
protected _session: string;
protected _nextStage: BaseRegistrationStage;
protected _params?: Record<string, any>
constructor(hsApi: HomeServerApi, registrationData: RegistrationParameters, session: string, params?: Params) {
constructor(hsApi: HomeServerApi, registrationData: RegistrationDetails, session: string, params?: RegistrationParams) {
this._hsApi = hsApi;
this._registrationData = registrationData;
this._session = session;
@ -49,7 +52,7 @@ export abstract class BaseRegistrationStage {
* - the next stage if this stage was completed successfully
* - user-id (string) if registration is completed
*/
abstract complete(auth?: Auth): Promise<BaseRegistrationStage | string>;
abstract complete(auth?: AuthenticationData): Promise<BaseRegistrationStage | string>;
setNextStage(stage: BaseRegistrationStage) {
this._nextStage = stage;