From 963fb33fb9afe1975a7e1661586f033289c7e1ea Mon Sep 17 00:00:00 2001 From: SEOKKAMONI Date: Sat, 4 Nov 2023 00:38:15 +0900 Subject: [PATCH 1/5] =?UTF-8?q?FIX:=20=EC=97=90=EB=9F=AC=20=EC=9D=B8?= =?UTF-8?q?=EC=8A=A4=ED=84=B4=EC=8A=A4=20=EB=B3=B4=EC=9E=A5=20axios=20?= =?UTF-8?q?=EA=B6=8C=EC=9E=A5=20=EB=B0=A9=EC=8B=9D=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/bsmOauth.ts | 111 ++++++++++++++++++++++++++++++------------------ 1 file changed, 70 insertions(+), 41 deletions(-) diff --git a/lib/bsmOauth.ts b/lib/bsmOauth.ts index 0335d48..2eb9df0 100644 --- a/lib/bsmOauth.ts +++ b/lib/bsmOauth.ts @@ -1,86 +1,116 @@ -import axios, { AxiosError } from 'axios'; -import BsmOauthError from './error.js'; -import ErrorType from './types/errorType.js'; -import { RawBsmOAuthResource, RawBsmOAuthToken } from './types/rawOAuthType.js'; -import { BsmStudent, BsmStudentResource } from './types/student.js'; -import { BsmTeacher, BsmTeacherResource } from './types/teacher.js'; -import UserRole from './types/userRole.js'; +import axios, { AxiosError, isAxiosError } from "axios"; +import BsmOauthError from "./error.js"; +import ErrorType from "./types/errorType.js"; +import { RawBsmOAuthResource, RawBsmOAuthToken } from "./types/rawOAuthType.js"; +import { BsmStudent, BsmStudentResource } from "./types/student.js"; +import { BsmTeacher, BsmTeacherResource } from "./types/teacher.js"; +import UserRole from "./types/userRole.js"; export default class BsmOauth { - constructor(clientId: string, clientSecret: string) { this.bsmAuthPayload = { clientId, - clientSecret + clientSecret, }; } private bsmAuthPayload: { - clientId: string, - clientSecret: string + clientId: string; + clientSecret: string; }; - private readonly BSM_AUTH_TOKEN_URL: string = "https://auth.bssm.kro.kr/api/oauth/token"; - private readonly BSM_AUTH_RESOURCE_URL: string = "https://auth.bssm.kro.kr/api/oauth/resource"; + private readonly BSM_AUTH_TOKEN_URL: string = + "https://auth.bssm.kro.kr/api/oauth/token"; + private readonly BSM_AUTH_RESOURCE_URL: string = + "https://auth.bssm.kro.kr/api/oauth/resource"; public async getToken(authCode: string): Promise { try { - return (await axios.post(this.BSM_AUTH_TOKEN_URL, { - ...this.bsmAuthPayload, - authCode - })).data.token; + return ( + await axios.post(this.BSM_AUTH_TOKEN_URL, { + ...this.bsmAuthPayload, + authCode, + }) + ).data.token; } catch (error) { - if (error instanceof AxiosError) { + if (isAxiosError(error)) { switch (error.response?.status) { - case 400: throw new BsmOauthError(ErrorType.INVALID_CLIENT, 'BSM OAuth 클라이언트 정보가 잘못되었습니다'); - case 404: throw new BsmOauthError(ErrorType.AUTH_CODE_NOT_FOUND, 'BSM OAuth 인증 코드를 찾을 수 없습니다'); - default: throw error; + case 400: + throw new BsmOauthError( + ErrorType.INVALID_CLIENT, + "BSM OAuth 클라이언트 정보가 잘못되었습니다" + ); + case 404: + throw new BsmOauthError( + ErrorType.AUTH_CODE_NOT_FOUND, + "BSM OAuth 인증 코드를 찾을 수 없습니다" + ); + default: + throw error; } } throw error; } } - public async getResource(token: string): Promise { + public async getResource( + token: string + ): Promise { try { - const resource = (await axios.post<{ user: RawBsmOAuthResource }>(this.BSM_AUTH_RESOURCE_URL, { - ...this.bsmAuthPayload, - token - })).data.user; + const resource = ( + await axios.post<{ user: RawBsmOAuthResource }>( + this.BSM_AUTH_RESOURCE_URL, + { + ...this.bsmAuthPayload, + token, + } + ) + ).data.user; return this.toResource(resource); } catch (error) { - if (error instanceof AxiosError) { + if (isAxiosError(error)) { switch (error.response?.status) { - case 400: throw new BsmOauthError(ErrorType.INVALID_CLIENT, 'BSM OAuth 클라이언트 정보가 잘못되었습니다'); - case 404: throw new BsmOauthError(ErrorType.TOKEN_NOT_FOUND, 'BSM OAuth 토큰을 찾을 수 없습니다'); - default: throw error; + case 400: + throw new BsmOauthError( + ErrorType.INVALID_CLIENT, + "BSM OAuth 클라이언트 정보가 잘못되었습니다" + ); + case 404: + throw new BsmOauthError( + ErrorType.TOKEN_NOT_FOUND, + "BSM OAuth 토큰을 찾을 수 없습니다" + ); + default: + throw error; } } throw error; } } - private toResource(resource: RawBsmOAuthResource): BsmStudentResource | BsmTeacherResource { + private toResource( + resource: RawBsmOAuthResource + ): BsmStudentResource | BsmTeacherResource { const { code: userCode, role, nickname, email, profileUrl } = resource; const commonResource = { userCode, nickname, email, - profileUrl + profileUrl, }; if (role === UserRole.STUDENT) { return { ...commonResource, role, - student: this.toStudent(resource) - } + student: this.toStudent(resource), + }; } if (role === UserRole.TEACHER) { return { ...commonResource, role, - teacher: this.toTeacher(resource) - } + teacher: this.toTeacher(resource), + }; } throw new BsmOauthError(ErrorType.INVALID_USER_ROLE); } @@ -93,7 +123,7 @@ export default class BsmOauth { enrolledAt, grade, classNo, - studentNo + studentNo, }; } @@ -101,8 +131,7 @@ export default class BsmOauth { const { name } = resource; return { - name - } + name, + }; } - -} \ No newline at end of file +} From c854db476ca24819805a9ab614ff1a88085a9283 Mon Sep 17 00:00:00 2001 From: SEOKKAMONI Date: Sat, 4 Nov 2023 00:42:58 +0900 Subject: [PATCH 2/5] =?UTF-8?q?ADD:=20=EC=A1=B8=EC=97=85=EC=83=9D=20?= =?UTF-8?q?=EA=B5=AC=EB=B6=84=20=EB=A6=AC=ED=84=B4=EA=B0=92=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/bsmOauth.ts | 6 ++++++ lib/types/student.ts | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/bsmOauth.ts b/lib/bsmOauth.ts index 2eb9df0..1892142 100644 --- a/lib/bsmOauth.ts +++ b/lib/bsmOauth.ts @@ -116,14 +116,20 @@ export default class BsmOauth { } private toStudent(resource: RawBsmOAuthResource): BsmStudent { + let isGraduate = false; const { name, enrolledAt, grade, classNo, studentNo } = resource; + if (grade === 0 && classNo === 0 && studentNo === 0) { + isGraduate = true; + } + return { name, enrolledAt, grade, classNo, studentNo, + isGraduate, }; } diff --git a/lib/types/student.ts b/lib/types/student.ts index 1899bce..8e5f42f 100644 --- a/lib/types/student.ts +++ b/lib/types/student.ts @@ -7,9 +7,10 @@ export interface BsmStudent { readonly grade: number; readonly classNo: number; readonly studentNo: number; + readonly isGraduate: boolean; } export interface BsmStudentResource extends CommonResource { readonly role: UserRole.STUDENT; readonly student: BsmStudent; -} \ No newline at end of file +} From 1829bc7dc0f654bf041948a3c517446c013cc801 Mon Sep 17 00:00:00 2001 From: SEOKKAMONI Date: Sat, 4 Nov 2023 00:58:05 +0900 Subject: [PATCH 3/5] =?UTF-8?q?REFACTOR:=20HTTP=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EB=A1=9C=EC=A7=81=EC=9D=84=20=EA=B3=B5?= =?UTF-8?q?=ED=86=B5=ED=99=94=ED=95=98=EC=97=AC=20util=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/bsmOauth.ts | 31 +++---------------------------- lib/utils/handleHttpError.ts | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 28 deletions(-) create mode 100644 lib/utils/handleHttpError.ts diff --git a/lib/bsmOauth.ts b/lib/bsmOauth.ts index 1892142..af8ed11 100644 --- a/lib/bsmOauth.ts +++ b/lib/bsmOauth.ts @@ -5,6 +5,7 @@ import { RawBsmOAuthResource, RawBsmOAuthToken } from "./types/rawOAuthType.js"; import { BsmStudent, BsmStudentResource } from "./types/student.js"; import { BsmTeacher, BsmTeacherResource } from "./types/teacher.js"; import UserRole from "./types/userRole.js"; +import handleHttpError from "./utils/handleHttpError.js"; export default class BsmOauth { constructor(clientId: string, clientSecret: string) { @@ -33,20 +34,7 @@ export default class BsmOauth { ).data.token; } catch (error) { if (isAxiosError(error)) { - switch (error.response?.status) { - case 400: - throw new BsmOauthError( - ErrorType.INVALID_CLIENT, - "BSM OAuth 클라이언트 정보가 잘못되었습니다" - ); - case 404: - throw new BsmOauthError( - ErrorType.AUTH_CODE_NOT_FOUND, - "BSM OAuth 인증 코드를 찾을 수 없습니다" - ); - default: - throw error; - } + handleHttpError(error); } throw error; } @@ -68,20 +56,7 @@ export default class BsmOauth { return this.toResource(resource); } catch (error) { if (isAxiosError(error)) { - switch (error.response?.status) { - case 400: - throw new BsmOauthError( - ErrorType.INVALID_CLIENT, - "BSM OAuth 클라이언트 정보가 잘못되었습니다" - ); - case 404: - throw new BsmOauthError( - ErrorType.TOKEN_NOT_FOUND, - "BSM OAuth 토큰을 찾을 수 없습니다" - ); - default: - throw error; - } + handleHttpError(error); } throw error; } diff --git a/lib/utils/handleHttpError.ts b/lib/utils/handleHttpError.ts new file mode 100644 index 0000000..1138548 --- /dev/null +++ b/lib/utils/handleHttpError.ts @@ -0,0 +1,22 @@ +import { AxiosError } from "axios"; +import BsmOauthError from "../error"; +import ErrorType from "../types/errorType"; + +const handleHttpError = (error: AxiosError) => { + switch (error.response?.status) { + case 400: + throw new BsmOauthError( + ErrorType.INVALID_CLIENT, + "BSM OAuth 클라이언트 정보가 잘못되었습니다" + ); + case 404: + throw new BsmOauthError( + ErrorType.TOKEN_NOT_FOUND, + "BSM OAuth 토큰을 찾을 수 없습니다" + ); + default: + throw error; + } +}; + +export default handleHttpError; From 023835eedfc9137dcc2a32d008e445c7fc8f32fa Mon Sep 17 00:00:00 2001 From: SEOKKAMONI Date: Mon, 6 Nov 2023 10:22:26 +0900 Subject: [PATCH 4/5] =?UTF-8?q?ADD:=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/bsmOauth.ts | 37 ++++++++++++++++++++++++++++-------- lib/utils/handleHttpError.ts | 22 --------------------- 2 files changed, 29 insertions(+), 30 deletions(-) delete mode 100644 lib/utils/handleHttpError.ts diff --git a/lib/bsmOauth.ts b/lib/bsmOauth.ts index af8ed11..7e03f58 100644 --- a/lib/bsmOauth.ts +++ b/lib/bsmOauth.ts @@ -5,7 +5,6 @@ import { RawBsmOAuthResource, RawBsmOAuthToken } from "./types/rawOAuthType.js"; import { BsmStudent, BsmStudentResource } from "./types/student.js"; import { BsmTeacher, BsmTeacherResource } from "./types/teacher.js"; import UserRole from "./types/userRole.js"; -import handleHttpError from "./utils/handleHttpError.js"; export default class BsmOauth { constructor(clientId: string, clientSecret: string) { @@ -34,7 +33,20 @@ export default class BsmOauth { ).data.token; } catch (error) { if (isAxiosError(error)) { - handleHttpError(error); + switch (error.response?.status) { + case 400: + throw new BsmOauthError( + ErrorType.INVALID_CLIENT, + "BSM OAuth 클라이언트 정보가 잘못되었습니다" + ); + case 404: + throw new BsmOauthError( + ErrorType.AUTH_CODE_NOT_FOUND, + "BSM OAuth 인증 코드를 찾을 수 없습니다" + ); + default: + throw error; + } } throw error; } @@ -56,7 +68,20 @@ export default class BsmOauth { return this.toResource(resource); } catch (error) { if (isAxiosError(error)) { - handleHttpError(error); + switch (error.response?.status) { + case 400: + throw new BsmOauthError( + ErrorType.INVALID_CLIENT, + "BSM OAuth 클라이언트 정보가 잘못되었습니다" + ); + case 404: + throw new BsmOauthError( + ErrorType.TOKEN_NOT_FOUND, + "BSM OAuth 토큰을 찾을 수 없습니다" + ); + default: + throw error; + } } throw error; } @@ -91,12 +116,8 @@ export default class BsmOauth { } private toStudent(resource: RawBsmOAuthResource): BsmStudent { - let isGraduate = false; const { name, enrolledAt, grade, classNo, studentNo } = resource; - - if (grade === 0 && classNo === 0 && studentNo === 0) { - isGraduate = true; - } + const isGraduate = !grade && !classNo && !studentNo; return { name, diff --git a/lib/utils/handleHttpError.ts b/lib/utils/handleHttpError.ts deleted file mode 100644 index 1138548..0000000 --- a/lib/utils/handleHttpError.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { AxiosError } from "axios"; -import BsmOauthError from "../error"; -import ErrorType from "../types/errorType"; - -const handleHttpError = (error: AxiosError) => { - switch (error.response?.status) { - case 400: - throw new BsmOauthError( - ErrorType.INVALID_CLIENT, - "BSM OAuth 클라이언트 정보가 잘못되었습니다" - ); - case 404: - throw new BsmOauthError( - ErrorType.TOKEN_NOT_FOUND, - "BSM OAuth 토큰을 찾을 수 없습니다" - ); - default: - throw error; - } -}; - -export default handleHttpError; From 5852e37afe92867703af561aeb8a388dbbf29d10 Mon Sep 17 00:00:00 2001 From: SEOKKAMONI Date: Mon, 6 Nov 2023 10:28:03 +0900 Subject: [PATCH 5/5] =?UTF-8?q?ADD:=20=ED=94=84=EB=A6=AC=ED=8B=B0=EC=96=B4?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .prettierrc | 10 +++++ README.md | 25 ++++++++++- index.ts | 9 +--- lib/bsmOauth.ts | 88 +++++++++++-------------------------- lib/error.ts | 13 +++--- lib/types/commonResource.ts | 6 +-- lib/types/errorType.ts | 2 +- lib/types/rawOAuthType.ts | 4 +- lib/types/student.ts | 4 +- lib/types/teacher.ts | 4 +- lib/types/userRole.ts | 2 +- package-lock.json | 24 ++++++++++ package.json | 6 ++- 13 files changed, 105 insertions(+), 92 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..8b3f0f2 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,10 @@ +{ + "singleQuote": true, + "semi": true, + "useTabs": false, + "tabWidth": 2, + "trailingComma": "none", + "printWidth": 120, + "arrowParens": "avoid", + "bracketSameLine": false + } \ No newline at end of file diff --git a/README.md b/README.md index 874d9f1..ff2916e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # BSM OAuth JS + [BSM Auth](https://github.com/BSSM-BSM/BSM-Auth-Backend-V1)의 OAuth기능을 JS에서 사용하기 쉽게 만들어주는 라이브러리입니다. ## 설치 + ```bash $ npm install bsm-oauth ``` @@ -9,8 +11,15 @@ $ npm install bsm-oauth ## 사용하기 ### TypeScript + ```typescript -import BsmOauth, { BsmOauthError, BsmOauthErrorType, BsmUserRole, BsmStudentResource, BsmTeacherResource } from "bsm-oauth"; +import BsmOauth, { + BsmOauthError, + BsmOauthErrorType, + BsmUserRole, + BsmStudentResource, + BsmTeacherResource +} from 'bsm-oauth'; // BSM OAuth 객체 초기화 const bsmOauth = new BsmOauth(BSM_AUTH_CLIENT_ID, BSM_AUTH_CLIENT_SECRET); @@ -38,9 +47,18 @@ try { } } ``` + ### JavaScript + ```typescript -const { BsmOauth, BsmOauthError, BsmOauthErrorType, BsmUserRole, BsmStudentResource, BsmTeacherResource } = require('bsm-oauth'); +const { + BsmOauth, + BsmOauthError, + BsmOauthErrorType, + BsmUserRole, + BsmStudentResource, + BsmTeacherResource +} = require('bsm-oauth'); const bsmOauth = new BsmOauth(BSM_AUTH_CLIENT_ID, BSM_AUTH_CLIENT_SECRET); @@ -69,8 +87,11 @@ const bsmOauth = new BsmOauth(BSM_AUTH_CLIENT_ID, BSM_AUTH_CLIENT_SECRET); } })(); ``` + ### 학생, 선생님계정 구분하기 + role 속성으로 구분할 수 있습니다. + ```javascript // TypeScript에서는 role로 타입을 추론해야 학생 및 선생님 정보에 접근 가능합니다. if (resource.role === BsmUserRole.STUDENT) { diff --git a/index.ts b/index.ts index f9681fb..00291fa 100644 --- a/index.ts +++ b/index.ts @@ -6,11 +6,4 @@ import { BsmStudentResource } from './lib/types/student.js'; import { BsmTeacherResource } from './lib/types/teacher.js'; export default BsmOauth; -export { - BsmOauth, - BsmOauthError, - BsmOauthErrorType, - BsmUserRole, - BsmStudentResource, - BsmTeacherResource -} \ No newline at end of file +export { BsmOauth, BsmOauthError, BsmOauthErrorType, BsmUserRole, BsmStudentResource, BsmTeacherResource }; diff --git a/lib/bsmOauth.ts b/lib/bsmOauth.ts index 7e03f58..905bf9e 100644 --- a/lib/bsmOauth.ts +++ b/lib/bsmOauth.ts @@ -1,16 +1,16 @@ -import axios, { AxiosError, isAxiosError } from "axios"; -import BsmOauthError from "./error.js"; -import ErrorType from "./types/errorType.js"; -import { RawBsmOAuthResource, RawBsmOAuthToken } from "./types/rawOAuthType.js"; -import { BsmStudent, BsmStudentResource } from "./types/student.js"; -import { BsmTeacher, BsmTeacherResource } from "./types/teacher.js"; -import UserRole from "./types/userRole.js"; +import axios, { isAxiosError } from 'axios'; +import BsmOauthError from './error.js'; +import ErrorType from './types/errorType.js'; +import { RawBsmOAuthResource, RawBsmOAuthToken } from './types/rawOAuthType.js'; +import { BsmStudent, BsmStudentResource } from './types/student.js'; +import { BsmTeacher, BsmTeacherResource } from './types/teacher.js'; +import UserRole from './types/userRole.js'; export default class BsmOauth { constructor(clientId: string, clientSecret: string) { this.bsmAuthPayload = { clientId, - clientSecret, + clientSecret }; } @@ -18,32 +18,24 @@ export default class BsmOauth { clientId: string; clientSecret: string; }; - private readonly BSM_AUTH_TOKEN_URL: string = - "https://auth.bssm.kro.kr/api/oauth/token"; - private readonly BSM_AUTH_RESOURCE_URL: string = - "https://auth.bssm.kro.kr/api/oauth/resource"; + private readonly BSM_AUTH_TOKEN_URL: string = 'https://auth.bssm.kro.kr/api/oauth/token'; + private readonly BSM_AUTH_RESOURCE_URL: string = 'https://auth.bssm.kro.kr/api/oauth/resource'; public async getToken(authCode: string): Promise { try { return ( await axios.post(this.BSM_AUTH_TOKEN_URL, { ...this.bsmAuthPayload, - authCode, + authCode }) ).data.token; } catch (error) { if (isAxiosError(error)) { switch (error.response?.status) { case 400: - throw new BsmOauthError( - ErrorType.INVALID_CLIENT, - "BSM OAuth 클라이언트 정보가 잘못되었습니다" - ); + throw new BsmOauthError(ErrorType.INVALID_CLIENT, 'BSM OAuth 클라이언트 정보가 잘못되었습니다'); case 404: - throw new BsmOauthError( - ErrorType.AUTH_CODE_NOT_FOUND, - "BSM OAuth 인증 코드를 찾을 수 없습니다" - ); + throw new BsmOauthError(ErrorType.AUTH_CODE_NOT_FOUND, 'BSM OAuth 인증 코드를 찾을 수 없습니다'); default: throw error; } @@ -52,33 +44,22 @@ export default class BsmOauth { } } - public async getResource( - token: string - ): Promise { + public async getResource(token: string): Promise { try { const resource = ( - await axios.post<{ user: RawBsmOAuthResource }>( - this.BSM_AUTH_RESOURCE_URL, - { - ...this.bsmAuthPayload, - token, - } - ) + await axios.post<{ user: RawBsmOAuthResource }>(this.BSM_AUTH_RESOURCE_URL, { + ...this.bsmAuthPayload, + token + }) ).data.user; return this.toResource(resource); } catch (error) { if (isAxiosError(error)) { switch (error.response?.status) { case 400: - throw new BsmOauthError( - ErrorType.INVALID_CLIENT, - "BSM OAuth 클라이언트 정보가 잘못되었습니다" - ); + throw new BsmOauthError(ErrorType.INVALID_CLIENT, 'BSM OAuth 클라이언트 정보가 잘못되었습니다'); case 404: - throw new BsmOauthError( - ErrorType.TOKEN_NOT_FOUND, - "BSM OAuth 토큰을 찾을 수 없습니다" - ); + throw new BsmOauthError(ErrorType.TOKEN_NOT_FOUND, 'BSM OAuth 토큰을 찾을 수 없습니다'); default: throw error; } @@ -87,30 +68,15 @@ export default class BsmOauth { } } - private toResource( - resource: RawBsmOAuthResource - ): BsmStudentResource | BsmTeacherResource { + private toResource(resource: RawBsmOAuthResource): BsmStudentResource | BsmTeacherResource { const { code: userCode, role, nickname, email, profileUrl } = resource; - const commonResource = { - userCode, - nickname, - email, - profileUrl, - }; + const commonResource = { userCode, nickname, email, profileUrl }; if (role === UserRole.STUDENT) { - return { - ...commonResource, - role, - student: this.toStudent(resource), - }; + return { ...commonResource, role, student: this.toStudent(resource) }; } if (role === UserRole.TEACHER) { - return { - ...commonResource, - role, - teacher: this.toTeacher(resource), - }; + return { ...commonResource, role, teacher: this.toTeacher(resource) }; } throw new BsmOauthError(ErrorType.INVALID_USER_ROLE); } @@ -125,15 +91,13 @@ export default class BsmOauth { grade, classNo, studentNo, - isGraduate, + isGraduate }; } private toTeacher(resource: RawBsmOAuthResource): BsmTeacher { const { name } = resource; - return { - name, - }; + return { name }; } } diff --git a/lib/error.ts b/lib/error.ts index 4fa2b83..d4d6e22 100644 --- a/lib/error.ts +++ b/lib/error.ts @@ -1,14 +1,11 @@ -import ErrorType from "./types/errorType.js"; +import ErrorType from './types/errorType.js'; export default class BsmOauthError extends Error { - constructor( - type: ErrorType, - message?: string - ) { - super(message) + constructor(type: ErrorType, message?: string) { + super(message); this.name = 'BsmOauthError'; this.type = type; - }; + } type: ErrorType; -} \ No newline at end of file +} diff --git a/lib/types/commonResource.ts b/lib/types/commonResource.ts index cc92abf..24920c2 100644 --- a/lib/types/commonResource.ts +++ b/lib/types/commonResource.ts @@ -1,9 +1,9 @@ -import UserRole from "./userRole.js"; +import UserRole from './userRole.js'; export default interface BsmOauthCommonResource { readonly userCode: number; - readonly role: UserRole + readonly role: UserRole; readonly nickname: string; readonly email: string; readonly profileUrl: string; -} \ No newline at end of file +} diff --git a/lib/types/errorType.ts b/lib/types/errorType.ts index 4c0da0d..a1087af 100644 --- a/lib/types/errorType.ts +++ b/lib/types/errorType.ts @@ -5,4 +5,4 @@ enum BsmOauthErrorType { INVALID_USER_ROLE = 'INVALID_USER_ROLE' } -export default BsmOauthErrorType; \ No newline at end of file +export default BsmOauthErrorType; diff --git a/lib/types/rawOAuthType.ts b/lib/types/rawOAuthType.ts index 26ee552..76d06c4 100644 --- a/lib/types/rawOAuthType.ts +++ b/lib/types/rawOAuthType.ts @@ -1,4 +1,4 @@ -import UserRole from "./userRole.js"; +import UserRole from './userRole.js'; export interface RawBsmOAuthToken { readonly token: string; @@ -15,4 +15,4 @@ export interface RawBsmOAuthResource { readonly email: string; readonly role: UserRole; readonly profileUrl: string; -} \ No newline at end of file +} diff --git a/lib/types/student.ts b/lib/types/student.ts index 8e5f42f..47db429 100644 --- a/lib/types/student.ts +++ b/lib/types/student.ts @@ -1,5 +1,5 @@ -import CommonResource from "./commonResource.js"; -import UserRole from "./userRole.js"; +import CommonResource from './commonResource.js'; +import UserRole from './userRole.js'; export interface BsmStudent { readonly name: string; diff --git a/lib/types/teacher.ts b/lib/types/teacher.ts index 94e5085..a357d07 100644 --- a/lib/types/teacher.ts +++ b/lib/types/teacher.ts @@ -1,5 +1,5 @@ -import CommonResource from "./commonResource.js"; -import UserRole from "./userRole.js"; +import CommonResource from './commonResource.js'; +import UserRole from './userRole.js'; export interface BsmTeacher { readonly name: string; diff --git a/lib/types/userRole.ts b/lib/types/userRole.ts index 50ff973..10aa2f6 100644 --- a/lib/types/userRole.ts +++ b/lib/types/userRole.ts @@ -3,4 +3,4 @@ enum BsmUserRole { TEACHER = 'TEACHER' } -export default BsmUserRole; \ No newline at end of file +export default BsmUserRole; diff --git a/package-lock.json b/package-lock.json index 2834021..2c4b053 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,9 @@ "dependencies": { "axios": "^1.1.3", "typescript": "^4.8.4" + }, + "devDependencies": { + "prettier": "3.0.3" } }, "node_modules/asynckit": { @@ -98,6 +101,21 @@ "node": ">= 0.6" } }, + "node_modules/prettier": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", @@ -173,6 +191,12 @@ "mime-db": "1.52.0" } }, + "prettier": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "dev": true + }, "proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", diff --git a/package.json b/package.json index b39eaa9..a917cd1 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "scripts": { "build": "npm run build:cjs & npm run build:esm", "build:cjs": "tsc --p ./cjs/tsconfig.json", - "build:esm": "tsc --p ./esm/tsconfig.json" + "build:esm": "tsc --p ./esm/tsconfig.json", + "format": "prettier --write \"**/*.{ts,js,md}\"" }, "repository": { "type": "git", @@ -28,5 +29,8 @@ "dependencies": { "axios": "^1.1.3", "typescript": "^4.8.4" + }, + "devDependencies": { + "prettier": "3.0.3" } }