diff --git a/api/package-lock.json b/api/package-lock.json deleted file mode 100644 index a1493f2f2..000000000 --- a/api/package-lock.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "api", - "lockfileVersion": 3, - "requires": true, - "packages": {} -} diff --git a/idp/src/account/service.ts b/idp/src/account/service.ts index 2755acca6..692a93273 100644 --- a/idp/src/account/service.ts +++ b/idp/src/account/service.ts @@ -16,7 +16,10 @@ import { import { newHashId, newHyphenlessUuid } from '@/infra/id.ts' import { sendTemplateMail } from '@/infra/mail.ts' import { hashPassword } from '@/infra/password.ts' -import search, { USER_SEARCH_INDEX } from '@/infra/search.ts' +import { + client as meilisearch, + USER_SEARCH_INDEX, +} from '../infra/meilisearch.ts' import { User } from '@/user/model.ts' import userRepo from '@/user/repo.ts' import { getUserCount, mapEntity, UserDTO } from '@/user/service.ts' @@ -73,7 +76,7 @@ export async function createUser( createTime: newDateTime(), isAdmin: options.isAdmin, }) - await search.index(USER_SEARCH_INDEX).addDocuments([ + await meilisearch.index(USER_SEARCH_INDEX).addDocuments([ { id: user.id, username: user.username, @@ -91,7 +94,7 @@ export async function createUser( return mapEntity(user) } catch (error) { await userRepo.delete(id) - await search.index(USER_SEARCH_INDEX).deleteDocuments([id]) + await meilisearch.index(USER_SEARCH_INDEX).deleteDocuments([id]) throw newInternalServerError(error) } } @@ -111,7 +114,7 @@ export async function confirmEmail(options: AccountConfirmEmailOptions) { isEmailConfirmed: true, emailConfirmationToken: null, }) - await search.index(USER_SEARCH_INDEX).updateDocuments([ + await meilisearch.index(USER_SEARCH_INDEX).updateDocuments([ { id: user.id, username: user.username, diff --git a/idp/src/health/router.ts b/idp/src/health/router.ts index 543ea8d34..8c9d8a6a2 100644 --- a/idp/src/health/router.ts +++ b/idp/src/health/router.ts @@ -8,25 +8,21 @@ // by the GNU Affero General Public License v3.0 only, included in the file // AGPL-3.0-only in the root of this repository. import { Request, Response, Router } from 'express' -import { Client as PgClient } from 'https://deno.land/x/postgres@v0.19.3/mod.ts' -import { getConfig } from '@/config/config.ts' +import { client as postgres } from '@/infra/postgres.ts' +import { client as meilisearch } from '@/infra/meilisearch.ts' const router = Router() router.get('', async (_: Request, res: Response) => { - let pg: PgClient | undefined - try { - pg = new PgClient(getConfig().databaseURL) - await pg.connect() - await pg.queryObject('SELECT 1') - res.send('OK') - } catch { + if (!postgres.connected) { res.sendStatus(503) - } finally { - if (pg) { - await pg.end() - } + return } + if (!(await meilisearch.isHealthy())) { + res.sendStatus(503) + return + } + res.send('OK') }) export default router diff --git a/idp/src/infra/search.ts b/idp/src/infra/meilisearch.ts similarity index 87% rename from idp/src/infra/search.ts rename to idp/src/infra/meilisearch.ts index 7d4370b8e..b776cdb05 100644 --- a/idp/src/infra/search.ts +++ b/idp/src/infra/meilisearch.ts @@ -12,7 +12,5 @@ import { getConfig } from '@/config/config.ts' export const USER_SEARCH_INDEX = 'user' -const client = new MeiliSearch({ host: getConfig().search.url }) +export const client = new MeiliSearch({ host: getConfig().search.url }) client.createIndex(USER_SEARCH_INDEX, { primaryKey: 'id' }).then() - -export default client diff --git a/idp/src/user/service.ts b/idp/src/user/service.ts index a43ba3079..63c6066ca 100644 --- a/idp/src/user/service.ts +++ b/idp/src/user/service.ts @@ -28,7 +28,10 @@ import { ErrorCode, newError } from '@/infra/error/core.ts' import { newHyphenlessUuid } from '@/infra/id.ts' import { sendTemplateMail } from '@/infra/mail.ts' import { hashPassword, verifyPassword } from '@/infra/password.ts' -import search, { USER_SEARCH_INDEX } from '@/infra/search.ts' +import { + client as meilisearch, + USER_SEARCH_INDEX, +} from '../infra/meilisearch.ts' import { User } from '@/user/model.ts' import userRepo from '@/user/repo.ts' import { Buffer } from 'node:buffer' @@ -149,7 +152,7 @@ export async function list({ page, }: UserListOptions): Promise { if (query && query.length >= 3) { - const users = await search + const users = await meilisearch .index(USER_SEARCH_INDEX) .search(query, { page: page, hitsPerPage: size }) .then((value) => { @@ -194,7 +197,7 @@ export async function updateFullName( ): Promise { let user = await userRepo.findById(id) user = await userRepo.update({ id: user.id, fullName: options.fullName }) - await search.index(USER_SEARCH_INDEX).updateDocuments([ + await meilisearch.index(USER_SEARCH_INDEX).updateDocuments([ { id: user.id, username: user.username, @@ -266,7 +269,7 @@ export async function updateEmailConfirmation( emailUpdateToken: null, emailUpdateValue: null, }) - await search.index(USER_SEARCH_INDEX).updateDocuments([ + await meilisearch.index(USER_SEARCH_INDEX).updateDocuments([ { id: user.id, username: user.username, @@ -308,7 +311,7 @@ export async function updatePicture( id: userId, picture: `data:${contentType};base64,${picture}`, }) - await search.index(USER_SEARCH_INDEX).updateDocuments([ + await meilisearch.index(USER_SEARCH_INDEX).updateDocuments([ { id: user.id, username: user.username, @@ -326,7 +329,7 @@ export async function updatePicture( export async function deletePicture(id: string): Promise { let user = await userRepo.findById(id) user = await userRepo.update({ id: user.id, picture: null }) - await search.index(USER_SEARCH_INDEX).updateDocuments([ + await meilisearch.index(USER_SEARCH_INDEX).updateDocuments([ { id: user.id, username: user.username, @@ -345,7 +348,7 @@ export async function deleteUser(id: string, options: UserDeleteOptions) { const user = await userRepo.findById(id) if (verifyPassword(options.password, user.passwordHash)) { await userRepo.delete(user.id) - await search.index(USER_SEARCH_INDEX).deleteDocuments([user.id]) + await meilisearch.index(USER_SEARCH_INDEX).deleteDocuments([user.id]) } else { throw newInvalidPasswordError() } @@ -362,7 +365,7 @@ export async function suspendUser(id: string, options: UserSuspendOptions) { } if (user) { await userRepo.suspend(user.id, options.suspend) - await search.index(USER_SEARCH_INDEX).updateDocuments([ + await meilisearch.index(USER_SEARCH_INDEX).updateDocuments([ { id: user.id, username: user.username, @@ -390,7 +393,7 @@ export async function makeAdminUser(id: string, options: UserMakeAdminOptions) { } if (user) { await userRepo.makeAdmin(user.id, options.makeAdmin) - await search.index(USER_SEARCH_INDEX).updateDocuments([ + await meilisearch.index(USER_SEARCH_INDEX).updateDocuments([ { id: user.id, username: user.username,