@ph-cms/client-sdk 0.1.13 → 0.1.15

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.
package/README.md CHANGED
@@ -56,10 +56,7 @@ import type {
56
56
 
57
57
  // Channel
58
58
  ChannelDto,
59
- CreateChannelDto,
60
- ListChannelQuery,
61
59
  CheckHierarchyQuery,
62
- PagedChannelListResponse,
63
60
 
64
61
  // Content
65
62
  ContentDto,
@@ -77,12 +74,9 @@ import type {
77
74
 
78
75
  // Terms
79
76
  TermDto,
80
- ListTermsQuery,
81
- PagedTermListResponse,
82
77
 
83
78
  // Geo
84
79
  GeoJSON,
85
- BoundsQuery,
86
80
 
87
81
  // Media
88
82
  MediaUploadTicketRequest,
@@ -544,9 +538,11 @@ function ProfileEditor({ userUid }) {
544
538
  }
545
539
  ```
546
540
 
547
- ### Standalone (Non-React) Usage
541
+ ## Using API Directly (Without Hooks)
548
542
 
549
- React 없이 `PHCMSClient`를 직접 사용할 수 있습니다.
543
+ React Hook을 사용하지 않는 환경(Vanilla JS, Node.js, 또는 React 컴포넌트 외부)에서도 `PHCMSClient`를 직접 사용하여 모든 기능을 이용할 수 있습니다.
544
+
545
+ ### 1. Client 초기화
550
546
 
551
547
  ```ts
552
548
  import { PHCMSClient, LocalAuthProvider } from '@ph-cms/client-sdk';
@@ -556,27 +552,71 @@ const client = new PHCMSClient({
556
552
  baseURL: 'https://api.example.com',
557
553
  auth: authProvider,
558
554
  });
555
+ ```
559
556
 
560
- // 로그인 provider에 토큰이 자동 저장됨
557
+ ### 2. 인증 사용자 정보
558
+
559
+ ```ts
560
+ // 로그인 (토큰은 provider에 자동 저장됨)
561
561
  const authResponse = await client.auth.login({
562
562
  email: 'user@example.com',
563
563
  password: 'password',
564
564
  });
565
565
 
566
- // 프로필 조회
567
- const me = await client.auth.me();
568
- console.log(me.email);
566
+ // 현재 사용자 프로필 조회
567
+ // channelUid를 넘기면 해당 채널에 대한 약관 준수 상태 등이 포함됩니다.
568
+ const me = await client.auth.me({ channelUid: 'my-channel-uid' });
569
+ console.log(`Hello, ${me.display_name}`);
570
+
571
+ // 로그아웃
572
+ await client.auth.logout();
573
+ ```
574
+
575
+ ### 3. 콘텐츠 및 채널 관리
576
+
577
+ ```ts
578
+ // 콘텐츠 목록 조회
579
+ const posts = await client.content.list({
580
+ channelUid: 'my-channel-uid',
581
+ type: 'post',
582
+ limit: 10
583
+ });
584
+
585
+ // 콘텐츠 상세 조회
586
+ const detail = await client.content.get('content-uid');
587
+
588
+ // 채널 정보 조회
589
+ const channel = await client.channel.getBySlug('my-channel-slug');
590
+ ```
591
+
592
+ ### 4. 약관 동의
593
+
594
+ ```ts
595
+ // 채널별 약관 목록 조회
596
+ const terms = await client.terms.listByChannel('my-channel-uid');
597
+
598
+ // 약관 동의 제출
599
+ await client.terms.agree({
600
+ channelUid: 'my-channel-uid',
601
+ termCodes: ['service_terms_v1', 'privacy_policy_v1']
602
+ });
603
+ ```
604
+
605
+ ### 5. 토큰 수동 관리 (선택 사항)
606
+
607
+ 일반적으로 SDK가 가로채기(Interceptor)를 통해 토큰을 자동으로 관리하지만, 직접 제어해야 할 경우 다음과 같이 사용합니다.
569
608
 
570
- // 토큰 갱신 (수동)
571
- // 일반적으로 SDK가 자동으로 처리하지만, 필요 시 직접 호출 가능
609
+ ```ts
610
+ // 현재 저장된 리프레시 토큰 가져오기
572
611
  const refreshToken = authProvider.getRefreshToken();
612
+
573
613
  if (refreshToken) {
614
+ // 토큰 갱신 요청
574
615
  const newTokens = await client.auth.refresh(refreshToken);
616
+
617
+ // 새 토큰 저장
575
618
  authProvider.setTokens(newTokens.accessToken, newTokens.refreshToken);
576
619
  }
577
-
578
- // 로그아웃
579
- await client.auth.logout();
580
620
  ```
581
621
 
582
622
  ### Legacy Hooks
@@ -711,10 +751,13 @@ function App() {
711
751
 
712
752
  ### Content
713
753
 
754
+ `useContentList`, `useCreateContent` 등 콘텐츠 관련 훅은 `PHCMSProvider`에 설정된 `channelUid`를 자동으로 사용합니다.
755
+
714
756
  ```tsx
715
- import { useContentList, useContentDetail } from '@ph-cms/client-sdk';
757
+ import { useContentList } from '@ph-cms/client-sdk';
716
758
 
717
759
  function ContentList() {
760
+ // channelUid를 직접 넘기지 않아도 컨텍스트의 값을 사용합니다.
718
761
  const { data, isLoading } = useContentList({ limit: 10 });
719
762
 
720
763
  if (isLoading) return <div>Loading...</div>;
@@ -729,17 +772,6 @@ function ContentList() {
729
772
  }
730
773
  ```
731
774
 
732
- ### Channel
733
-
734
- ```tsx
735
- import { useChannelList } from '@ph-cms/client-sdk';
736
-
737
- function ChannelList() {
738
- const { data, isLoading } = useChannelList({ limit: 20 });
739
- // ...
740
- }
741
- ```
742
-
743
775
  ---
744
776
 
745
777
  ## Like (좋아요)
@@ -1063,8 +1095,6 @@ try {
1063
1095
 
1064
1096
  ---
1065
1097
 
1066
- ## API Reference
1067
-
1068
1098
  ### `PHCMSClient`
1069
1099
 
1070
1100
  ```ts
@@ -1073,6 +1103,7 @@ const client = new PHCMSClient({
1073
1103
  apiPrefix?: string; // API 경로 접두사 (기본값: '/api')
1074
1104
  auth?: AuthProvider; // 인증 프로바이더
1075
1105
  timeout?: number; // 요청 타임아웃 ms (기본값: 10000)
1106
+ axiosInstance?: AxiosInstance; // 직접 커스터마이징한 Axios 인스턴스 (선택 사항)
1076
1107
  });
1077
1108
 
1078
1109
  client.authProvider // AuthProvider | undefined
@@ -1085,6 +1116,27 @@ client.terms // TermsModule
1085
1116
  client.media // MediaModule
1086
1117
  ```
1087
1118
 
1119
+ ### 커스텀 Axios 인스턴스 사용 (서버 to 서버 등)
1120
+
1121
+ 인증서(SSL)가 필요하거나 특수한 Agent 설정이 필요한 경우, 직접 생성한 Axios 인스턴스를 주입할 수 있습니다.
1122
+
1123
+ ```ts
1124
+ import axios from 'axios';
1125
+ import https from 'https';
1126
+ import { PHCMSClient } from '@ph-cms/client-sdk';
1127
+
1128
+ const customInstance = axios.create({
1129
+ httpsAgent: new https.Agent({
1130
+ rejectUnauthorized: false, // 혹은 인증서 설정
1131
+ }),
1132
+ });
1133
+
1134
+ const client = new PHCMSClient({
1135
+ baseURL: 'https://internal-api.ph-cms.com',
1136
+ axiosInstance: customInstance,
1137
+ });
1138
+ ```
1139
+
1088
1140
  ### `UserModule` (`client.user`)
1089
1141
 
1090
1142
  | 메서드 | 설명 |
@@ -1098,7 +1150,7 @@ client.media // MediaModule
1098
1150
  | `login(data: LoginRequest)` | 이메일/비밀번호 로그인 → `AuthResponse` |
1099
1151
  | `loginWithFirebase(data: FirebaseExchangeRequest)` | Firebase ID 토큰 교환 → `AuthResponse` |
1100
1152
  | `register(data: RegisterRequest)` | 회원가입 → `AuthResponse` |
1101
- | `me()` | 현재 사용자 프로필 조회 → `UserDto` |
1153
+ | `me(params?: { channelUid?: string })` | 현재 사용자 프로필 조회 → `UserDto` |
1102
1154
  | `refresh(refreshToken: string)` | 토큰 갱신 → `{ accessToken, refreshToken }` |
1103
1155
  | `logout()` | 로그아웃 (프로바이더 토큰 삭제 + 서버 세션 무효화) |
1104
1156
 
@@ -1119,6 +1171,23 @@ client.media // MediaModule
1119
1171
  | `toggleLike(uid: string)` | 좋아요 토글 → `ToggleLikeResponse` |
1120
1172
  | `getLikeStatus(uid: string)` | 내 좋아요 여부 확인 → `LikeStatusResponse` |
1121
1173
 
1174
+ ### `ChannelModule` (`client.channel`)
1175
+
1176
+ | 메서드 | 설명 |
1177
+ |---|---|
1178
+ | `getByUid(uid: string)` | UID로 채널 상세 조회 |
1179
+ | `getBySlug(slug: string)` | 슬러그로 채널 상세 조회 |
1180
+ | `update(uid: string, data: any)` | 채널 정보 수정 |
1181
+ | `checkHierarchy(params: CheckHierarchyQuery)` | 하이어라키 규칙 체크 |
1182
+
1183
+ ### `TermsModule` (`client.terms`)
1184
+
1185
+ | 메서드 | 설명 |
1186
+ |---|---|
1187
+ | `get(id: number)` | 약관 상세 조회 |
1188
+ | `agree(data: { termCodes: string[]; channelUid?: string })` | 약관 동의 제출 |
1189
+ | `listByChannel(channelUid: string)` | 채널별 약관 목록 조회 |
1190
+
1122
1191
  ### JWT Utilities
1123
1192
 
1124
1193
  클라이언트에서 토큰 상태를 확인할 수 있는 유틸리티입니다 (서명 검증은 하지 않음).
package/bin/cli.js ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ const command = process.argv[2];
7
+
8
+ if (command === 'init-skill') {
9
+ initSkill();
10
+ } else {
11
+ console.log('Usage: npx @ph-cms/client-sdk init-skill');
12
+ process.exit(1);
13
+ }
14
+
15
+ function initSkill() {
16
+ const skillDir = path.join(process.cwd(), '.gemini/skills/ph-cms-client');
17
+ const skillMdPath = path.join(skillDir, 'SKILL.md');
18
+
19
+ const skillContent = `# PH-CMS Client SDK Skill
20
+
21
+ This skill provides expert guidance for implementing and maintaining applications using the \`@ph-cms/client-sdk\`.
22
+
23
+ ## 📌 Core Directives
24
+
25
+ 1. **Context Scoping**: All hooks (\`useContentList\`, \`useChannelTerms\`, \`useCreateContent\`, etc.) are automatically scoped to the \`channelUid\` provided in the \`PHCMSProvider\`. Do NOT manually pass \`channelUid\` to these hooks unless a cross-channel operation is explicitly requested.
26
+ 2. **Provider Requirement**: Always ensure all components using SDK hooks are wrapped within a \`PHCMSProvider\`.
27
+ 3. **Authentication Lifecycle**: Use the \`useAuth()\` hook for login, registration, and logout. It handles token storage, refreshing, and profile state automatically.
28
+ 4. **Direct API Usage**: For non-React environments or server-to-server calls, use the \`PHCMSClient\` class directly. You can inject a custom \`axiosInstance\` for special network needs (e.g., custom HTTPS agents).
29
+
30
+ ## 🛠 Usage Patterns
31
+
32
+ ### 1. Provider Setup
33
+ \`\`\`tsx
34
+ import { PHCMSClient, LocalAuthProvider, PHCMSProvider } from '@ph-cms/client-sdk';
35
+
36
+ const authProvider = new LocalAuthProvider('my_app_');
37
+ const client = new PHCMSClient({
38
+ baseURL: 'https://api.example.com',
39
+ auth: authProvider,
40
+ });
41
+
42
+ export function App() {
43
+ return (
44
+ <PHCMSProvider client={client} channelUid="target-channel-slug">
45
+ <YourApp />
46
+ </PHCMSProvider>
47
+ );
48
+ }
49
+ \`\`\`
50
+
51
+ ### 2. Content Hook (Auto-scoped)
52
+ \`\`\`tsx
53
+ const { data, isLoading } = useContentList({ limit: 10 });
54
+ \`\`\`
55
+
56
+ ### 3. User & Terms (Auto-scoped)
57
+ \`\`\`tsx
58
+ const { data: terms } = useChannelTerms();
59
+ const { mutate: agree } = useAgreeTerms();
60
+ \`\`\`
61
+
62
+ ## ⚠️ Common Pitfalls
63
+ - **Manual channelUid passing**: Avoid \`useContentList({ channelUid: '...', ... })\` unless necessary. Rely on the provider.
64
+ - **Hook-less API calls**: When using \`client.content.list()\` directly, you MUST provide \`channelUid\` in the params as there is no context available.
65
+ `;
66
+
67
+ if (!fs.existsSync(skillDir)) {
68
+ fs.mkdirSync(skillDir, { recursive: true });
69
+ }
70
+
71
+ fs.writeFileSync(skillMdPath, skillContent);
72
+ console.log('✅ PH-CMS Client SDK Skill has been successfully initialized at .gemini/skills/ph-cms-client/SKILL.md');
73
+ }
package/dist/client.d.ts CHANGED
@@ -11,6 +11,7 @@ export interface PHCMSClientConfig {
11
11
  apiPrefix?: string;
12
12
  auth?: AuthProvider;
13
13
  timeout?: number;
14
+ axiosInstance?: AxiosInstance;
14
15
  }
15
16
  export declare class PHCMSClient {
16
17
  private config;
package/dist/client.js CHANGED
@@ -31,13 +31,17 @@ class PHCMSClient {
31
31
  */
32
32
  this.refreshQueue = [];
33
33
  const normalizedApiPrefix = `/${(config.apiPrefix || '/api').replace(/^\/+|\/+$/g, '')}`;
34
- this.axiosInstance = axios_1.default.create({
34
+ this.axiosInstance = config.axiosInstance || axios_1.default.create({
35
35
  baseURL: config.baseURL,
36
36
  timeout: config.timeout || 10000,
37
37
  headers: {
38
38
  'Content-Type': 'application/json',
39
39
  },
40
40
  });
41
+ // Ensure baseURL is set if provided, even on a pre-existing instance.
42
+ if (config.baseURL && !this.axiosInstance.defaults.baseURL) {
43
+ this.axiosInstance.defaults.baseURL = config.baseURL;
44
+ }
41
45
  // Initialize Modules (before interceptors so the refresh wiring
42
46
  // can reference `this.auth`).
43
47
  this.auth = new auth_1.AuthModule(this.axiosInstance, config.auth);
package/dist/context.d.ts CHANGED
@@ -10,7 +10,7 @@ export interface PHCMSContextType {
10
10
  isLoading: boolean;
11
11
  isError: boolean;
12
12
  /** The current channel context for terms compliance. */
13
- channelUid?: string;
13
+ channelUid: string;
14
14
  /**
15
15
  * Fine-grained authentication status.
16
16
  * - `'loading'`: Token exists, `/auth/me` is being fetched.
@@ -26,7 +26,7 @@ export interface PHCMSContextType {
26
26
  export interface PHCMSProviderProps {
27
27
  client: PHCMSClient;
28
28
  queryClient?: QueryClient;
29
- channelUid?: string;
29
+ channelUid: string;
30
30
  children: ReactNode;
31
31
  }
32
32
  /**
package/dist/context.js CHANGED
@@ -43,6 +43,10 @@ const AUTH_ME_QUERY_KEY = ['auth', 'me'];
43
43
  */
44
44
  const PHCMSInternalProvider = ({ client, channelUid, children }) => {
45
45
  const queryClient = (0, react_query_1.useQueryClient)();
46
+ // Check for channel identifier
47
+ if (!channelUid) {
48
+ throw new Error('PHCMSProvider requires channelUid');
49
+ }
46
50
  // Track token presence in state to trigger re-renders when it changes.
47
51
  // Initial value from provider.
48
52
  const [hasToken, setHasToken] = (0, react_1.useState)(() => client.authProvider?.hasToken() ?? false);
@@ -113,6 +113,7 @@ export declare const useAuth: () => {
113
113
  accessToken: string;
114
114
  }, Error, {
115
115
  idToken: string;
116
+ channelUid?: string | undefined;
116
117
  }, unknown>;
117
118
  register: import("@tanstack/react-query").UseMutateAsyncFunction<{
118
119
  refreshToken: string;
@@ -159,6 +160,81 @@ export declare const useAuth: () => {
159
160
  termCodes?: string[] | undefined;
160
161
  channelUid?: string | undefined;
161
162
  }, unknown>;
163
+ loginAnonymous: import("@tanstack/react-query").UseMutateAsyncFunction<{
164
+ refreshToken: string;
165
+ user: {
166
+ status: string;
167
+ uid: string;
168
+ email: string;
169
+ username: string | null;
170
+ display_name: string;
171
+ avatar_url: string | null;
172
+ phone_number: string | null;
173
+ email_verified_at: string | null;
174
+ phone_verified_at: string | null;
175
+ locale: string;
176
+ timezone: string;
177
+ role: string[];
178
+ profile_data: Record<string, any>;
179
+ last_login_at: string | null;
180
+ created_at: string;
181
+ updated_at: string;
182
+ channel_agreements?: {
183
+ channel_uid: string | null;
184
+ is_fully_compliant: boolean;
185
+ agreements: {
186
+ code: string;
187
+ version: string;
188
+ title: string;
189
+ term_id: number;
190
+ is_agreed: boolean;
191
+ is_required: boolean;
192
+ is_latest: boolean;
193
+ agreed_at: string | null;
194
+ }[];
195
+ }[] | undefined;
196
+ };
197
+ accessToken: string;
198
+ }, Error, {
199
+ channelUid?: string;
200
+ } | undefined, unknown>;
201
+ upgradeAnonymous: import("@tanstack/react-query").UseMutateAsyncFunction<{
202
+ status: string;
203
+ uid: string;
204
+ email: string;
205
+ username: string | null;
206
+ display_name: string;
207
+ avatar_url: string | null;
208
+ phone_number: string | null;
209
+ email_verified_at: string | null;
210
+ phone_verified_at: string | null;
211
+ locale: string;
212
+ timezone: string;
213
+ role: string[];
214
+ profile_data: Record<string, any>;
215
+ last_login_at: string | null;
216
+ created_at: string;
217
+ updated_at: string;
218
+ channel_agreements?: {
219
+ channel_uid: string | null;
220
+ is_fully_compliant: boolean;
221
+ agreements: {
222
+ code: string;
223
+ version: string;
224
+ title: string;
225
+ term_id: number;
226
+ is_agreed: boolean;
227
+ is_required: boolean;
228
+ is_latest: boolean;
229
+ agreed_at: string | null;
230
+ }[];
231
+ }[] | undefined;
232
+ }, Error, {
233
+ email: string;
234
+ password: string;
235
+ display_name?: string;
236
+ username?: string;
237
+ }, unknown>;
162
238
  logout: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, void, unknown>;
163
239
  loginStatus: import("@tanstack/react-query").UseMutationResult<{
164
240
  refreshToken: string;
@@ -236,6 +312,7 @@ export declare const useAuth: () => {
236
312
  accessToken: string;
237
313
  }, Error, {
238
314
  idToken: string;
315
+ channelUid?: string | undefined;
239
316
  }, unknown>;
240
317
  registerStatus: import("@tanstack/react-query").UseMutationResult<{
241
318
  refreshToken: string;
@@ -282,10 +359,45 @@ export declare const useAuth: () => {
282
359
  termCodes?: string[] | undefined;
283
360
  channelUid?: string | undefined;
284
361
  }, unknown>;
285
- logoutStatus: import("@tanstack/react-query").UseMutationResult<void, Error, void, unknown>;
286
- };
287
- export declare const useUser: () => {
288
- data: {
362
+ loginAnonymousStatus: import("@tanstack/react-query").UseMutationResult<{
363
+ refreshToken: string;
364
+ user: {
365
+ status: string;
366
+ uid: string;
367
+ email: string;
368
+ username: string | null;
369
+ display_name: string;
370
+ avatar_url: string | null;
371
+ phone_number: string | null;
372
+ email_verified_at: string | null;
373
+ phone_verified_at: string | null;
374
+ locale: string;
375
+ timezone: string;
376
+ role: string[];
377
+ profile_data: Record<string, any>;
378
+ last_login_at: string | null;
379
+ created_at: string;
380
+ updated_at: string;
381
+ channel_agreements?: {
382
+ channel_uid: string | null;
383
+ is_fully_compliant: boolean;
384
+ agreements: {
385
+ code: string;
386
+ version: string;
387
+ title: string;
388
+ term_id: number;
389
+ is_agreed: boolean;
390
+ is_required: boolean;
391
+ is_latest: boolean;
392
+ agreed_at: string | null;
393
+ }[];
394
+ }[] | undefined;
395
+ };
396
+ accessToken: string;
397
+ }, Error, {
398
+ channelUid?: string;
399
+ } | undefined, unknown>;
400
+ upgradeAnonymousStatus: import("@tanstack/react-query").UseMutationResult<{
289
401
  status: string;
290
402
  uid: string;
291
403
  email: string;
@@ -316,10 +428,13 @@ export declare const useUser: () => {
316
428
  agreed_at: string | null;
317
429
  }[];
318
430
  }[] | undefined;
319
- } | null;
320
- isLoading: boolean;
321
- isAuthenticated: boolean;
322
- error: boolean;
431
+ }, Error, {
432
+ email: string;
433
+ password: string;
434
+ display_name?: string;
435
+ username?: string;
436
+ }, unknown>;
437
+ logoutStatus: import("@tanstack/react-query").UseMutationResult<void, Error, void, unknown>;
323
438
  };
324
439
  export declare const useLogin: () => import("@tanstack/react-query").UseMutationResult<{
325
440
  refreshToken: string;
@@ -361,3 +476,78 @@ export declare const useLogin: () => import("@tanstack/react-query").UseMutation
361
476
  password: string;
362
477
  }, unknown>;
363
478
  export declare const useLogout: () => import("@tanstack/react-query").UseMutationResult<void, Error, void, unknown>;
479
+ export declare const useLoginAnonymous: () => import("@tanstack/react-query").UseMutationResult<{
480
+ refreshToken: string;
481
+ user: {
482
+ status: string;
483
+ uid: string;
484
+ email: string;
485
+ username: string | null;
486
+ display_name: string;
487
+ avatar_url: string | null;
488
+ phone_number: string | null;
489
+ email_verified_at: string | null;
490
+ phone_verified_at: string | null;
491
+ locale: string;
492
+ timezone: string;
493
+ role: string[];
494
+ profile_data: Record<string, any>;
495
+ last_login_at: string | null;
496
+ created_at: string;
497
+ updated_at: string;
498
+ channel_agreements?: {
499
+ channel_uid: string | null;
500
+ is_fully_compliant: boolean;
501
+ agreements: {
502
+ code: string;
503
+ version: string;
504
+ title: string;
505
+ term_id: number;
506
+ is_agreed: boolean;
507
+ is_required: boolean;
508
+ is_latest: boolean;
509
+ agreed_at: string | null;
510
+ }[];
511
+ }[] | undefined;
512
+ };
513
+ accessToken: string;
514
+ }, Error, {
515
+ channelUid?: string;
516
+ } | undefined, unknown>;
517
+ export declare const useUpgradeAnonymous: () => import("@tanstack/react-query").UseMutationResult<{
518
+ status: string;
519
+ uid: string;
520
+ email: string;
521
+ username: string | null;
522
+ display_name: string;
523
+ avatar_url: string | null;
524
+ phone_number: string | null;
525
+ email_verified_at: string | null;
526
+ phone_verified_at: string | null;
527
+ locale: string;
528
+ timezone: string;
529
+ role: string[];
530
+ profile_data: Record<string, any>;
531
+ last_login_at: string | null;
532
+ created_at: string;
533
+ updated_at: string;
534
+ channel_agreements?: {
535
+ channel_uid: string | null;
536
+ is_fully_compliant: boolean;
537
+ agreements: {
538
+ code: string;
539
+ version: string;
540
+ title: string;
541
+ term_id: number;
542
+ is_agreed: boolean;
543
+ is_required: boolean;
544
+ is_latest: boolean;
545
+ agreed_at: string | null;
546
+ }[];
547
+ }[] | undefined;
548
+ }, Error, {
549
+ email: string;
550
+ password: string;
551
+ display_name?: string;
552
+ username?: string;
553
+ }, unknown>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useLogout = exports.useLogin = exports.useUser = exports.useAuth = void 0;
3
+ exports.useUpgradeAnonymous = exports.useLoginAnonymous = exports.useLogout = exports.useLogin = exports.useAuth = void 0;
4
4
  const react_query_1 = require("@tanstack/react-query");
5
5
  const context_1 = require("../context");
6
6
  const AUTH_ME_QUERY_KEY = ['auth', 'me'];
@@ -9,7 +9,7 @@ const AUTH_ME_QUERY_KEY = ['auth', 'me'];
9
9
  * Returns both the current auth status and the actions.
10
10
  */
11
11
  const useAuth = () => {
12
- const { user, isAuthenticated, isLoading, refreshUser } = (0, context_1.usePHCMSContext)();
12
+ const { user, isAuthenticated, isLoading, refreshUser, channelUid } = (0, context_1.usePHCMSContext)();
13
13
  const client = (0, context_1.usePHCMS)();
14
14
  const queryClient = (0, react_query_1.useQueryClient)();
15
15
  const loginMutation = (0, react_query_1.useMutation)({
@@ -19,13 +19,34 @@ const useAuth = () => {
19
19
  },
20
20
  });
21
21
  const loginWithFirebaseMutation = (0, react_query_1.useMutation)({
22
- mutationFn: (data) => client.auth.loginWithFirebase(data),
22
+ mutationFn: (data) => client.auth.loginWithFirebase({
23
+ channelUid: data.channelUid || channelUid,
24
+ ...data
25
+ }),
23
26
  onSuccess: async () => {
24
27
  await refreshUser();
25
28
  },
26
29
  });
27
30
  const registerMutation = (0, react_query_1.useMutation)({
28
- mutationFn: (data) => client.auth.register(data),
31
+ mutationFn: (data) => client.auth.register({
32
+ channelUid: data.channelUid || channelUid,
33
+ ...data
34
+ }),
35
+ onSuccess: async () => {
36
+ await refreshUser();
37
+ },
38
+ });
39
+ const loginAnonymousMutation = (0, react_query_1.useMutation)({
40
+ mutationFn: (data) => client.auth.loginAnonymous({
41
+ channelUid: data?.channelUid || channelUid,
42
+ ...data
43
+ }),
44
+ onSuccess: async () => {
45
+ await refreshUser();
46
+ },
47
+ });
48
+ const upgradeAnonymousMutation = (0, react_query_1.useMutation)({
49
+ mutationFn: (data) => client.auth.upgradeAnonymous(data),
29
50
  onSuccess: async () => {
30
51
  await refreshUser();
31
52
  },
@@ -44,21 +65,19 @@ const useAuth = () => {
44
65
  login: loginMutation.mutateAsync,
45
66
  loginWithFirebase: loginWithFirebaseMutation.mutateAsync,
46
67
  register: registerMutation.mutateAsync,
68
+ loginAnonymous: loginAnonymousMutation.mutateAsync,
69
+ upgradeAnonymous: upgradeAnonymousMutation.mutateAsync,
47
70
  logout: logoutMutation.mutateAsync,
48
71
  // Access to mutation objects for loading/error states if needed
49
72
  loginStatus: loginMutation,
50
73
  loginWithFirebaseStatus: loginWithFirebaseMutation,
51
74
  registerStatus: registerMutation,
75
+ loginAnonymousStatus: loginAnonymousMutation,
76
+ upgradeAnonymousStatus: upgradeAnonymousMutation,
52
77
  logoutStatus: logoutMutation,
53
78
  };
54
79
  };
55
80
  exports.useAuth = useAuth;
56
- // Keep individual hooks for backward compatibility or more specific use cases
57
- const useUser = () => {
58
- const { user, isLoading, isAuthenticated, isError } = (0, context_1.usePHCMSContext)();
59
- return { data: user, isLoading, isAuthenticated, error: isError };
60
- };
61
- exports.useUser = useUser;
62
81
  const useLogin = () => {
63
82
  const { loginStatus } = (0, exports.useAuth)();
64
83
  return loginStatus;
@@ -69,3 +88,13 @@ const useLogout = () => {
69
88
  return logoutStatus;
70
89
  };
71
90
  exports.useLogout = useLogout;
91
+ const useLoginAnonymous = () => {
92
+ const { loginAnonymousStatus } = (0, exports.useAuth)();
93
+ return loginAnonymousStatus;
94
+ };
95
+ exports.useLoginAnonymous = useLoginAnonymous;
96
+ const useUpgradeAnonymous = () => {
97
+ const { upgradeAnonymousStatus } = (0, exports.useAuth)();
98
+ return upgradeAnonymousStatus;
99
+ };
100
+ exports.useUpgradeAnonymous = useUpgradeAnonymous;