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

ES Modules 방식으로 마이그레이션 #258

Merged
merged 5 commits into from
Mar 27, 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
14 changes: 0 additions & 14 deletions .eslintrc.js

This file was deleted.

5 changes: 5 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
packageExtensions:
[email protected]:
dependencies:
"@typescript-eslint/utils": 7.3.1

yarnPath: .yarn/releases/yarn-4.1.1.cjs
6 changes: 3 additions & 3 deletions bootstrap/bootstrap_host.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as bunyan from 'bunyan';
import * as fs from 'fs';
import Config from '../src/config';
import Model from '../src/model/model';
import type Config from '../src/config.js';
import Model from '../src/model/model.js';

import { HARDWARE_LAB, LOUNGE, PRACTICE_SERVER, SOFTWARE_LAB } from './hosts_info';
import { HARDWARE_LAB, LOUNGE, PRACTICE_SERVER, SOFTWARE_LAB } from './hosts_info.js';

const config: Config = JSON.parse(fs.readFileSync('config.json', { encoding: 'utf-8' }));

Expand Down
4 changes: 2 additions & 2 deletions bootstrap/rebuild_group_cache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as bunyan from 'bunyan';
import * as fs from 'fs';
import Config from '../src/config';
import Model from '../src/model/model';
import type Config from '../src/config.js';
import Model from '../src/model/model.js';

const config: Config = JSON.parse(fs.readFileSync('config.json', { encoding: 'utf-8' }));

Expand Down
16 changes: 16 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @ts-check

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
rules: {
'no-sequences': 'error',
'no-constant-condition': ['error', { checkLoops: false }],
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
},
},
);
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"bugs": {
"url": "https://github.com/bacchus-snu/id/issues"
},
"type": "module",
"dependencies": {
"@koa/cors": "^5.0.0",
"@phc/format": "^1.0.0",
Expand All @@ -40,7 +41,9 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@eslint/js": "^8.57.0",
"@types/bunyan": "^1.8.11",
"@types/eslint__js": "^8",
"@types/koa": "^2.15.0",
"@types/koa-bodyparser": "^4.3.12",
"@types/koa-mount": "^4.0.5",
Expand All @@ -52,13 +55,12 @@
"@types/pg": "^8.11.4",
"@types/supertest": "^6.0.2",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"ava": "^6.1.2",
"dprint": "^0.45.0",
"eslint": "^8.57.0",
"supertest": "^6.3.4",
"typescript": "^5.4.3"
"typescript": "^5.4.3",
"typescript-eslint": "7.3.1"
},
"packageManager": "[email protected]"
}
4 changes: 2 additions & 2 deletions src/api/email.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Bunyan from 'bunyan';
import * as nodemailer from 'nodemailer';
import Config from '../config';
import { InvalidEmailError, ResendLimitExeededError } from '../model/errors';
import type Config from '../config.js';
import { InvalidEmailError, ResendLimitExeededError } from '../model/errors.js';

export interface EmailOption {
address: string;
Expand Down
14 changes: 7 additions & 7 deletions src/api/handlers/emails.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { IMiddleware } from 'koa-router';
import type { IMiddleware } from 'koa-router';
import z from 'zod';
import Config from '../../config';
import { EmailAddress } from '../../model/email_addresses';
import { EmailInUseError, InvalidEmailError, ResendLimitExeededError } from '../../model/errors';
import Model from '../../model/model';
import { sendEmail } from '../email';
import emailVerificationTemplate from '../templates/verification_email_template';
import type Config from '../../config.js';
import type { EmailAddress } from '../../model/email_addresses.js';
import { EmailInUseError, InvalidEmailError, ResendLimitExeededError } from '../../model/errors.js';
import Model from '../../model/model.js';
import { sendEmail } from '../email.js';
import emailVerificationTemplate from '../templates/verification_email_template.js';

export function sendVerificationEmail(model: Model, config: Config): IMiddleware {
const bodySchema = z.object({
Expand Down
8 changes: 4 additions & 4 deletions src/api/handlers/groups.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IMiddleware } from 'koa-router';
import type { IMiddleware } from 'koa-router';
import z from 'zod';
import { BadParameterError } from '../../model/errors';
import Model from '../../model/model';
import { User } from '../../model/users';
import { BadParameterError } from '../../model/errors.js';
import Model from '../../model/model.js';
import type { User } from '../../model/users.js';

export function listGroups(model: Model): IMiddleware {
return async (ctx, next) => {
Expand Down
10 changes: 5 additions & 5 deletions src/api/handlers/login.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IMiddleware } from 'koa-router';
import type { IMiddleware } from 'koa-router';

import z from 'zod';
import Config from '../../config';
import { AuthorizationError, ControllableError, NoSuchEntryError } from '../../model/errors';
import Model from '../../model/model';
import { SignatureError, verifyPubkeyReq } from '../pubkey';
import type Config from '../../config.js';
import { AuthorizationError, ControllableError, NoSuchEntryError } from '../../model/errors.js';
import Model from '../../model/model.js';
import { SignatureError, verifyPubkeyReq } from '../pubkey.js';

const loginBodySchema = z.object({
username: z.string(),
Expand Down
6 changes: 3 additions & 3 deletions src/api/handlers/nss.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IMiddleware } from 'koa-router';
import type { IMiddleware } from 'koa-router';

import { NoSuchEntryError } from '../../model/errors';
import Model from '../../model/model';
import { NoSuchEntryError } from '../../model/errors.js';
import Model from '../../model/model.js';

export function getPasswd(model: Model): IMiddleware {
return async (ctx, next) => {
Expand Down
4 changes: 2 additions & 2 deletions src/api/handlers/shells.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IMiddleware } from 'koa-router';
import Model from '../../model/model';
import type { IMiddleware } from 'koa-router';
import Model from '../../model/model.js';

export function getShells(model: Model): IMiddleware {
return async (ctx, next) => {
Expand Down
14 changes: 7 additions & 7 deletions src/api/handlers/users.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { createPublicKey } from 'crypto';
import { jwtVerify } from 'jose';
import { IMiddleware } from 'koa-router';
import type { IMiddleware } from 'koa-router';
import z from 'zod';
import Config from '../../config';
import { EmailAddress } from '../../model/email_addresses';
import { InvalidEmailError, ResendLimitExeededError, UserExistsError } from '../../model/errors';
import Model from '../../model/model';
import { sendEmail } from '../email';
import changePasswordTemplate from '../templates/change_password_email_template';
import type Config from '../../config.js';
import type { EmailAddress } from '../../model/email_addresses.js';
import { InvalidEmailError, ResendLimitExeededError, UserExistsError } from '../../model/errors.js';
import Model from '../../model/model.js';
import { sendEmail } from '../email.js';
import changePasswordTemplate from '../templates/change_password_email_template.js';

export function createUser(model: Model, config: Config): IMiddleware {
const bodySchema = z.object({
Expand Down
4 changes: 2 additions & 2 deletions src/api/pubkey.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Context } from 'koa';
import * as tweetnacl from 'tweetnacl';
import type { Context } from 'koa';
import tweetnacl from 'tweetnacl';

export class SignatureError extends Error {
constructor() {
Expand Down
25 changes: 13 additions & 12 deletions src/api/router.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import bodyParser from 'koa-bodyparser';
import Router from 'koa-router';
import Config from '../config';
import Model from '../model/model';
import createOIDCRouter from '../oidc/routes';
import { checkVerificationEmailToken, sendVerificationEmail } from './handlers/emails';
import type OIDCProvider from 'oidc-provider';
import type { Configuration as OIDCConfiguration } from 'oidc-provider';

import type Config from '../config.js';
import Model from '../model/model.js';
import createOIDCRouter from '../oidc/routes.js';
import { checkVerificationEmailToken, sendVerificationEmail } from './handlers/emails.js';
import {
acceptGroup,
applyGroup,
Expand All @@ -12,21 +15,19 @@ import {
listMembers,
listPending,
rejectGroup,
} from './handlers/groups';
import { checkLogin, login, loginLegacy, loginPAM, logout } from './handlers/login';
import { getGroup, getPasswd } from './handlers/nss';
import { getShells } from './handlers/shells';
} from './handlers/groups.js';
import { checkLogin, login, loginLegacy, loginPAM, logout } from './handlers/login.js';
import { getGroup, getPasswd } from './handlers/nss.js';
import { getShells } from './handlers/shells.js';
import {
changePassword,
checkChangePasswordEmailToken,
createUser,
getUserEmails,
getUserInfo,
sendChangePasswordEmail,
} from './handlers/users';
import { changeUserShell, getUserShell } from './handlers/users';
// @ts-expect-error: https://github.com/microsoft/TypeScript/issues/49721
import type OIDCProvider, { Configuration as OIDCConfiguration } from 'oidc-provider';
} from './handlers/users.js';
import { changeUserShell, getUserShell } from './handlers/users.js';

export function createRouter(
model: Model,
Expand Down
12 changes: 6 additions & 6 deletions src/api/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import * as Bunyan from 'bunyan';
import * as crypto from 'crypto';
import Koa from 'koa';
import mount from 'koa-mount';
import OIDCProvider from 'oidc-provider';

import Config from '../config';
import Model from '../model/model';
import createOIDCConfig from '../oidc/configuration';
import { createRouter } from './router';
import type Config from '../config.js';
import Model from '../model/model.js';
import createOIDCConfig from '../oidc/configuration.js';
import { createRouter } from './router.js';

const createServer = async (config: Config, log: Bunyan, inputModel?: Model) => {
const createServer = (config: Config, log: Bunyan, inputModel?: Model) => {
const model = inputModel ?? new Model(config, log);
const OIDCProvider = (await import('oidc-provider')).default;
const oidcConfig = createOIDCConfig(model, config.oidc);
const oidcProvider = new OIDCProvider(config.oidc.issuer, oidcConfig);

Expand Down
1 change: 0 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Configuration.
*/

// @ts-expect-error: https://github.com/microsoft/TypeScript/issues/49721
import type { ClientMetadata, JWKS } from 'oidc-provider';

/**
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as bunyan from 'bunyan';
import * as fs from 'fs';
import createAPIServer from './api/server';
import Config from './config';
import createAPIServer from './api/server.js';
import type Config from './config.js';

const config: Config = JSON.parse(fs.readFileSync('config.json', { encoding: 'utf-8' }));

Expand All @@ -10,8 +10,8 @@ const log = bunyan.createLogger({
level: config.logLevel,
});

async function run() {
const apiServer = await createAPIServer(config, log);
function run() {
const apiServer = createAPIServer(config, log);
apiServer.listen(config.api.listenPort, config.api.listenHost);
}

Expand Down
4 changes: 2 additions & 2 deletions src/model/email_addresses.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as crypto from 'crypto';
import moment from 'moment';
import { ExpiredTokenError, NoSuchEntryError } from './errors';
import Transaction from './transaction';
import { ExpiredTokenError, NoSuchEntryError } from './errors.js';
import Transaction from './transaction.js';

interface EmailAddressRow {
address_local: string;
Expand Down
6 changes: 3 additions & 3 deletions src/model/groups.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NoSuchEntryError } from './errors';
import Transaction from './transaction';
import { Translation } from './translation';
import { NoSuchEntryError } from './errors.js';
import Transaction from './transaction.js';
import type { Translation } from './translation.js';

interface GroupRow {
idx: number;
Expand Down
6 changes: 3 additions & 3 deletions src/model/hosts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AuthorizationError, NoSuchEntryError } from './errors';
import Model from './model';
import Transaction from './transaction';
import { AuthorizationError, NoSuchEntryError } from './errors.js';
import Model from './model.js';
import Transaction from './transaction.js';

interface HostRow {
idx: number;
Expand Down
22 changes: 11 additions & 11 deletions src/model/model.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as Bunyan from 'bunyan';
import * as pg from 'pg';
import Config from '../config';
import EmailAddresses from './email_addresses';
import { ControllableError } from './errors';
import Groups from './groups';
import Hosts from './hosts';
import OAuth from './oauth';
import Permissions from './permissions';
import Shells from './shells';
import Transaction from './transaction';
import Users from './users';
import pg from 'pg';
import type Config from '../config.js';
import EmailAddresses from './email_addresses.js';
import { ControllableError } from './errors.js';
import Groups from './groups.js';
import Hosts from './hosts.js';
import OAuth from './oauth.js';
import Permissions from './permissions.js';
import Shells from './shells.js';
import Transaction from './transaction.js';
import Users from './users.js';

const PSQL_SERIALIZATION_FAILURE = '40001';
const PSQL_DEADLOCK_DETECTED = '40P01';
Expand Down
5 changes: 2 additions & 3 deletions src/model/oauth.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// @ts-expect-error: https://github.com/microsoft/TypeScript/issues/49721
import type { AllClientMetadata } from 'oidc-provider';

import { NoSuchEntryError } from './errors';
import Transaction from './transaction';
import { NoSuchEntryError } from './errors.js';
import Transaction from './transaction.js';

export default class OAuth {
public async getClientById(tr: Transaction, id: string): Promise<AllClientMetadata> {
Expand Down
8 changes: 4 additions & 4 deletions src/model/permissions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NoSuchEntryError } from './errors';
import Model from './model';
import Transaction from './transaction';
import { Translation } from './translation';
import { NoSuchEntryError } from './errors.js';
import Model from './model.js';
import Transaction from './transaction.js';
import type { Translation } from './translation.js';

export default class Permissions {
constructor(private readonly model: Model) {
Expand Down
2 changes: 1 addition & 1 deletion src/model/shells.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Transaction from './transaction';
import Transaction from './transaction.js';

export default class Shells {
constructor() {
Expand Down
6 changes: 3 additions & 3 deletions src/model/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
ExpiredTokenError,
NoSuchEntryError,
NotActivatedError,
} from './errors';
import Model from './model';
import Transaction from './transaction';
} from './errors.js';
import Model from './model.js';
import Transaction from './transaction.js';

// see language enum in schema.sql
export type Language = 'ko' | 'en';
Expand Down
Loading
Loading