# 초기화하기

Wepin widget Javascript SDK를 초기화하는 방법입니다.&#x20;

먼저 Wepin 인스턴스를 생성하고 앱 등록 후 할당 받은 앱 ID와 앱 키를 이용하여 인스턴스를 초기화 합니다.

## init

init 메서드를 통해서 Wepin 오브젝트를 초기화 합니다. 초기화 시에 앱 등록 과정에서 할당 받은 앱 ID와 앱 SDK 키를 할당 합니다. 그리고 추가로 필요한 위젯의 속성들을 정의합니다.

```javascript
const testAppId = 'app_id_eg12sf3491azgs520' // 테스트용 앱 ID
const testAppKey = 'ak_test_ghq1D5s1sfG234sbnhdsw24mnovk313' // 테스트용 앱 키 
const attributes = {
  type: 'hide',
  defaultLanguage: 'en',
  defaultCurrency : 'USD',
  loginProviders: ['google', 'apple'],
}

const wepin = await Wepin.init( 
  testAppId,
  testAppKey,
  attributes
)
```

<mark style="color:blue;">`init`</mark> 의 파라미터는 아래와 같습니다.

* **appId**: *String*\
  앱 등록시 할당 받은 ID
* **appKey**: *String*\
  앱 등록시 할당 받은 키 값
* **attributes**: *Object (optional)*\
  위핀 위젯의 속성 값
  * **type**: *String*\
    처음 로딩 시 앱 위젯 윈도우를 어떻게 보여줄 지를 결정 합니다. 기본 값은 `hide` 입니다. \
    `show`: 처음 로딩 후, 바로 위젯 윈도우를 띄워서 보여 줍니다. \
    `hide`: 는 처음 로딩시 위젯 윈도우를 보여주지 않고 숨깁니다. 이후 `openWindow()`을 통해서 위젯 윈도우을 띄워 보여 줍니다.
  * **defaultLanguage**: *String*\
    위젯 기본 언어 설정, 기본 값은 `ko`입니다. 현재 지원하는 언어는 `en`, `ko` 2가지 입니다.
  * **defaultCurrency:** *String*\
    위젯 기본 통화 설정, 기본 값은 `KRW`입니다. 현재 지원하는 통화는 `USD`, `KRW` 2가지 입니다.
  * **loginProviders**: *\[String]*

    로그인 프로바이더 리스트 입니다.   현재 지원하는 프로바이더는 `google`, `apple` , `naver`, `discord` 이렇게 4가지 입니다.  필요한 로그인 프로바이더만 정의해서 사용하세요.  이 값을 지정하지 않으면  기본적으로 4개의 프로바이더 모두를 이용할 수 있습니다.

    * &#x20;`loginProviders` 파라미터는`@wepin/types`   version `v0.0.11`부터 지원합니다.&#x20;

## isInitialized

<mark style="color:blue;">`isInitialized`</mark>를 이용해서 Wepin 객체가 정상적으로 초기화 되었는지 확인할 수 있습니다.&#x20;

반환값은 아래와 같습니다.&#x20;

* *boolean*\
  init 결괏값, init이 정상적으로 잘 된 경우 <mark style="color:orange;">`true`</mark> 실패한 경우 <mark style="color:orange;">`false`</mark> 를 반환합니다.

## 예시

```javascript
const testAppId = 'app_id_eg12sf3491azgs520' // 테스트용 앱 ID
const testAppKey = 'ak_test_ghq1D5s1sfG234sbnhdsw24mnovk313' // 테스트용 앱 키 
const attributes = {
  type: 'hide',
  defaultLanguage: 'ko',
  defaultCurrency : 'KRW',
}

const wepin = await Wepin.init( 
  testAppId,
  testAppKey,
  attributes
)
if(wepin.isInitialized()) {
  console.log('wepin is initialized!')
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wepin.io/deprecated/web-javascript-sdk/sdk/initialization.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
