@solapi/ui-kit 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,209 @@
1
+ import { create as w } from "zustand";
2
+ const S = w((a, r) => ({
3
+ queue: [],
4
+ isProcessing: !1,
5
+ lastAddedRequest: null,
6
+ lastRemovedRequestId: null,
7
+ enqueue: (e, s = {}) => {
8
+ const n = `req_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`, {
9
+ reason: t = "Unknown",
10
+ mfa: o,
11
+ isNewMfa: c,
12
+ then: f,
13
+ catch: l
14
+ } = s, i = {
15
+ id: n,
16
+ status: "pending",
17
+ config: e,
18
+ reason: t,
19
+ createdAt: Date.now(),
20
+ mfa: o,
21
+ isNewMfa: c,
22
+ then: f,
23
+ catch: l
24
+ };
25
+ return a((u) => ({
26
+ queue: [...u.queue, i],
27
+ lastAddedRequest: i
28
+ })), n;
29
+ },
30
+ dequeue: (e) => {
31
+ const s = r().queue.find((n) => n.id === e);
32
+ s && s.status === "pending" && s.catch?.(new Error("2차 인증이 중단되었습니다.")), a((n) => ({
33
+ queue: n.queue.filter((t) => t.id !== e),
34
+ lastRemovedRequestId: e
35
+ }));
36
+ },
37
+ clearQueue: () => {
38
+ a({ queue: [] });
39
+ },
40
+ updateQueue: (e, s) => {
41
+ a((n) => ({
42
+ queue: n.queue.map((t) => t.id === e ? { ...t, ...s } : t)
43
+ }));
44
+ },
45
+ resolve: (e, s) => {
46
+ const n = r().queue.find((t) => t.id === e);
47
+ n && (a((t) => ({
48
+ queue: t.queue.filter((o) => o.id !== e),
49
+ lastRemovedRequestId: e
50
+ })), n.then?.(s));
51
+ },
52
+ reject: (e, s) => {
53
+ const n = r().queue.find((t) => t.id === e);
54
+ n && (a((t) => ({
55
+ queue: t.queue.filter((o) => o.id !== e),
56
+ lastRemovedRequestId: e
57
+ })), n.catch?.(s));
58
+ },
59
+ getQueueStatus: () => {
60
+ const { queue: e } = r();
61
+ return {
62
+ total: e.length
63
+ };
64
+ },
65
+ getLastAddedRequest: () => {
66
+ const { lastAddedRequest: e } = r();
67
+ return e;
68
+ },
69
+ getLastRemovedRequestId: () => {
70
+ const { lastRemovedRequestId: e } = r();
71
+ return e;
72
+ }
73
+ }));
74
+ let M = {
75
+ legacyMfaHeaderKey: "x-mfa-data",
76
+ newMfaHeaderKey: "x-auth-flow",
77
+ authTypeLabels: {
78
+ PASSWORD: "비밀번호",
79
+ "KR-ARS": "ARS",
80
+ SMS: "문자",
81
+ "EMAIL-OTP": "이메일",
82
+ HASH: "문자 해시",
83
+ ARS: "ARS",
84
+ "SELF-CERT": "본인인증",
85
+ "MULTI-CERT": "간편인증",
86
+ CERT: "본인인증"
87
+ },
88
+ authTypePriority: [
89
+ "PASSWORD",
90
+ "MULTI-CERT",
91
+ "SELF-CERT",
92
+ "EMAIL-OTP",
93
+ "KR-ARS",
94
+ "SMS",
95
+ "HASH",
96
+ "ARS",
97
+ "CERT"
98
+ ]
99
+ };
100
+ function F(a) {
101
+ M = { ...M, ...a };
102
+ }
103
+ function g() {
104
+ return { ...M };
105
+ }
106
+ function p(a) {
107
+ const e = g().newMfaHeaderKey || "x-auth-flow";
108
+ try {
109
+ const n = a?.response?.headers || {}, t = JSON.parse(n[e] || "{}"), o = t?.allowedAuthTypes || [], c = t.requiredFactors || [], f = t.completedFactors || [], l = c.find(
110
+ (d) => !f.includes(d)
111
+ ), i = {
112
+ ...t,
113
+ allowedAuthTypes: o,
114
+ requiredFactors: c,
115
+ completedFactors: f,
116
+ targetFactor: l
117
+ }, u = a.config, { enqueue: q } = S.getState();
118
+ return new Promise((d, R) => {
119
+ q(u, {
120
+ reason: "New MFA required",
121
+ isNewMfa: !0,
122
+ mfa: i,
123
+ then: d,
124
+ catch: R
125
+ });
126
+ });
127
+ } catch (s) {
128
+ console.error("신규 MFA 처리 실패:", s);
129
+ }
130
+ return !1;
131
+ }
132
+ function A(a) {
133
+ try {
134
+ const r = a?.response, e = r?.data || {}, s = String(r?.status), { mfa: n, errorCode: t } = e;
135
+ if (n && s === "401" && t === "Unauthorized") {
136
+ const o = a.config, { enqueue: c } = S.getState();
137
+ return new Promise((f, l) => {
138
+ c(o, {
139
+ reason: "Legacy MFA required",
140
+ isNewMfa: !1,
141
+ mfa: n,
142
+ then: f,
143
+ catch: l
144
+ });
145
+ });
146
+ }
147
+ } catch (r) {
148
+ console.error("기존 MFA 처리 실패:", r);
149
+ }
150
+ return !1;
151
+ }
152
+ function y(a) {
153
+ const e = g().newMfaHeaderKey || "x-auth-flow";
154
+ try {
155
+ const s = a?.response, n = s?.headers || {}, t = s?.data?.errorCode, o = String(s?.status);
156
+ return n?.[e] && o === "401" && t === "Unauthorized" ? p(a) : A(a);
157
+ } catch (s) {
158
+ console.error("MFA 처리 실패:", s);
159
+ }
160
+ return !1;
161
+ }
162
+ function T(a = {}, r) {
163
+ const {
164
+ enableAlert: e = !0,
165
+ successMessage: s,
166
+ errorMessage: n,
167
+ onSuccess: t,
168
+ onError: o,
169
+ mutationFn: c,
170
+ snackbar: f,
171
+ ...l
172
+ } = a, i = r || f;
173
+ return {
174
+ ...l,
175
+ mutationFn: async (u, q) => {
176
+ const d = c || (() => Promise.resolve(void 0));
177
+ let R;
178
+ try {
179
+ R = await d(u, q);
180
+ } catch (h) {
181
+ const m = await y(h);
182
+ if (m === !1)
183
+ throw h;
184
+ R = m;
185
+ }
186
+ return R;
187
+ },
188
+ onSuccess: async (u, q, d) => {
189
+ e && s && i && i.success(s), t && await t(u, q, d);
190
+ },
191
+ onError: async (u, q, d) => {
192
+ if (e && i) {
193
+ const R = u?.response?.data?.errorMessage, h = n || R || u?.message || "요청 처리 중 오류가 발생했습니다.";
194
+ i.error(h);
195
+ }
196
+ o && await o(u, q, d);
197
+ }
198
+ };
199
+ }
200
+ export {
201
+ F as configureMfa,
202
+ T as createMutationConfig,
203
+ T as default,
204
+ g as getMfaSettings,
205
+ A as handleLegacyMfa,
206
+ y as handleMfa,
207
+ p as handleNewMfa,
208
+ S as useRequestQueueStore
209
+ };
@@ -10,4 +10,5 @@ export { default as ListFilter } from 'components/ListFilter';
10
10
  export { default as TextInput } from 'components/TextInput';
11
11
  export { DatePicker } from 'components/DatePicker';
12
12
  export { type Theme, type ThemeMode, type ThemeConfig, type ThemeColors, type ThemeSpacing, type ThemeTypography, type ThemeBorderRadius, type ThemeShadows, type ThemeTransition, type ThemeBreakpoints, defaultTheme, lightColors, darkColors, ThemeProvider, useTheme, useThemeOptional, getCSSVariable, setCSSVariable, getThemeColor, getThemeSpacing, getThemeFontSize, getThemeBorderRadius, getThemeShadow, createTransition, mediaQuery, withAlpha, spacing } from 'theme/index';
13
+ export { default as createMutationConfig } from 'lib/createMutationConfig';
13
14
  export { Box, Stack, Grid, Typography, Button, Divider, Collapse, Paper, IconButton } from 'components/common';