Skip to content

Commit

Permalink
Adds Email Confirmation, KYC procedure, Password Reset and Disable O…
Browse files Browse the repository at this point in the history
…perator modules. (#64)

* Fixes after check

* Removes unnecessary comment

* Fixes SDK limitation

* Removes unnecessary interceptor, changes Body to Query in request for oracle discovery

* Adds statistics related DTO interfaces with api mapping

* Changes in interface naming convention of received data

* Review fixes

* Review fixes

* Review fixes

* Review fixes

* Changes logic of calling exchange oracle: url is obtained based on the address provided in the enpoint. Adds CORS

* Adds test coverage

* Adds test coverage

* Adds kv store to the modules that use it

* minor fixes

* minor fixes

* Alignment of the swagger and interface used in the project

* Add email verification endpoints and related logic.

* Implement password reset functionality.

* Add disableOperator and prepareSignature methods.

* A property has been set in the eslint config to avoid enforcing a line break style.

* Implement KYC procedure start.

* Integration with the KYC procedure, password reset and disable operator modules.

* The variable name 'restorePasswordDto' in the sendRestorePassword function has been changed to 'restorePasswordData'.

* Update 'type' field data type in PrepareSignature model.

* Refactor prepareSignature test and update response fixture.

* Refactor service injections in multiple controllers, renamed to a generic 'service' format.

* Refactor services to use 'gateway' instead of 'reputationOracleService'.

* Sets base paths in the controllers and simplify the path of each endpoint.

* Refactor email verification test fixtures.

* Refactor 'h_captcha_token'.

* Enhance test coverage for oracle gateway.

* bug fixed

* Remove hCaptcha token mapping in user-worker and password-reset mappers.

* Refactor code to separate PrepareSignature functionality into its own module. (#71)

* fix: Change naming conventions in password-reset mapper.

* Merge conflict fixes

---------

Co-authored-by: maciek.nabialek <maciej.nabialek@blockydevs.com>
  • Loading branch information
MWBlocky and macnablocky authored May 13, 2024
1 parent 1fee79a commit 74cce2e
Show file tree
Hide file tree
Showing 64 changed files with 2,036 additions and 41 deletions.
1 change: 1 addition & 0 deletions packages/apps/human-app/server/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'linebreak-style': 0,
},
};
10 changes: 10 additions & 0 deletions packages/apps/human-app/server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import { StatisticsModule } from './modules/statistics/statistics.module';
import { StatisticsController } from './modules/statistics/statistics.controller';
import { ExchangeOracleModule } from './integrations/exchange-oracle/exchange-oracle.module';
import { KvStoreModule } from './integrations/kv-store/kv-store.module';
import { EmailConfirmationModule } from './modules/email-confirmation/email-confirmation.module';
import { PasswordResetModule } from './modules/password-reset/password-reset.module';
import { DisableOperatorModule } from './modules/disable-operator/disable-operator.module';
import { KycProcedureModule } from './modules/kyc-procedure/kyc-procedure.module';
import { PrepareSignatureModule } from './modules/prepare-signature/prepare-signature.module';
import { EscrowUtilsModule } from './integrations/escrow/escrow-utils.module';
import Joi from 'joi';
import { ChainId } from '@human-protocol/sdk';
Expand Down Expand Up @@ -69,6 +74,11 @@ import { ChainId } from '@human-protocol/sdk';
OracleDiscoveryModule,
StatisticsModule,
KvStoreModule,
EmailConfirmationModule,
PasswordResetModule,
DisableOperatorModule,
KycProcedureModule,
PrepareSignatureModule,
EscrowUtilsModule,
],
controllers: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,41 @@ export const gatewayConfigServiceMock = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
},
EMAIL_VERIFICATION: {
endpoint: '/auth/email-verification',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
},
RESEND_EMAIL_VERIFICATION: {
endpoint: '/auth/resend-email-verification',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
},
FORGOT_PASSWORD: {
endpoint: '/auth/forgot-password',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
},
RESTORE_PASSWORD: {
endpoint: '/auth/restore-password',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
},
PREPARE_SIGNATURE: {
endpoint: '/web3/prepare-signature',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
},
DISABLE_OPERATOR: {
endpoint: '/user/disable-operator',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
},
KYC_PROCEDURE_START: {
endpoint: '/kyc/start',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
},
},
}),
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,41 @@ export class GatewayConfigService {
method: HttpMethod.POST,
headers: this.JSON_HEADER,
},
[EndpointName.EMAIL_VERIFICATION]: {
endpoint: '/auth/email-verification',
method: HttpMethod.POST,
headers: this.JSON_HEADER,
},
[EndpointName.RESEND_EMAIL_VERIFICATION]: {
endpoint: '/auth/resend-email-verification',
method: HttpMethod.POST,
headers: this.JSON_HEADER,
},
[EndpointName.FORGOT_PASSWORD]: {
endpoint: '/auth/forgot-password',
method: HttpMethod.POST,
headers: this.JSON_HEADER,
},
[EndpointName.RESTORE_PASSWORD]: {
endpoint: '/auth/restore-password',
method: HttpMethod.POST,
headers: this.JSON_HEADER,
},
[EndpointName.PREPARE_SIGNATURE]: {
endpoint: '/web3/prepare-signature',
method: HttpMethod.POST,
headers: this.JSON_HEADER,
},
[EndpointName.DISABLE_OPERATOR]: {
endpoint: '/user/disable-operator',
method: HttpMethod.POST,
headers: this.JSON_HEADER,
},
[EndpointName.KYC_PROCEDURE_START]: {
endpoint: '/kyc/start',
method: HttpMethod.POST,
headers: this.JSON_HEADER,
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ export enum EndpointName {
WORKER_SIGNUP = 'WORKER_SIGNUP',
OPERATOR_SIGNUP = 'OPERATOR_SIGNUP',
WORKER_SIGNIN = 'WORKER_SIGNIN',
EMAIL_VERIFICATION = 'EMAIL_VERIFICATION',
RESEND_EMAIL_VERIFICATION = 'RESEND_EMAIL_VERIFICATION',
FORGOT_PASSWORD = 'FORGOT_PASSWORD',
RESTORE_PASSWORD = 'RESTORE_PASSWORD',
PREPARE_SIGNATURE = 'PREPARE_SIGNATURE',
DISABLE_OPERATOR = 'DISABLE_OPERATOR',
KYC_PROCEDURE_START = 'KYC_PROCEDURE_START',
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ export enum AssignmentSortField {
CREATED_AT = 'created_at',
EXPIRES_AT = 'expires_at',
}
export enum PrepareSignatureType {
SIGNUP = 'SIGNUP',
DISABLE_OPERATOR = 'DISABLE_OPERATOR',
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,40 @@ import { GatewayConfig } from '../../common/interfaces/endpoint.interface';
import { ExternalApiName } from '../../common/enums/external-api-name';
import { EndpointName } from '../../common/enums/endpoint-name';
import { AxiosRequestConfig } from 'axios';
import { RequestDataType } from './reputation-oracle.interface';
import { EmptyData, RequestDataType } from './reputation-oracle.interface';
import {
SigninWorkerCommand,
SigninWorkerData,
SigninWorkerResponse,
} from '../../modules/user-worker/model/worker-signin.model';
import {
EmailVerificationCommand,
EmailVerificationData,
} from '../../modules/email-confirmation/model/email-verification.model';
import {
ResendEmailVerificationCommand,
ResendEmailVerificationData,
ResendEmailVerificationParams,
} from '../../modules/email-confirmation/model/resend-email-verification.model';
import {
ForgotPasswordCommand,
ForgotPasswordData,
} from '../../modules/password-reset/model/forgot-password.model';
import {
RestorePasswordCommand,
RestorePasswordData,
} from '../../modules/password-reset/model/restore-password.model';
import {
PrepareSignatureCommand,
PrepareSignatureData,
PrepareSignatureResponse,
} from '../../modules/prepare-signature/model/prepare-signature.model';
import {
DisableOperatorCommand,
DisableOperatorData,
DisableOperatorParams,
} from '../../modules/disable-operator/model/disable-operator.model';
import { KycProcedureStartResponse } from '../../modules/kyc-procedure/model/kyc-start.model';

@Injectable()
export class ReputationOracleGateway {
Expand All @@ -38,13 +66,18 @@ export class ReputationOracleGateway {
private getEndpointOptions(
endpointName: EndpointName,
data: RequestDataType,
token?: string,
) {
const { method, endpoint, headers } =
this.reputationOracleConfig.endpoints[endpointName];
const authHeader = token ? { Authorization: token } : {};
return {
method: method,
url: `${this.reputationOracleConfig.url}${endpoint}`,
headers: headers,
headers: {
...authHeader,
...headers,
},
data: data,
};
}
Expand Down Expand Up @@ -94,4 +127,100 @@ export class ReputationOracleGateway {
);
return this.handleRequestToReputationOracle<SigninWorkerResponse>(options);
}

async sendEmailVerification(
emailVerificationCommand: EmailVerificationCommand,
) {
const emailVerificationData = this.mapper.map(
emailVerificationCommand,
EmailVerificationCommand,
EmailVerificationData,
);
const options = this.getEndpointOptions(
EndpointName.EMAIL_VERIFICATION,
emailVerificationData,
);
return this.handleRequestToReputationOracle<void>(options);
}

async sendResendEmailVerification(
resendEmailVerificationCommand: ResendEmailVerificationCommand,
) {
const resendEmailVerificationData = this.mapper.map(
resendEmailVerificationCommand.data,
ResendEmailVerificationParams,
ResendEmailVerificationData,
);
const options = this.getEndpointOptions(
EndpointName.RESEND_EMAIL_VERIFICATION,
resendEmailVerificationData,
resendEmailVerificationCommand.token,
);
return this.handleRequestToReputationOracle<void>(options);
}

async sendForgotPassword(forgotPasswordCommand: ForgotPasswordCommand) {
const forgotPasswordData = this.mapper.map(
forgotPasswordCommand,
ForgotPasswordCommand,
ForgotPasswordData,
);
const options = this.getEndpointOptions(
EndpointName.FORGOT_PASSWORD,
forgotPasswordData,
);
return this.handleRequestToReputationOracle<void>(options);
}

async sendRestorePassword(restorePasswordCommand: RestorePasswordCommand) {
const restorePasswordData = this.mapper.map(
restorePasswordCommand,
RestorePasswordCommand,
RestorePasswordData,
);
const options = this.getEndpointOptions(
EndpointName.RESTORE_PASSWORD,
restorePasswordData,
);
return this.handleRequestToReputationOracle<void>(options);
}

async sendPrepareSignature(prepareSignatureCommand: PrepareSignatureCommand) {
const prepareSignatureData = this.mapper.map(
prepareSignatureCommand,
PrepareSignatureCommand,
PrepareSignatureData,
);
const options = this.getEndpointOptions(
EndpointName.PREPARE_SIGNATURE,
prepareSignatureData,
);
return this.handleRequestToReputationOracle<PrepareSignatureResponse>(
options,
);
}

async sendDisableOperator(disableOperatorCommand: DisableOperatorCommand) {
const disableOperatorData = this.mapper.map(
disableOperatorCommand.data,
DisableOperatorParams,
DisableOperatorData,
);
const options = this.getEndpointOptions(
EndpointName.DISABLE_OPERATOR,
disableOperatorData,
disableOperatorCommand.token,
);
return this.handleRequestToReputationOracle<void>(options);
}

async sendKycProcedureStart() {
const options = this.getEndpointOptions(
EndpointName.KYC_PROCEDURE_START,
EmptyData,
);
return this.handleRequestToReputationOracle<KycProcedureStartResponse>(
options,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { SignupWorkerData } from '../../modules/user-worker/model/worker-registration.model';
import { SignupOperatorData } from '../../modules/user-operator/model/operator-registration.model';
import { SigninWorkerData } from '../../modules/user-worker/model/worker-signin.model';
import { EmailVerificationData } from '../../modules/email-confirmation/model/email-verification.model';
import { ResendEmailVerificationData } from '../../modules/email-confirmation/model/resend-email-verification.model';
import { PrepareSignatureData } from '../../modules/prepare-signature/model/prepare-signature.model';
import { DisableOperatorData } from '../../modules/disable-operator/model/disable-operator.model';

export class EmptyData {}

export type RequestDataType =
| EmptyData
| SignupWorkerData
| SignupOperatorData
| SigninWorkerData;
| SigninWorkerData
| EmailVerificationData
| ResendEmailVerificationData
| PrepareSignatureData
| DisableOperatorData;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ export const reputationOracleGatewayMock = {
sendWorkerSignup: jest.fn(),
sendOperatorSignup: jest.fn(),
sendWorkerSignin: jest.fn(),
sendEmailVerification: jest.fn(),
sendResendEmailVerification: jest.fn(),
sendForgotPassword: jest.fn(),
sendRestorePassword: jest.fn(),
sendPrepareSignature: jest.fn(),
sendDisableOperator: jest.fn(),
sendKycProcedureStart: jest.fn(),
};
Loading

0 comments on commit 74cce2e

Please sign in to comment.