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:
parent
d393741366
commit
d792e754a2
14 changed files with 40 additions and 31 deletions
|
@ -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, {
|
|
@ -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: {
|
13
packages/core/src/routes/admin-user/index.ts
Normal file
13
packages/core/src/routes/admin-user/index.ts
Normal 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);
|
||||
}
|
|
@ -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 });
|
|
@ -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>
|
|
@ -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, {
|
|
@ -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>
|
|
@ -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, {
|
|
@ -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>
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
}
|
|
@ -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,
|
|
@ -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 () => {
|
|
@ -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,
|
Loading…
Reference in a new issue