0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00

refactor(core): reorg routes

This commit is contained in:
Gao Sun 2023-10-15 15:29:08 +08:00
parent d393741366
commit d792e754a2
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
14 changed files with 40 additions and 31 deletions

View file

@ -95,7 +95,7 @@ const usersLibraries = {
),
} satisfies Partial<Libraries['users']>;
const adminUserRoutes = await pickDefault(import('./admin-user.js'));
const adminUserRoutes = await pickDefault(import('./basics.js'));
describe('adminUserRoutes', () => {
const tenantContext = new MockTenant(undefined, mockedQueries, undefined, {

View file

@ -14,11 +14,10 @@ import koaGuard from '#src/middleware/koa-guard.js';
import assertThat from '#src/utils/assert-that.js';
import { transpileUserMfaVerifications } from '#src/utils/user.js';
import type { AuthedRouter, RouterInitArgs } from './types.js';
import type { AuthedRouter, RouterInitArgs } from '../types.js';
export default function adminUserRoutes<T extends AuthedRouter>(
...[router, { queries, libraries }]: RouterInitArgs<T>
) {
export default function adminUserBasicsRoutes<T extends AuthedRouter>(...args: RouterInitArgs<T>) {
const [router, { queries, libraries }] = args;
const {
oidcModelInstances: { revokeInstanceByUserId },
users: {

View file

@ -0,0 +1,13 @@
import type { AuthedRouter, RouterInitArgs } from '../types.js';
import adminUserBasicsRoutes from './basics.js';
import adminUserRoleRoutes from './role.js';
import adminUserSearchRoutes from './search.js';
import adminUserSocialRoutes from './social.js';
export default function adminUserRoutes<T extends AuthedRouter>(...args: RouterInitArgs<T>) {
adminUserBasicsRoutes(...args);
adminUserRoleRoutes(...args);
adminUserSearchRoutes(...args);
adminUserSocialRoutes(...args);
}

View file

@ -35,7 +35,7 @@ const { findRolesByRoleIds } = roles;
const tenantContext = new MockTenant(undefined, { usersRoles, users, roles });
const roleRoutes = await pickDefault(import('./admin-user-role.js'));
const roleRoutes = await pickDefault(import('./role.js'));
describe('user role routes', () => {
const roleRequester = createRequester({ authedRoutes: roleRoutes, tenantContext });

View file

@ -10,7 +10,7 @@ import koaRoleRlsErrorHandler from '#src/middleware/koa-role-rls-error-handler.j
import assertThat from '#src/utils/assert-that.js';
import { parseSearchParamsForSearch } from '#src/utils/search.js';
import type { AuthedRouter, RouterInitArgs } from './types.js';
import type { AuthedRouter, RouterInitArgs } from '../types.js';
export default function adminUserRoleRoutes<T extends AuthedRouter>(
...[router, { queries }]: RouterInitArgs<T>

View file

@ -60,7 +60,7 @@ const usersLibraries = {
),
} satisfies Partial<Libraries['users']>;
const adminUserRoutes = await pickDefault(import('./admin-user-search.js'));
const adminUserRoutes = await pickDefault(import('./search.js'));
describe('adminUserRoutes', () => {
const tenantContext = new MockTenant(undefined, mockedQueries, undefined, {

View file

@ -6,7 +6,7 @@ import koaGuard from '#src/middleware/koa-guard.js';
import koaPagination from '#src/middleware/koa-pagination.js';
import { parseSearchParamsForSearch } from '#src/utils/search.js';
import type { AuthedRouter, RouterInitArgs } from './types.js';
import type { AuthedRouter, RouterInitArgs } from '../types.js';
export default function adminUserSearchRoutes<T extends AuthedRouter>(
...[router, { queries }]: RouterInitArgs<T>

View file

@ -70,7 +70,7 @@ const mockedConnectors = {
const { findUserById, updateUserById, deleteUserIdentity } = mockedQueries.users;
const adminUserSocialRoutes = await pickDefault(import('./admin-user-social.js'));
const adminUserSocialRoutes = await pickDefault(import('./social.js'));
describe('Admin user social identities APIs', () => {
const tenantContext = new MockTenant(undefined, mockedQueries, mockedConnectors, {

View file

@ -12,7 +12,7 @@ import RequestError from '#src/errors/RequestError/index.js';
import koaGuard from '#src/middleware/koa-guard.js';
import assertThat from '#src/utils/assert-that.js';
import type { AuthedRouter, RouterInitArgs } from './types.js';
import type { AuthedRouter, RouterInitArgs } from '../types.js';
export default function adminUserSocialRoutes<T extends AuthedRouter>(
...[router, tenant]: RouterInitArgs<T>

View file

@ -10,10 +10,7 @@ import type TenantContext from '#src/tenants/TenantContext.js';
import koaAuth from '../middleware/koa-auth/index.js';
import adminUserRoleRoutes from './admin-user-role.js';
import adminUserSearchRoutes from './admin-user-search.js';
import adminUserSocialRoutes from './admin-user-social.js';
import adminUserRoutes from './admin-user.js';
import adminUserRoutes from './admin-user/index.js';
import applicationRoleRoutes from './application-role.js';
import applicationRoutes from './application.js';
import authnRoutes from './authn.js';
@ -25,9 +22,7 @@ import hookRoutes from './hook.js';
import interactionRoutes from './interaction/index.js';
import logRoutes from './log.js';
import logtoConfigRoutes from './logto-config.js';
import organizationRoleRoutes from './organization-roles.js';
import organizationScopeRoutes from './organization-scopes.js';
import organizationRoutes from './organizations.js';
import organizationRoutes from './organization/index.js';
import resourceRoutes from './resource.js';
import roleRoutes from './role.js';
import roleScopeRoutes from './role.scope.js';
@ -54,9 +49,6 @@ const createRouters = (tenant: TenantContext) => {
resourceRoutes(managementRouter, tenant);
signInExperiencesRoutes(managementRouter, tenant);
adminUserRoutes(managementRouter, tenant);
adminUserSearchRoutes(managementRouter, tenant);
adminUserRoleRoutes(managementRouter, tenant);
adminUserSocialRoutes(managementRouter, tenant);
logRoutes(managementRouter, tenant);
roleRoutes(managementRouter, tenant);
roleScopeRoutes(managementRouter, tenant);
@ -67,8 +59,6 @@ const createRouters = (tenant: TenantContext) => {
userAssetsRoutes(managementRouter, tenant);
domainRoutes(managementRouter, tenant);
organizationRoutes(managementRouter, tenant);
organizationScopeRoutes(managementRouter, tenant);
organizationRoleRoutes(managementRouter, tenant);
const anonymousRouter: AnonymousRouter = new Router();
wellKnownRoutes(anonymousRouter, tenant);

View file

@ -5,16 +5,18 @@ import RequestError from '#src/errors/RequestError/index.js';
import koaGuard from '#src/middleware/koa-guard.js';
import SchemaRouter, { SchemaActions } from '#src/utils/SchemaRouter.js';
import { type AuthedRouter, type RouterInitArgs } from './types.js';
import { type AuthedRouter, type RouterInitArgs } from '../types.js';
export default function organizationRoutes<T extends AuthedRouter>(
...[
import organizationRoleRoutes from './roles.js';
import organizationScopeRoutes from './scopes.js';
export default function organizationRoutes<T extends AuthedRouter>(...args: RouterInitArgs<T>) {
const [
originalRouter,
{
queries: { organizations, users },
},
]: RouterInitArgs<T>
) {
] = args;
const router = new SchemaRouter(Organizations, new SchemaActions(organizations));
router.addRelationRoutes(organizations.relations.users);
@ -91,5 +93,10 @@ export default function organizationRoutes<T extends AuthedRouter>(
}
);
// MARK: Mount sub-routes
organizationRoleRoutes(...args);
organizationScopeRoutes(...args);
// Add routes to the router
originalRouter.use(router.routes());
}

View file

@ -11,7 +11,7 @@ import RequestError from '#src/errors/RequestError/index.js';
import koaGuard from '#src/middleware/koa-guard.js';
import SchemaRouter, { SchemaActions } from '#src/utils/SchemaRouter.js';
import { type AuthedRouter, type RouterInitArgs } from './types.js';
import { type AuthedRouter, type RouterInitArgs } from '../types.js';
class OrganizationRoleActions extends SchemaActions<
OrganizationRoleKeys,

View file

@ -2,7 +2,7 @@ import { UniqueIntegrityConstraintViolationError } from 'slonik';
import RequestError from '#src/errors/RequestError/index.js';
import { OrganizationScopeActions } from './organization-scopes.js';
import { OrganizationScopeActions } from './scopes.js';
describe('OrganizationScopeActions', () => {
it('should throw RequestError if UniqueIntegrityConstraintViolationError is thrown inside', async () => {

View file

@ -9,7 +9,7 @@ import { UniqueIntegrityConstraintViolationError } from 'slonik';
import RequestError from '#src/errors/RequestError/index.js';
import SchemaRouter, { SchemaActions } from '#src/utils/SchemaRouter.js';
import { type AuthedRouter, type RouterInitArgs } from './types.js';
import { type AuthedRouter, type RouterInitArgs } from '../types.js';
export class OrganizationScopeActions extends SchemaActions<
OrganizationScopeKeys,