Skip to content

Commit

Permalink
refactor(core): refactor experience API context type
Browse files Browse the repository at this point in the history
refactor experience API context type
  • Loading branch information
simeng-li committed Jul 31, 2024
1 parent f83265e commit 52363fc
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 40 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/routes/experience/profile-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import assertThat from '#src/utils/assert-that.js';

import { identifierCodeVerificationTypeMap } from './classes/verifications/code-verification.js';
import { experienceRoutes } from './const.js';
import { type WithExperienceInteractionContext } from './middleware/koa-experience-interaction.js';
import { type ExperienceInteractionRouterContext } from './types.js';

/**
* @throws {RequestError} with status 400 if current interaction is ForgotPassword
Expand All @@ -27,7 +27,7 @@ function verifiedInteractionGuard<
StateT,
ContextT extends WithLogContext,
ResponseT,
>(): MiddlewareType<StateT, WithExperienceInteractionContext<ContextT>, ResponseT> {
>(): MiddlewareType<StateT, ExperienceInteractionRouterContext<ContextT>, ResponseT> {
return async (ctx, next) => {
const { experienceInteraction } = ctx;

Expand All @@ -47,8 +47,8 @@ function verifiedInteractionGuard<
};
}

export default function interactionProfileRoutes<T extends WithLogContext>(
router: Router<unknown, WithExperienceInteractionContext<T>>,
export default function interactionProfileRoutes<T extends ExperienceInteractionRouterContext>(
router: Router<unknown, T>,
tenant: TenantContext
) {
router.post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import { backupCodeVerificationVerifyPayloadGuard } from '@logto/schemas';
import type Router from 'koa-router';
import { z } from 'zod';

import { type WithLogContext } from '#src/middleware/koa-audit-log.js';
import koaGuard from '#src/middleware/koa-guard.js';
import type TenantContext from '#src/tenants/TenantContext.js';
import assertThat from '#src/utils/assert-that.js';

import { BackupCodeVerification } from '../classes/verifications/backup-code-verification.js';
import { experienceRoutes } from '../const.js';
import { type WithExperienceInteractionContext } from '../middleware/koa-experience-interaction.js';
import { type ExperienceInteractionRouterContext } from '../types.js';

export default function backupCodeVerificationRoutes<T extends WithLogContext>(
router: Router<unknown, WithExperienceInteractionContext<T>>,
export default function backupCodeVerificationRoutes<T extends ExperienceInteractionRouterContext>(
router: Router<unknown, T>,
tenantContext: TenantContext
) {
const { libraries, queries } = tenantContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@ import type Router from 'koa-router';
import { z } from 'zod';

import RequestError from '#src/errors/RequestError/index.js';
import { type WithLogContext } from '#src/middleware/koa-audit-log.js';
import koaGuard from '#src/middleware/koa-guard.js';
import type TenantContext from '#src/tenants/TenantContext.js';
import assertThat from '#src/utils/assert-that.js';

import { EnterpriseSsoVerification } from '../classes/verifications/enterprise-sso-verification.js';
import { experienceRoutes } from '../const.js';
import { type WithExperienceInteractionContext } from '../middleware/koa-experience-interaction.js';
import { type ExperienceInteractionRouterContext } from '../types.js';

export default function enterpriseSsoVerificationRoutes<T extends WithLogContext>(
router: Router<unknown, WithExperienceInteractionContext<T>>,
tenantContext: TenantContext
) {
export default function enterpriseSsoVerificationRoutes<
T extends ExperienceInteractionRouterContext,
>(router: Router<unknown, T>, tenantContext: TenantContext) {
const { libraries, queries } = tenantContext;

router.post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ import { newPasswordIdentityVerificationPayloadGuard } from '@logto/schemas';
import type Router from 'koa-router';
import { z } from 'zod';

import { type WithLogContext } from '#src/middleware/koa-audit-log.js';
import koaGuard from '#src/middleware/koa-guard.js';
import type TenantContext from '#src/tenants/TenantContext.js';

import { NewPasswordIdentityVerification } from '../classes/verifications/new-password-identity-verification.js';
import { experienceRoutes } from '../const.js';
import { type WithExperienceInteractionContext } from '../middleware/koa-experience-interaction.js';
import { type ExperienceInteractionRouterContext } from '../types.js';

export default function newPasswordIdentityVerificationRoutes<T extends WithLogContext>(
router: Router<unknown, WithExperienceInteractionContext<T>>,
{ libraries, queries }: TenantContext
) {
export default function newPasswordIdentityVerificationRoutes<
T extends ExperienceInteractionRouterContext,
>(router: Router<unknown, T>, { libraries, queries }: TenantContext) {
router.post(
`${experienceRoutes.verification}/new-password-identity`,
koaGuard({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import { passwordVerificationPayloadGuard } from '@logto/schemas';
import type Router from 'koa-router';
import { z } from 'zod';

import { type WithLogContext } from '#src/middleware/koa-audit-log.js';
import koaGuard from '#src/middleware/koa-guard.js';
import type TenantContext from '#src/tenants/TenantContext.js';

import { PasswordVerification } from '../classes/verifications/password-verification.js';
import { experienceRoutes } from '../const.js';
import { type WithExperienceInteractionContext } from '../middleware/koa-experience-interaction.js';
import { type ExperienceInteractionRouterContext } from '../types.js';

export default function passwordVerificationRoutes<T extends WithLogContext>(
router: Router<unknown, WithExperienceInteractionContext<T>>,
export default function passwordVerificationRoutes<T extends ExperienceInteractionRouterContext>(
router: Router<unknown, T>,
{ libraries, queries }: TenantContext
) {
router.post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ import type Router from 'koa-router';
import { z } from 'zod';

import RequestError from '#src/errors/RequestError/index.js';
import { type WithLogContext } from '#src/middleware/koa-audit-log.js';
import koaGuard from '#src/middleware/koa-guard.js';
import type TenantContext from '#src/tenants/TenantContext.js';
import assertThat from '#src/utils/assert-that.js';

import { SocialVerification } from '../classes/verifications/social-verification.js';
import { experienceRoutes } from '../const.js';
import { type WithExperienceInteractionContext } from '../middleware/koa-experience-interaction.js';
import { type ExperienceInteractionRouterContext } from '../types.js';

export default function socialVerificationRoutes<T extends WithLogContext>(
router: Router<unknown, WithExperienceInteractionContext<T>>,
export default function socialVerificationRoutes<T extends ExperienceInteractionRouterContext>(
router: Router<unknown, T>,
tenantContext: TenantContext
) {
const { libraries, queries } = tenantContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import type Router from 'koa-router';
import { z } from 'zod';

import RequestError from '#src/errors/RequestError/index.js';
import { type WithLogContext } from '#src/middleware/koa-audit-log.js';
import koaGuard from '#src/middleware/koa-guard.js';
import type TenantContext from '#src/tenants/TenantContext.js';
import assertThat from '#src/utils/assert-that.js';

import { TotpVerification } from '../classes/verifications/totp-verification.js';
import { experienceRoutes } from '../const.js';
import { type WithExperienceInteractionContext } from '../middleware/koa-experience-interaction.js';
import { type ExperienceInteractionRouterContext } from '../types.js';

export default function totpVerificationRoutes<T extends WithLogContext>(
router: Router<unknown, WithExperienceInteractionContext<T>>,
export default function totpVerificationRoutes<T extends ExperienceInteractionRouterContext>(
router: Router<unknown, T>,
tenantContext: TenantContext
) {
const { libraries, queries } = tenantContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import { InteractionEvent, verificationCodeIdentifierGuard } from '@logto/schema
import type Router from 'koa-router';
import { z } from 'zod';

import { type WithLogContext } from '#src/middleware/koa-audit-log.js';
import koaGuard from '#src/middleware/koa-guard.js';
import type TenantContext from '#src/tenants/TenantContext.js';

import { codeVerificationIdentifierRecordTypeMap } from '../classes/utils.js';
import { createNewCodeVerificationRecord } from '../classes/verifications/code-verification.js';
import { experienceRoutes } from '../const.js';
import { type WithExperienceInteractionContext } from '../middleware/koa-experience-interaction.js';
import { type ExperienceInteractionRouterContext } from '../types.js';

export default function verificationCodeRoutes<T extends WithLogContext>(
router: Router<unknown, WithExperienceInteractionContext<T>>,
export default function verificationCodeRoutes<T extends ExperienceInteractionRouterContext>(
router: Router<unknown, T>,
{ libraries, queries }: TenantContext
) {
router.post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ import type Router from 'koa-router';
import { z } from 'zod';

import RequestError from '#src/errors/RequestError/index.js';
import { type WithLogContext } from '#src/middleware/koa-audit-log.js';
import koaGuard from '#src/middleware/koa-guard.js';
import type TenantContext from '#src/tenants/TenantContext.js';
import assertThat from '#src/utils/assert-that.js';

import { WebAuthnVerification } from '../classes/verifications/web-authn-verification.js';
import { experienceRoutes } from '../const.js';
import { type WithExperienceInteractionContext } from '../middleware/koa-experience-interaction.js';
import { type ExperienceInteractionRouterContext } from '../types.js';

export default function webAuthnVerificationRoute<T extends WithLogContext>(
router: Router<unknown, WithExperienceInteractionContext<T>>,
export default function webAuthnVerificationRoute<T extends ExperienceInteractionRouterContext>(
router: Router<unknown, T>,
tenantContext: TenantContext
) {
const { libraries, queries } = tenantContext;
Expand Down

0 comments on commit 52363fc

Please sign in to comment.