onemedics-sdk-user v0.1.3
Onemedics Library
이 프로젝트는 회원가입/로그인 기능을 간편하게 만들수 있도록 SDK 제공하는데 그 목적이 있습니다.
개발문서는 아래링크 참조
1. 설치
$npm i onemedics-sdk-user[@<version>]2. 사용예제
기본 UserModule 생성 및 초기 로그인 REST
import * as React from "react";
import { useRef } from "react";
import { UserModule, Token } from "onemedics-sdk-user";
import { AxiosResponse } from "axios";
export function App() {
const userid = useRef<HTMLInputElement | null>(null);
const password = useRef<HTMLInputElement | null>(null);
// 유저모듈 초기화
const userModule = new UserModule({
clientId: "test1",
uri: "https://dev.one.net:9000",
token: "Basic ZG8zb28td1ViOmNlY3JldA==",
});
const onLogin = () => {
// 아이디 비밀번호로 초기 로그인
userModule
.signIn({
username: userid.current?.value,
password: password.current?.value,
})
.then(({ data }: AxiosResponse<Token>) => {
/* 토큰정보 저장 프로세스 수행 및 로그인 후 프로세스 수행 */
});
};
return (
<div className='App'>
<input type='text' ref={userid} placeholder={'아이디'} />
<input type='password' ref={password} placeholder={'아이디'} />
<button onClick={onLogin}>로그인</button>
</div>
);
}
export default App;3. API 리스트
Core
User
- UserModule
- requestAuthNumber
- identifyAuthNumber
- checkDuplicateId
- getTerms
- getTermsBy
- signUp
- getToken
- getMe
- signIn
- refreshToken
- serializeForm
Core
ApolloToolKit
ApolloClient 생성과 생성된 ApolloClient을 이용한 별도의 query, mutate 등의 함수를 제공합니다.
- 요청변수
변수병 유형 설명 variables clientId string 프로젝트로 구분되는 clientId를 넣습니다. uri string 호출할 서버의 uri token string header에 전달될 초기 token 값(Basic) - 예시
import { ApolloToolKit } from "onemedics-sdk-user"; export const apolloToolKit = new ApolloToolKit({ clientId: "dosoo-web", uri: "https://dev.one.net/test/graphql", token: "Basic b25123421===", });
UserError
회원모듈 에러처리를 위한 Error Class( extends Error )
User
UserModule
모듈 사용자로부터 넘겨받은 객체로 새로운 UserModule 객체를 생성합니다.
Core의 ApolloToolKit을 포함하고 있습니다.- 요청변수
변수병 유형 설명 clientId string프로젝트로 구분되는 clientId를 넣습니다. uri string호출할 서버의 uri token stringheader에 전달될 초기 token 값(Basic) graphqlEndpoint [optional]stringgraphql endpoint( default: '/user/graphql')restBaseURL [optional]stringREST API base URL( default: 변수 uri 로 초기화됨)- 예시
//App.tsx import {UserModule} from "onemedics-sdk-user";
export const userModule = new UserModule({ clientId: "dosoo-web", uri: "https://dev.one.net/test/graphql", token: "Basic b25123421===", });
#### requestAuthNumber
<a name="request-auth-num"></a>
>[인증공통]인증번호 생성 요청
##### - 요청변수
|변수병| |유형|설명|
|---|:---:|:---:|---|
|variables|authNumType| `'SIGNUP'` `'FIND_ID'` `'FIND_PW'` `'MODIFY_MYINFO'` |인증번호 유형|
| |phone|`string`|모바일 번호|
##### - 예제
```typescript jsx
import {userModule} from './App'
userModule
.requestAuthNumber({
variables: {
authNumType: 'SIGNUP',
phone: '01012345678'
},
})
.then((result) => {
/*result process*/
});identifyAuthNumber 미구현
인증공통인증번호 생성 확인
- 요청변수
변수병 유형 설명 variables - 예제
import { userModule } from "[유저모듈 경로]";
userModule .identifyAuthNumber({ variables: {}, }) .then((result) => { /result process/ });
#### checkDuplicateId
<a name="check-duplicate-id"></a>
>[회원가입]아이디 중복체크를 수행합니다.
##### - 요청변수
|변수병| |유형|설명|
|---|:---:|:---:|---|
|variables|loginId|`string`|로그인 아이디|
##### - 예제
```typescript jsx
import { userModule } from "[유저모듈 경로]";
userModule
.checkDuplicateId({
variables: {
},
})
.then((result) => {
/*result process*/
});getTerms
회원가입약관 가져오기
- 요청변수
변수병 유형 설명 variables - 예제
import { userModule } from "[유저모듈 경로]";
userModule .getTerms({ variables: {}, }) .then((result) => { /result process/ });
#### getTermsBy
<a name="get-terms-by"></a>
> [회원가입]약관 가져오기
##### - 요청변수
|변수병| |유형|설명|
|---|:---:|:---:|---|
| variables | | | |
##### - 예제
```typescript jsx
import { userModule } from "[유저모듈 경로]";
userModule
.getTermsBy({
variables: {},
})
.then((result) => {
/*result process*/
});signUp
회원가입약관 가져오기
- 요청변수
변수병 유형 설명 clientId string클라이언트 아이디 loginId string로그인 아이디 password string비밀번호 username string유저명 phone string핸드폰번호 marketingAgreement boolean마케팅 수신동의 authNumId number인증번호 ID authNum string인증번호 getToken
로그인토큰 가져오기
- 요청변수
변수병 유형 설명 username string아이디 password string암호 grant_typeoptional string인증유형(default: 'password')getMe
로그인회원정보 가져오기
- 요청변수
변수병 유형 설명 token stringaccess_token값
signIn
로그인아이디 패스워드 로그인 가져오기
- 요청변수
변수병 유형 설명 username string아이디 password string암호 grant_typeoptional string인증유형(default: 'password')
refreshToken
로그인token정보 업데이트 가져오기
- 요청변수
변수병 유형 설명 refresh_token stringrefresh_token값 grant_type [optional]string인증유형(default: 'refresh_token'
serializeForm
로그인 FormData 생성
- 요청변수
변수병 유형 설명 params object FormData로 생성할 object
4. 개발 방법
TDD 개발방식을 지향합니다.
모든 코드들은 테스트 코드 작성 및 테스트 후에 실제 비즈니스 로직 코드로 옯겨집니다.
초기 개발 및 테스트는 Mockup 파일(fixtures.json)로 진행합니다.
.gitignore 파일과 .npmignore 파일을 혼용한 이유
.gitignore: github 업로드시 제외하기위해 사용되었습니다..npmignore: github 주소를 통해 npm설치 시 특정파일(예:Mockup 파일)은 제외하기 위해 사용.
5. 버전 관리
CHANGELOG.md 파일 참조 부탁드립니다.