@blastlabs/utils 1.12.0 → 1.13.0

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.
Files changed (36) hide show
  1. package/README.md +20 -13
  2. package/bin/entity-generator-guide.md +126 -0
  3. package/bin/generate-entity.cjs +282 -0
  4. package/dist/components/auth/AuthGuard.d.ts +95 -0
  5. package/dist/components/auth/AuthGuard.d.ts.map +1 -0
  6. package/dist/components/auth/AuthGuard.js +103 -0
  7. package/dist/components/auth/index.d.ts +5 -0
  8. package/dist/components/auth/index.d.ts.map +1 -0
  9. package/dist/components/auth/index.js +4 -0
  10. package/dist/components/dev/ApiLogger.d.ts +1 -1
  11. package/dist/components/dev/ApiLogger.js +1 -1
  12. package/dist/components/index.d.ts +1 -0
  13. package/dist/components/index.d.ts.map +1 -1
  14. package/dist/components/index.js +1 -0
  15. package/dist/hooks/auth/__tests__/useAuth.test.d.ts +2 -0
  16. package/dist/hooks/auth/__tests__/useAuth.test.d.ts.map +1 -0
  17. package/dist/hooks/auth/__tests__/useAuth.test.js +139 -0
  18. package/dist/hooks/auth/index.d.ts +5 -0
  19. package/dist/hooks/auth/index.d.ts.map +1 -0
  20. package/dist/hooks/auth/index.js +4 -0
  21. package/dist/hooks/auth/useAuth.d.ts +275 -0
  22. package/dist/hooks/auth/useAuth.d.ts.map +1 -0
  23. package/dist/hooks/auth/useAuth.js +384 -0
  24. package/dist/hooks/form/useCRUDForm.d.ts +7 -28
  25. package/dist/hooks/form/useCRUDForm.d.ts.map +1 -1
  26. package/dist/hooks/index.d.ts +1 -0
  27. package/dist/hooks/index.d.ts.map +1 -1
  28. package/dist/hooks/index.js +2 -0
  29. package/dist/hooks/ui/index.d.ts +1 -0
  30. package/dist/hooks/ui/index.d.ts.map +1 -1
  31. package/dist/hooks/ui/index.js +1 -0
  32. package/dist/hooks/ui/useTabs.d.ts +33 -0
  33. package/dist/hooks/ui/useTabs.d.ts.map +1 -0
  34. package/dist/hooks/ui/useTabs.js +117 -0
  35. package/dist/index.js +1 -1
  36. package/package.json +6 -2
package/README.md CHANGED
@@ -1,15 +1,17 @@
1
- # goodchuck-utils
1
+ # @blastlabs/utils
2
+
3
+ > **⚠️ 주의: 이 라이브러리는 사내 개발용이며, 현재 테스트 단계입니다.**
2
4
 
3
5
  React 프로젝트에서 자주 사용하는 유틸리티 훅(Hooks)과 개발용 컴포넌트 모음입니다.
4
6
 
5
7
  ## 설치
6
8
 
7
9
  ```bash
8
- npm install goodchuck-utils
10
+ npm install @blastlabs/utils
9
11
  # or
10
- yarn add goodchuck-utils
12
+ yarn add @blastlabs/utils
11
13
  # or
12
- pnpm add goodchuck-utils
14
+ pnpm add @blastlabs/utils
13
15
  ```
14
16
 
15
17
  ## 기능
@@ -19,7 +21,7 @@ pnpm add goodchuck-utils
19
21
  프로젝트에서 자주 사용하는 커스텀 훅들을 제공합니다.
20
22
 
21
23
  ```typescript
22
- import { useDebounce, useToggle, useCopyToClipboard } from 'goodchuck-utils/hooks';
24
+ import { useDebounce, useToggle, useCopyToClipboard } from '@blastlabs/utils/hooks';
23
25
  ```
24
26
 
25
27
  #### 사용 가능한 Hooks
@@ -38,7 +40,7 @@ import { useDebounce, useToggle, useCopyToClipboard } from 'goodchuck-utils/hook
38
40
  개발 환경에서만 사용하는 유틸리티 컴포넌트들입니다.
39
41
 
40
42
  ```typescript
41
- import { DevPanel, FormDevTools, ApiLogger } from 'goodchuck-utils/components/dev';
43
+ import { DevPanel, FormDevTools, ApiLogger } from '@blastlabs/utils/components/dev';
42
44
  ```
43
45
 
44
46
  #### IdSelector
@@ -46,7 +48,7 @@ import { DevPanel, FormDevTools, ApiLogger } from 'goodchuck-utils/components/de
46
48
  개발 환경에서 여러 계정으로 빠르게 로그인할 수 있는 컴포넌트입니다.
47
49
 
48
50
  ```tsx
49
- import { IdSelector } from 'goodchuck-utils/components/dev';
51
+ import { IdSelector } from '@blastlabs/utils/components/dev';
50
52
 
51
53
  const devAccounts = [
52
54
  { id: 'admin', pw: 'admin123', memo: '관리자' },
@@ -75,7 +77,7 @@ react-hook-form의 상태를 실시간으로 시각화하는 개발용 컴포넌
75
77
 
76
78
  ```tsx
77
79
  import { useForm } from 'react-hook-form';
78
- import { FormDevTools } from 'goodchuck-utils/components/dev';
80
+ import { FormDevTools } from '@blastlabs/utils/components/dev';
79
81
 
80
82
  function MyForm() {
81
83
  const form = useForm({
@@ -112,7 +114,7 @@ API 요청/응답을 로깅하고 모니터링하는 컴포넌트입니다.
112
114
 
113
115
  ```tsx
114
116
  import axios from 'axios';
115
- import { ApiLogger, addApiLog } from 'goodchuck-utils/components/dev';
117
+ import { ApiLogger, addApiLog } from '@blastlabs/utils/components/dev';
116
118
 
117
119
  // Axios interceptor 설정
118
120
  axios.interceptors.request.use(
@@ -178,7 +180,7 @@ function App() {
178
180
  여러 개발 도구를 하나의 패널에서 관리할 수 있는 통합 컴포넌트입니다.
179
181
 
180
182
  ```tsx
181
- import { DevPanel } from 'goodchuck-utils/components/dev';
183
+ import { DevPanel } from '@blastlabs/utils/components/dev';
182
184
 
183
185
  function App() {
184
186
  return (
@@ -200,7 +202,7 @@ function App() {
200
202
  페이지의 모든 z-index 값을 시각화하고 디버깅하는 도구입니다.
201
203
 
202
204
  ```tsx
203
- import { ZIndexDebugger } from 'goodchuck-utils/components/dev';
205
+ import { ZIndexDebugger } from '@blastlabs/utils/components/dev';
204
206
 
205
207
  function App() {
206
208
  return (
@@ -222,7 +224,7 @@ function App() {
222
224
  현재 윈도우 크기를 화면에 표시하는 간단한 컴포넌트입니다.
223
225
 
224
226
  ```tsx
225
- import { WindowSizeDisplay } from 'goodchuck-utils/components/dev';
227
+ import { WindowSizeDisplay } from '@blastlabs/utils/components/dev';
226
228
 
227
229
  function App() {
228
230
  return (
@@ -250,7 +252,7 @@ function App() {
250
252
  모든 컴포넌트와 훅은 TypeScript로 작성되었으며, 타입 정의가 포함되어 있습니다.
251
253
 
252
254
  ```typescript
253
- import type { FormDevToolsProps, ApiLogEntry } from 'goodchuck-utils/components/dev';
255
+ import type { FormDevToolsProps, ApiLogEntry } from '@blastlabs/utils/components/dev';
254
256
  ```
255
257
 
256
258
  ## 주의사항
@@ -258,6 +260,11 @@ import type { FormDevToolsProps, ApiLogEntry } from 'goodchuck-utils/components/
258
260
  - **개발용 컴포넌트(`components/dev`)는 프로덕션 환경에서 제외하는 것을 권장합니다.**
259
261
  - 개발 환경 구분을 위해 `import.meta.env.DEV` (Vite) 또는 `process.env.NODE_ENV === 'development'` (CRA)를 사용하세요.
260
262
 
263
+ ## 문의
264
+
265
+ - goodchuck852@gmail.com
266
+ - taehyunyang@blast-team.com
267
+
261
268
  ## 라이선스
262
269
 
263
270
  ISC
@@ -0,0 +1,126 @@
1
+ # 엔티티 자동 생성 스크립트 사용법
2
+
3
+ ## 개요
4
+
5
+ `generate-entity.cjs` 스크립트를 사용하여 새로운 엔티티의 기본 구조를 자동으로 생성할 수 있습니다.
6
+
7
+ ## 사용법
8
+
9
+ ```bash
10
+ # entities 폴더로 이동
11
+ cd apps/admin/src/entities
12
+
13
+ # 엔티티 생성
14
+ node generate-entity.cjs <entity-name>
15
+ ```
16
+
17
+ ## 예시
18
+
19
+ ```bash
20
+ # user-profile 엔티티 생성
21
+ node generate-entity.cjs user-profile
22
+
23
+ # my-entity 엔티티 생성
24
+ node generate-entity.cjs my-entity
25
+
26
+ # product-review 엔티티 생성
27
+ node generate-entity.cjs product-review
28
+ ```
29
+
30
+ ## 생성되는 파일 구조
31
+
32
+ ```
33
+ {entity-name}/
34
+ ├── index.ts # 엔티티 메인 export 파일
35
+ ├── api/
36
+ │ ├── get-{entity-name}-list.ts # API 호출 함수
37
+ │ ├── {entity-name}-queries.ts # React Query 설정
38
+ │ ├── index.ts # API 모듈 export
39
+ │ ├── mapper/
40
+ │ │ └── map-{entity-name}.ts # 데이터 매핑 함수
41
+ │ └── query/
42
+ │ └── {entity-name}-list-query.ts # 쿼리 타입 정의
43
+ └── model/
44
+ └── {entity-name}.ts # Zod 스키마 및 타입
45
+ ```
46
+
47
+ ## 자동 생성 후 추가 작업
48
+
49
+ 스크립트 실행 후 다음 작업들을 수동으로 완료해야 합니다:
50
+
51
+ ### 1. query-keys.ts 파일 업데이트
52
+
53
+ ```typescript
54
+ export const {ENTITY_NAME}_QUERY_KEYS = {
55
+ all: ["{entity-name}"] as const,
56
+ lists: () => [...{ENTITY_NAME}_QUERY_KEYS.all, "list"] as const,
57
+ list: (filters: {EntityName}ListParams) =>
58
+ [...{ENTITY_NAME}_QUERY_KEYS.lists(), filters] as const,
59
+ details: () => [...{ENTITY_NAME}_QUERY_KEYS.all, "detail"] as const,
60
+ detail: (id: number) => [...{ENTITY_NAME}_QUERY_KEYS.details(), id] as const,
61
+ };
62
+ ```
63
+
64
+ ### 2. model/{entity-name}.ts 수정
65
+
66
+ 실제 API 응답 구조에 맞게 Zod 스키마를 수정해주세요:
67
+
68
+ ```typescript
69
+ export const {EntityName}Schema = z.object({
70
+ id: z.number(),
71
+ // 실제 필드들 추가
72
+ name: z.string(),
73
+ description: z.string().nullable(),
74
+ createDate: z.string(),
75
+ updateDate: z.string(),
76
+ });
77
+ ```
78
+
79
+ ### 3. api/mapper/map-{entity-name}.ts 수정
80
+
81
+ API 응답 데이터를 모델에 맞게 매핑하는 로직을 수정해주세요:
82
+
83
+ ```typescript
84
+ export const map{EntityName} = (item: {EntityName}) => {
85
+ const res = {EntityName}Schema.safeParse({
86
+ id: item.id,
87
+ name: item.name,
88
+ description: item.description,
89
+ createDate: item.createDate,
90
+ updateDate: item.updateDate,
91
+ });
92
+ // ...
93
+ };
94
+ ```
95
+
96
+ ### 4. api/get-{entity-name}-list.ts 수정
97
+
98
+ 실제 API 엔드포인트 메서드명으로 변경해주세요:
99
+
100
+ ```typescript
101
+ export const get{EntityName}List = (filters: {EntityName}ListQuery) => {
102
+ const customApi = createInstance(import.meta.env.VITE_BASE_URL);
103
+ // 실제 API 메서드명으로 변경
104
+ return customApi.default.admin{EntityName}List(filters);
105
+ };
106
+ ```
107
+
108
+ ### 5. api/query/{entity-name}-list-query.ts 수정
109
+
110
+ 필요한 필터링 옵션을 추가해주세요:
111
+
112
+ ```typescript
113
+ export type {EntityName}ListQuery = {
114
+ limit?: number;
115
+ offset?: number;
116
+ search?: string;
117
+ status?: string;
118
+ // 추가 필터 옵션들...
119
+ };
120
+ ```
121
+
122
+ ## 참고사항
123
+
124
+ - 엔티티 이름은 kebab-case로 입력해주세요 (예: `user-profile`, `product-review`)
125
+ - 생성된 파일들은 기본 템플릿이므로 실제 API 구조에 맞게 수정이 필요합니다
126
+ - popular-product, popular-review 폴더를 참고하여 패턴을 확인할 수 있습니다
@@ -0,0 +1,282 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+
6
+ // 엔티티 이름을 kebab-case로 변환
7
+ function toKebabCase(str) {
8
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
9
+ }
10
+
11
+ // 엔티티 이름을 PascalCase로 변환
12
+ function toPascalCase(str) {
13
+ return str
14
+ .split("-")
15
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
16
+ .join("");
17
+ }
18
+
19
+ // 엔티티 이름을 camelCase로 변환
20
+ function toCamelCase(str) {
21
+ const pascalCase = toPascalCase(str);
22
+ return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
23
+ }
24
+
25
+ function createEntityStructure(entityName, targetDir) {
26
+ const kebabName = toKebabCase(entityName);
27
+ const pascalName = toPascalCase(kebabName);
28
+ const camelName = toCamelCase(kebabName);
29
+
30
+ // 현재 작업 디렉토리 기준으로 생성
31
+ const basePath = path.join(targetDir, kebabName);
32
+
33
+ // 디렉토리 생성
34
+ const dirs = [
35
+ basePath,
36
+ path.join(basePath, "api"),
37
+ path.join(basePath, "api", "mapper"),
38
+ path.join(basePath, "api", "query"),
39
+ path.join(basePath, "model"),
40
+ ];
41
+
42
+ dirs.forEach((dir) => {
43
+ if (!fs.existsSync(dir)) {
44
+ fs.mkdirSync(dir, { recursive: true });
45
+ }
46
+ });
47
+
48
+ // 파일 템플릿 생성
49
+ createFiles(basePath, kebabName, pascalName, camelName);
50
+
51
+ console.log(`✅ ${kebabName} 엔티티가 성공적으로 생성되었습니다!`);
52
+ console.log(`📍 위치: ${basePath}`);
53
+ console.log(`\n생성된 파일들:`);
54
+ console.log(`📁 ${kebabName}/`);
55
+ console.log(`├── index.ts`);
56
+ console.log(`├── api/`);
57
+ console.log(`│ ├── get-${kebabName}-list.ts`);
58
+ console.log(`│ ├── get-${kebabName}-detail.ts`);
59
+ console.log(`│ ├── ${kebabName}-queries.ts`);
60
+ console.log(`│ ├── index.ts`);
61
+ console.log(`│ ├── mapper/`);
62
+ console.log(`│ │ ├── map-${kebabName}.ts`);
63
+ console.log(`│ │ └── map-${kebabName}-detail.ts`);
64
+ console.log(`│ └── query/`);
65
+ console.log(`│ └── ${kebabName}-list-query.ts`);
66
+ console.log(`└── model/`);
67
+ console.log(` ├── ${kebabName}.ts`);
68
+ console.log(` └── ${kebabName}-detail.ts`);
69
+
70
+ console.log(`\n⚠️ 추가 작업이 필요합니다:`);
71
+ console.log(
72
+ `1. query-keys.ts 파일에 ${pascalName.toUpperCase()}_QUERY_KEYS 추가`,
73
+ );
74
+ console.log(`2. API 스키마에 맞게 model과 mapper 수정`);
75
+ console.log(`3. 실제 API 엔드포인트에 맞게 get-${kebabName}-list.ts 수정`);
76
+ }
77
+
78
+ function createFiles(basePath, kebabName, pascalName, camelName) {
79
+ // index.ts
80
+ const indexContent = `export * as ${camelName}Api from "./api";
81
+ `;
82
+
83
+ // api/index.ts
84
+ const apiIndexContent = `export { get${pascalName}List } from "./get-${kebabName}-list";
85
+ export { get${pascalName}Detail } from "./get-${kebabName}-detail";
86
+ export { ${camelName}Queries } from "./${kebabName}-queries";
87
+ `;
88
+
89
+ // api/get-{entity}-list.ts
90
+ const getListContent = `// TODO: API 클라이언트 import 추가
91
+ // import { apiClient } from "@/shared/api";
92
+ import { ${pascalName}ListQuery } from "./query/${kebabName}-list-query";
93
+
94
+ export const get${pascalName}List = async (filters: ${pascalName}ListQuery) => {
95
+ // TODO: 실제 API 호출로 변경 필요
96
+ // return apiClient.get("/api/${kebabName}", { params: filters });
97
+ throw new Error("API 호출 구현 필요");
98
+ };
99
+ `;
100
+
101
+ // api/get-{entity}-detail.ts
102
+ const getDetailContent = `// TODO: API 클라이언트 import 추가
103
+ // import { apiClient } from "@/shared/api";
104
+
105
+ export const get${pascalName}Detail = async (id: number) => {
106
+ // TODO: 실제 API 호출로 변경 필요
107
+ // return apiClient.get(\`/api/${kebabName}/\${id}\`);
108
+ throw new Error("API 호출 구현 필요");
109
+ };
110
+ `;
111
+
112
+ // api/{entity}-queries.ts
113
+ const queriesContent = `import { queryOptions } from "@tanstack/react-query";
114
+ import { ${pascalName}ListQuery } from "./query/${kebabName}-list-query";
115
+ import { get${pascalName}List } from "./get-${kebabName}-list";
116
+ import { get${pascalName}Detail } from "./get-${kebabName}-detail";
117
+ import { map${pascalName} } from "./mapper/map-${kebabName}";
118
+ import { map${pascalName}Detail } from "./mapper/map-${kebabName}-detail";
119
+
120
+ export const ${camelName}Queries = {
121
+ all: () => ["${kebabName}"],
122
+ lists: () => [...${camelName}Queries.all(), "list"],
123
+ list: (filters: ${pascalName}ListQuery) =>
124
+ queryOptions({
125
+ queryKey: [...${camelName}Queries.lists(), filters],
126
+ queryFn: () => get${pascalName}List(filters),
127
+ select: (data) => {
128
+ return {
129
+ ...data,
130
+ items: data.items.map(map${pascalName}),
131
+ };
132
+ },
133
+ }),
134
+ details: () => [...${camelName}Queries.all(), "detail"],
135
+ detail: (id: number) =>
136
+ queryOptions({
137
+ queryKey: [...${camelName}Queries.details(), id],
138
+ queryFn: () => get${pascalName}Detail(id),
139
+ select: (data) => map${pascalName}Detail(data),
140
+ }),
141
+ };
142
+ `;
143
+
144
+ // api/mapper/map-{entity}.ts
145
+ const mapperContent = `import { ${pascalName}Schema } from "../../model/${kebabName}";
146
+
147
+ // TODO: API 응답 타입을 실제 타입으로 변경
148
+ type ${pascalName}Response = {
149
+ id: number;
150
+ createDate: string;
151
+ updateDate: string;
152
+ };
153
+
154
+ export const map${pascalName} = (item: ${pascalName}Response) => {
155
+ const res = ${pascalName}Schema.safeParse({
156
+ id: item.id,
157
+ // TODO: 실제 API 응답 구조에 맞게 매핑 수정 필요
158
+ createDate: item.createDate,
159
+ updateDate: item.updateDate,
160
+ });
161
+ if (!res.success) {
162
+ console.error(res.error);
163
+ return undefined;
164
+ }
165
+ return res.data;
166
+ };
167
+ `;
168
+
169
+ // api/mapper/map-{entity}-detail.ts
170
+ const mapperDetailContent = `import { ${pascalName}DetailSchema } from "../../model/${kebabName}-detail";
171
+
172
+ // TODO: API 응답 타입을 실제 타입으로 변경
173
+ type ${pascalName}DetailResponse = {
174
+ id: number;
175
+ createDate: string;
176
+ updateDate: string;
177
+ };
178
+
179
+ export const map${pascalName}Detail = (item: ${pascalName}DetailResponse) => {
180
+ const res = ${pascalName}DetailSchema.safeParse({
181
+ id: item.id,
182
+ // TODO: 실제 API 응답 구조에 맞게 매핑 수정 필요
183
+ createDate: item.createDate,
184
+ updateDate: item.updateDate,
185
+ });
186
+ if (!res.success) {
187
+ console.error(res.error);
188
+ return undefined;
189
+ }
190
+ return res.data;
191
+ };
192
+ `;
193
+
194
+ // api/query/{entity}-list-query.ts
195
+ const queryContent = `export type ${pascalName}ListQuery = {
196
+ limit?: number;
197
+ offset?: number;
198
+ // TODO: 추가 필터링 옵션이 필요한 경우 여기에 추가
199
+ };
200
+ `;
201
+
202
+ // model/{entity}.ts
203
+ const modelContent = `import { z } from "zod";
204
+
205
+ export const ${pascalName}Schema = z.object({
206
+ id: z.number(),
207
+ createDate: z.string(),
208
+ updateDate: z.string(),
209
+ // TODO: 실제 데이터 구조에 맞게 스키마 수정 필요
210
+ });
211
+
212
+ export type ${pascalName}Type = z.infer<typeof ${pascalName}Schema>;
213
+ `;
214
+
215
+ //model/{entity}-detail.ts
216
+ const detailContent = `import { z } from "zod";
217
+
218
+ export const ${pascalName}DetailSchema = z.object({
219
+ id: z.number(),
220
+ createDate: z.string(),
221
+ updateDate: z.string(),
222
+ });
223
+
224
+ export type ${pascalName}DetailType = z.infer<typeof ${pascalName}DetailSchema>;
225
+ `;
226
+
227
+ // 파일 쓰기
228
+ fs.writeFileSync(path.join(basePath, "index.ts"), indexContent);
229
+ fs.writeFileSync(path.join(basePath, "api", "index.ts"), apiIndexContent);
230
+ fs.writeFileSync(
231
+ path.join(basePath, "api", `get-${kebabName}-list.ts`),
232
+ getListContent,
233
+ );
234
+ fs.writeFileSync(
235
+ path.join(basePath, "api", `get-${kebabName}-detail.ts`),
236
+ getDetailContent,
237
+ );
238
+ fs.writeFileSync(
239
+ path.join(basePath, "api", `${kebabName}-queries.ts`),
240
+ queriesContent,
241
+ );
242
+ fs.writeFileSync(
243
+ path.join(basePath, "api", "mapper", `map-${kebabName}.ts`),
244
+ mapperContent,
245
+ );
246
+ fs.writeFileSync(
247
+ path.join(basePath, "api", "mapper", `map-${kebabName}-detail.ts`),
248
+ mapperDetailContent,
249
+ );
250
+ fs.writeFileSync(
251
+ path.join(basePath, "api", "query", `${kebabName}-list-query.ts`),
252
+ queryContent,
253
+ );
254
+ fs.writeFileSync(
255
+ path.join(basePath, "model", `${kebabName}.ts`),
256
+ modelContent,
257
+ );
258
+ fs.writeFileSync(
259
+ path.join(basePath, "model", `${kebabName}-detail.ts`),
260
+ detailContent,
261
+ );
262
+ }
263
+
264
+ // CLI 실행
265
+ const args = process.argv.slice(2);
266
+
267
+ if (args.length === 0) {
268
+ console.log("@blastlabs/utils - FSD Entity Generator\n");
269
+ console.log("사용법: npx blastlabs-generate-entity <entity-name>\n");
270
+ console.log("⚠️ entities 폴더 내에서 실행해주세요!\n");
271
+ console.log("예시:");
272
+ console.log(" cd src/entities");
273
+ console.log(" npx blastlabs-generate-entity user");
274
+ console.log(" npx blastlabs-generate-entity my-new-entity");
275
+ console.log(" npx blastlabs-generate-entity MyNewEntity");
276
+ process.exit(1);
277
+ }
278
+
279
+ const entityName = args[0];
280
+ const targetDir = process.cwd();
281
+
282
+ createEntityStructure(entityName, targetDir);
@@ -0,0 +1,95 @@
1
+ import React from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { UseAuthOptions } from '../../hooks/auth';
4
+ type AuthGuardProps = {
5
+ /** 인증된 경우 렌더링할 컴포넌트 */
6
+ children: ReactNode;
7
+ /** 로딩 중 표시할 컴포넌트 */
8
+ fallback?: ReactNode;
9
+ /** 인증되지 않은 경우 호출되는 콜백 (리다이렉트 로직 구현) */
10
+ onUnauthenticated?: () => void;
11
+ /** 로딩 완료 후 인증되지 않은 경우 렌더링할 컴포넌트 (onUnauthenticated가 없을 때) */
12
+ unauthenticatedFallback?: ReactNode;
13
+ /** useAuth 훅 옵션 (선택사항) */
14
+ authOptions?: UseAuthOptions;
15
+ };
16
+ /**
17
+ * 인증 가드 컴포넌트
18
+ * 인증이 필요한 페이지를 보호하는 컴포넌트
19
+ *
20
+ * 내부적으로 useAuth 훅을 호출하여 localStorage/sessionStorage에서 인증 상태를 확인합니다.
21
+ * 각 AuthGuard는 독립적으로 동작하며, storage를 통해 자동으로 동기화됩니다.
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * // 기본 사용 (localStorage 자동 로드)
26
+ * import { AuthGuard } from '@blastlabs/utils';
27
+ * import { useRouter } from 'next/navigation';
28
+ *
29
+ * function ProtectedPage() {
30
+ * const router = useRouter();
31
+ *
32
+ * return (
33
+ * <AuthGuard
34
+ * authOptions={{ autoLoadUser: true }}
35
+ * onUnauthenticated={() => router.push('/login')}
36
+ * fallback={<LoadingSpinner />}
37
+ * >
38
+ * <YourProtectedContent />
39
+ * </AuthGuard>
40
+ * );
41
+ * }
42
+ * ```
43
+ *
44
+ * @example
45
+ * ```tsx
46
+ * // React Router에서 사용
47
+ * import { useNavigate } from 'react-router-dom';
48
+ *
49
+ * function ProtectedPage() {
50
+ * const navigate = useNavigate();
51
+ *
52
+ * return (
53
+ * <AuthGuard
54
+ * authOptions={{ autoLoadUser: true }}
55
+ * onUnauthenticated={() => navigate('/login')}
56
+ * >
57
+ * <YourProtectedContent />
58
+ * </AuthGuard>
59
+ * );
60
+ * }
61
+ * ```
62
+ *
63
+ * @example
64
+ * ```tsx
65
+ * // 리다이렉트 없이 대체 UI 표시
66
+ * <AuthGuard
67
+ * authOptions={{ autoLoadUser: true }}
68
+ * unauthenticatedFallback={
69
+ * <div>
70
+ * <h1>로그인이 필요합니다</h1>
71
+ * <Link to="/login">로그인 페이지로 이동</Link>
72
+ * </div>
73
+ * }
74
+ * >
75
+ * <YourProtectedContent />
76
+ * </AuthGuard>
77
+ * ```
78
+ *
79
+ * @example
80
+ * ```tsx
81
+ * // 여러 페이지에서 사용해도 storage로 자동 동기화
82
+ * // Page1.tsx
83
+ * <AuthGuard authOptions={{ autoLoadUser: true }} onUnauthenticated={...}>
84
+ * <Page1Content />
85
+ * </AuthGuard>
86
+ *
87
+ * // Page2.tsx - 동일한 인증 상태 공유 (localStorage 사용)
88
+ * <AuthGuard authOptions={{ autoLoadUser: true }} onUnauthenticated={...}>
89
+ * <Page2Content />
90
+ * </AuthGuard>
91
+ * ```
92
+ */
93
+ export declare function AuthGuard({ children, fallback, onUnauthenticated, unauthenticatedFallback, authOptions, }: AuthGuardProps): React.JSX.Element | null;
94
+ export {};
95
+ //# sourceMappingURL=AuthGuard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthGuard.d.ts","sourceRoot":"","sources":["../../../src/components/auth/AuthGuard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAC7C,OAAO,EAA0B,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAE1E,KAAK,cAAc,GAAG;IACpB,uBAAuB;IACvB,QAAQ,EAAE,SAAS,CAAC;IACpB,oBAAoB;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,uCAAuC;IACvC,iBAAiB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC/B,6DAA6D;IAC7D,uBAAuB,CAAC,EAAE,SAAS,CAAC;IACpC,0BAA0B;IAC1B,WAAW,CAAC,EAAE,cAAc,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AACH,wBAAgB,SAAS,CAAC,EACxB,QAAQ,EACR,QAAQ,EACR,iBAAiB,EACjB,uBAAuB,EACvB,WAAW,GACZ,EAAE,cAAc,4BA0BhB"}