Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): rename prefix to account #6814

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/core/src/routes/account-center/index.openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"paths": {
"/api/account-center": {
"get": {
"operationId": "GetAccountCenterSettings",
"summary": "Get account center settings",
"description": "Get the account center settings.",
"responses": {
Expand All @@ -20,6 +21,7 @@
}
},
"patch": {
"operationId": "UpdateAccountCenterSettings",
"summary": "Update account center settings",
"description": "Update the account center settings with the provided settings.",
"requestBody": {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/routes/account/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const accountApiPrefix = '/account';
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { buildVerificationRecordByIdAndType } from '../../libraries/verification
import assertThat from '../../utils/assert-that.js';
import type { UserRouter, RouterInitArgs } from '../types.js';

import { accountApiPrefix } from './constants.js';

export default function emailAndPhoneRoutes<T extends UserRouter>(...args: RouterInitArgs<T>) {
const [router, { queries, libraries }] = args;
const {
Expand All @@ -21,7 +23,7 @@ export default function emailAndPhoneRoutes<T extends UserRouter>(...args: Route
} = libraries;

router.post(
'/profile/primary-email',
`${accountApiPrefix}/primary-email`,
koaGuard({
body: z.object({
email: z.string().regex(emailRegEx),
Expand Down Expand Up @@ -67,7 +69,7 @@ export default function emailAndPhoneRoutes<T extends UserRouter>(...args: Route
);

router.delete(
'/profile/primary-email',
`${accountApiPrefix}/primary-email`,
koaGuard({
status: [204, 400, 401],
}),
Expand Down Expand Up @@ -106,7 +108,7 @@ export default function emailAndPhoneRoutes<T extends UserRouter>(...args: Route
);

router.post(
'/profile/primary-phone',
`${accountApiPrefix}/primary-phone`,
koaGuard({
body: z.object({
phone: z.string().regex(phoneRegEx),
Expand Down Expand Up @@ -152,7 +154,7 @@ export default function emailAndPhoneRoutes<T extends UserRouter>(...args: Route
);

router.delete(
'/profile/primary-phone',
`${accountApiPrefix}/primary-phone`,
koaGuard({
status: [204, 400, 401],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { buildVerificationRecordByIdAndType } from '../../libraries/verification
import assertThat from '../../utils/assert-that.js';
import type { UserRouter, RouterInitArgs } from '../types.js';

import { accountApiPrefix } from './constants.js';

export default function identitiesRoutes<T extends UserRouter>(
...[router, { queries, libraries }]: RouterInitArgs<T>
) {
Expand All @@ -21,7 +23,7 @@ export default function identitiesRoutes<T extends UserRouter>(
} = libraries;

router.post(
'/profile/identities',
`${accountApiPrefix}/identities`,
koaGuard({
body: z.object({
newIdentifierVerificationRecordId: z.string(),
Expand Down Expand Up @@ -81,7 +83,7 @@ export default function identitiesRoutes<T extends UserRouter>(
);

router.delete(
'/profile/identities/:target',
`${accountApiPrefix}/identities/:target`,
koaGuard({
params: z.object({ target: z.string() }),
status: [204, 400, 401, 404],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"tags": [
{
"name": "Profile",
"description": "Profile routes provide functionality for managing user profiles for the end user to interact directly with access tokens."
"name": "Account",
"description": "Account routes provide functionality for managing user profile for the end user to interact directly with access tokens."
},
{
"name": "Dev feature"
}
],
"paths": {
"/api/profile": {
"/api/account": {
"get": {
"operationId": "GetProfile",
"summary": "Get profile",
Expand Down Expand Up @@ -56,7 +56,7 @@
}
}
},
"/api/profile/profile": {
"/api/account/profile": {
"patch": {
"operationId": "UpdateOtherProfile",
"summary": "Update other profile",
Expand Down Expand Up @@ -114,7 +114,7 @@
}
}
},
"/api/profile/password": {
"/api/account/password": {
"post": {
"operationId": "UpdatePassword",
"summary": "Update password",
Expand Down Expand Up @@ -142,7 +142,7 @@
}
}
},
"/api/profile/primary-email": {
"/api/account/primary-email": {
"post": {
"operationId": "UpdatePrimaryEmail",
"summary": "Update primary email",
Expand Down Expand Up @@ -186,7 +186,7 @@
}
}
},
"/api/profile/primary-phone": {
"/api/account/primary-phone": {
"post": {
"operationId": "UpdatePrimaryPhone",
"summary": "Update primary phone",
Expand Down Expand Up @@ -230,7 +230,7 @@
}
}
},
"/api/profile/identities": {
"/api/account/identities": {
"post": {
"operationId": "AddUserIdentities",
"summary": "Add a user identity",
Expand All @@ -255,7 +255,7 @@
}
}
},
"/api/profile/identities/{target}": {
"/api/account/identities/{target}": {
"delete": {
"operationId": "DeleteIdentity",
"summary": "Delete a user identity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import assertThat from '../../utils/assert-that.js';
import { PasswordValidator } from '../experience/classes/libraries/password-validator.js';
import type { UserRouter, RouterInitArgs } from '../types.js';

import { accountApiPrefix } from './constants.js';
import emailAndPhoneRoutes from './email-and-phone.js';
import identitiesRoutes from './identities.js';
import koaAccountCenter from './middlewares/koa-account-center.js';
import { getAccountCenterFilteredProfile, getScopedProfile } from './utils/get-scoped-profile.js';

export default function profileRoutes<T extends UserRouter>(...args: RouterInitArgs<T>) {
export default function accountRoutes<T extends UserRouter>(...args: RouterInitArgs<T>) {
const [router, { queries, libraries }] = args;
const {
users: { updateUserById, findUserById },
Expand All @@ -39,7 +40,7 @@ export default function profileRoutes<T extends UserRouter>(...args: RouterInitA
}

router.get(
'/profile',
`${accountApiPrefix}`,
koaGuard({
response: userProfileResponseGuard.partial(),
status: [200],
Expand All @@ -53,7 +54,7 @@ export default function profileRoutes<T extends UserRouter>(...args: RouterInitA
);

router.patch(
'/profile',
`${accountApiPrefix}`,
koaGuard({
body: z.object({
name: z.string().nullable().optional(),
Expand Down Expand Up @@ -111,7 +112,7 @@ export default function profileRoutes<T extends UserRouter>(...args: RouterInitA
);

router.patch(
'/profile/profile',
`${accountApiPrefix}/profile`,
koaGuard({
body: userProfileGuard,
response: userProfileGuard,
Expand Down Expand Up @@ -146,7 +147,7 @@ export default function profileRoutes<T extends UserRouter>(...args: RouterInitA
);

router.post(
'/profile/password',
`${accountApiPrefix}/password`,
koaGuard({
body: z.object({ password: z.string().min(1) }),
status: [204, 400, 401, 422],
Expand Down
9 changes: 5 additions & 4 deletions packages/core/src/routes/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import koaOidcAuth from '../middleware/koa-auth/koa-oidc-auth.js';
import koaCors from '../middleware/koa-cors.js';

import { accountApiPrefix } from './account/constants.js';
import accountRoutes from './account/index.js';
import accountCentersRoutes from './account-center/index.js';
import adminUserRoutes from './admin-user/index.js';
import applicationOrganizationRoutes from './applications/application-organization.js';
Expand All @@ -34,7 +36,6 @@
import logRoutes from './log.js';
import logtoConfigRoutes from './logto-config/index.js';
import organizationRoutes from './organization/index.js';
import profileRoutes from './profile/index.js';
import resourceRoutes from './resource.js';
import resourceScopeRoutes from './resource.scope.js';
import roleRoutes from './role.js';
Expand All @@ -47,7 +48,7 @@
import systemRoutes from './system.js';
import type { AnonymousRouter, ManagementApiRouter, UserRouter } from './types.js';
import userAssetsRoutes from './user-assets.js';
import verificationRoutes from './verification/index.js';
import verificationRoutes, { verificationApiPrefix } from './verification/index.js';
import verificationCodeRoutes from './verification-code.js';
import wellKnownRoutes from './well-known/index.js';
import wellKnownOpenApiRoutes from './well-known/well-known.openapi.js';
Expand All @@ -66,7 +67,7 @@
managementRouter.use(koaTenantGuard(tenant.id, tenant.queries));
managementRouter.use(koaManagementApiHooks(tenant.libraries.hooks));

// TODO: FIXME @sijie @darcy mount these routes in `applicationRoutes` instead

Check warning on line 70 in packages/core/src/routes/init.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/core/src/routes/init.ts#L70

[no-warning-comments] Unexpected 'todo' comment: 'TODO: FIXME @sijie @darcy mount these...'.
applicationRoutes(managementRouter, tenant);
applicationRoleRoutes(managementRouter, tenant);
applicationProtectedAppMetadataRoutes(managementRouter, tenant);
Expand Down Expand Up @@ -105,9 +106,9 @@

const userRouter: UserRouter = new Router();
userRouter.use(koaOidcAuth(tenant));
// TODO(LOG-10147): Rename to koaApiHooks, this middleware is used for both management API and user API

Check warning on line 109 in packages/core/src/routes/init.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/core/src/routes/init.ts#L109

[no-warning-comments] Unexpected 'todo' comment: 'TODO(LOG-10147): Rename to koaApiHooks,...'.
userRouter.use(koaManagementApiHooks(tenant.libraries.hooks));
profileRoutes(userRouter, tenant);
accountRoutes(userRouter, tenant);
verificationRoutes(userRouter, tenant);

wellKnownRoutes(anonymousRouter, tenant);
Expand All @@ -126,7 +127,7 @@
anonymousRouter,
experienceRouter,
userRouter,
// TODO: interactionRouter should be removed from swagger.json

Check warning on line 130 in packages/core/src/routes/init.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/core/src/routes/init.ts#L130

[no-warning-comments] Unexpected 'todo' comment: 'TODO: interactionRouter should be...'.
interactionRouter,
]);

Expand All @@ -136,7 +137,7 @@
export default function initApis(tenant: TenantContext): Koa {
const apisApp = new Koa();
const { adminUrlSet, cloudUrlSet } = EnvSet.values;
apisApp.use(koaCors([adminUrlSet, cloudUrlSet], ['/profile', '/verifications']));
apisApp.use(koaCors([adminUrlSet, cloudUrlSet], [accountApiPrefix, verificationApiPrefix]));
apisApp.use(koaBodyEtag());

for (const router of createRouters(tenant)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/routes/swagger/utils/operation-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const exceptionPrefixes = Object.freeze([
'/interaction',
'/experience',
'/sign-in-exp/default/check-password',
'/profile',
'/account',
'/verifications',
]);

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/routes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { type WithHookContext } from '#src/middleware/koa-management-api-hooks.js';
import type TenantContext from '#src/tenants/TenantContext.js';

import { type WithAccountCenterContext } from './profile/middlewares/koa-account-center.js';
import { type WithAccountCenterContext } from './account/middlewares/koa-account-center.js';

Check warning on line 10 in packages/core/src/routes/types.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/routes/types.ts#L10

Added line #L10 was not covered by tests

export type AnonymousRouter = Router<unknown, WithLogContext & WithI18nContext>;

Expand Down
12 changes: 7 additions & 5 deletions packages/core/src/routes/verification/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { PasswordVerification } from '../experience/classes/verifications/passwo
import { SocialVerification } from '../experience/classes/verifications/social-verification.js';
import type { UserRouter, RouterInitArgs } from '../types.js';

export const verificationApiPrefix = '/verifications';

export default function verificationRoutes<T extends UserRouter>(
...[router, tenantContext]: RouterInitArgs<T>
) {
Expand All @@ -34,7 +36,7 @@ export default function verificationRoutes<T extends UserRouter>(
}

router.post(
'/verifications/password',
`${verificationApiPrefix}/password`,
koaGuard({
body: z.object({ password: z.string().min(1) }),
response: z.object({ verificationRecordId: z.string(), expiresAt: z.string() }),
Expand Down Expand Up @@ -76,7 +78,7 @@ export default function verificationRoutes<T extends UserRouter>(
);

router.post(
'/verifications/verification-code',
`${verificationApiPrefix}/verification-code`,
koaGuard({
body: z.object({
identifier: verificationCodeIdentifierGuard,
Expand Down Expand Up @@ -119,7 +121,7 @@ export default function verificationRoutes<T extends UserRouter>(
);

router.post(
'/verifications/verification-code/verify',
`${verificationApiPrefix}/verification-code/verify`,
koaGuard({
body: z.object({
identifier: verificationCodeIdentifierGuard,
Expand Down Expand Up @@ -164,7 +166,7 @@ export default function verificationRoutes<T extends UserRouter>(
);

router.post(
'/verifications/social',
`${verificationApiPrefix}/social`,
koaGuard({
body: socialAuthorizationUrlPayloadGuard.extend({
connectorId: z.string(),
Expand Down Expand Up @@ -202,7 +204,7 @@ export default function verificationRoutes<T extends UserRouter>(
);

router.post(
'/verifications/social/verify',
`${verificationApiPrefix}/social/verify`,
koaGuard({
body: socialVerificationCallbackPayloadGuard
.pick({
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/routes/well-known/well-known.openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

// Find supplemental documents
const supplementDocuments = await getSupplementDocuments('routes', {
excludeDirectories: ['experience', 'interaction', 'profile', 'verification'],
excludeDirectories: ['experience', 'interaction', 'account', 'verification'],

Check warning on line 34 in packages/core/src/routes/well-known/well-known.openapi.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/routes/well-known/well-known.openapi.ts#L34

Added line #L34 was not covered by tests
});
const baseDocument = buildManagementApiBaseDocument(pathMap, tags, ctx.request.origin);

Expand Down Expand Up @@ -71,7 +71,7 @@

// Find supplemental documents
const supplementDocuments = await getSupplementDocuments('routes', {
includeDirectories: ['profile', 'verification'],
includeDirectories: ['account', 'verification'],

Check warning on line 74 in packages/core/src/routes/well-known/well-known.openapi.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/routes/well-known/well-known.openapi.ts#L74

Added line #L74 was not covered by tests
});
const baseDocument = buildUserApiBaseDocument(pathMap, tags, ctx.request.origin);

Expand Down
Loading
Loading