File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
export type OrgStatus = 'INFO_PENDING' | 'READY' | 'PARTIAL' | 'ACTIVE'
export interface Org {
id: number
orgNo: string
orgName: string
status: OrgStatus
deptName: string | null
managerName: string | null
managerTitle: string | null
managerPhone: string | null
managerEmail: string | null
channelIdMj: string | null
channelIdLaw: string | null
}
export interface Contact {
deptName: string
managerName: string
managerTitle: string
managerPhone: string
managerEmail: string
}
export type ProvisionOutcome = 'CACHED' | 'RECOVERED' | 'CREATED' | 'FAILED'
export interface ProvisionResult {
mj: ProvisionOutcome
law: ProvisionOutcome
message: string
}
export interface SeedReport {
created: number
updated: number
total: number
}
/** Spring Security가 내려주는 CSRF 쿠키를 읽어 헤더로 되돌려 보낸다. */
function csrfToken(): string {
const match = document.cookie.match(/(?:^|;\s*)XSRF-TOKEN=([^;]*)/)
return match ? decodeURIComponent(match[1]) : ''
}
async function request<T>(url: string, init: RequestInit = {}): Promise<T> {
const method = init.method ?? 'GET'
const headers: Record<string, string> = { ...(init.headers as Record<string, string>) }
if (method !== 'GET') {
headers['X-XSRF-TOKEN'] = csrfToken()
}
const response = await fetch(url, { ...init, method, headers, credentials: 'same-origin' })
if (!response.ok) {
const body = await response.text()
throw new Error(`요청 실패 (${response.status}): ${body}`)
}
return response.json() as Promise<T>
}
export function getOrgs(): Promise<Org[]> {
return request<Org[]>('/api/orgs')
}
export function updateContact(id: number, contact: Contact): Promise<Org> {
return request<Org>(`/api/orgs/${id}/contact`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(contact),
})
}
export function provisionChannels(id: number): Promise<ProvisionResult> {
return request<ProvisionResult>(`/api/orgs/${id}/channels`, { method: 'POST' })
}
export function uploadSeed(file: File): Promise<SeedReport> {
const form = new FormData()
form.append('file', file)
return request<SeedReport>('/api/seed', { method: 'POST', body: form })
}
export async function login(username: string, password: string): Promise<void> {
const body = new URLSearchParams({ username, password })
const response = await fetch('/api/auth/login', {
method: 'POST',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-XSRF-TOKEN': csrfToken(),
},
body,
})
if (!response.ok) {
throw new Error('아이디 또는 비밀번호가 올바르지 않습니다.')
}
}