@ph-cms/client-sdk 0.1.12 → 0.1.14

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/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;
@@ -1,4 +1,4 @@
1
- import { UpdateContentRequest, ListContentQuery, ContentDto, BoundsQuery } from '@ph-cms/api-contract';
1
+ import { UpdateContentRequest, ListContentQuery, ContentDto } from '@ph-cms/api-contract';
2
2
  export declare const contentKeys: {
3
3
  all: readonly ["contents"];
4
4
  lists: () => readonly ["contents", "list"];
@@ -20,13 +20,6 @@ export declare const contentKeys: {
20
20
  withDetail?: boolean | undefined;
21
21
  includeDeleted?: boolean | undefined;
22
22
  }];
23
- geoLists: () => readonly ["contents", "geo-list"];
24
- geoList: (bounds: BoundsQuery) => readonly ["contents", "geo-list", {
25
- minLat: number;
26
- maxLat: number;
27
- minLng: number;
28
- maxLng: number;
29
- }];
30
23
  details: () => readonly ["contents", "detail"];
31
24
  detail: (uid: string) => readonly ["contents", "detail", string];
32
25
  likes: () => readonly ["contents", "like"];
@@ -42,7 +35,6 @@ export declare const useContentList: (params: ListContentQuery, enabled?: boolea
42
35
  last: boolean;
43
36
  empty: boolean;
44
37
  }, Error>;
45
- export declare const useContentGeoList: (bounds: BoundsQuery) => import("@tanstack/react-query").UseQueryResult<ContentDto[], Error>;
46
38
  export declare const useContentDetail: (uid: string) => import("@tanstack/react-query").UseQueryResult<ContentDto, Error>;
47
39
  export declare const useIncrementView: () => import("@tanstack/react-query").UseMutationResult<void, Error, string, {
48
40
  previousDetail: ContentDto | undefined;
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useDeleteContent = exports.useUpdateContent = exports.useToggleLike = exports.useLikeStatus = exports.useCreateContent = exports.useIncrementView = exports.useContentDetail = exports.useContentGeoList = exports.useContentList = exports.contentKeys = void 0;
3
+ exports.useDeleteContent = exports.useUpdateContent = exports.useToggleLike = exports.useLikeStatus = exports.useCreateContent = exports.useIncrementView = exports.useContentDetail = exports.useContentList = exports.contentKeys = void 0;
4
4
  const react_query_1 = require("@tanstack/react-query");
5
5
  const context_1 = require("../context");
6
6
  exports.contentKeys = {
7
7
  all: ['contents'],
8
8
  lists: () => [...exports.contentKeys.all, 'list'],
9
9
  list: (params) => [...exports.contentKeys.lists(), params],
10
- geoLists: () => [...exports.contentKeys.all, 'geo-list'],
11
- geoList: (bounds) => [...exports.contentKeys.geoLists(), bounds],
12
10
  details: () => [...exports.contentKeys.all, 'detail'],
13
11
  detail: (uid) => [...exports.contentKeys.details(), uid],
14
12
  likes: () => [...exports.contentKeys.all, 'like'],
@@ -16,23 +14,19 @@ exports.contentKeys = {
16
14
  };
17
15
  const useContentList = (params, enabled = true) => {
18
16
  const client = (0, context_1.usePHCMS)();
17
+ const { channelUid } = (0, context_1.usePHCMSContext)();
18
+ const finalParams = {
19
+ channelUid: params.channelUid || channelUid,
20
+ ...params,
21
+ };
19
22
  return (0, react_query_1.useQuery)({
20
- queryKey: exports.contentKeys.list(params),
21
- queryFn: () => client.content.list(params),
23
+ queryKey: exports.contentKeys.list(finalParams),
24
+ queryFn: () => client.content.list(finalParams),
22
25
  staleTime: 1000 * 60, // 1 minute
23
26
  enabled,
24
27
  });
25
28
  };
26
29
  exports.useContentList = useContentList;
27
- const useContentGeoList = (bounds) => {
28
- const client = (0, context_1.usePHCMS)();
29
- return (0, react_query_1.useQuery)({
30
- queryKey: exports.contentKeys.geoList(bounds),
31
- queryFn: () => client.content.listGeo(bounds),
32
- enabled: !!(bounds.minLat && bounds.maxLat && bounds.minLng && bounds.maxLng),
33
- });
34
- };
35
- exports.useContentGeoList = useContentGeoList;
36
30
  const useContentDetail = (uid) => {
37
31
  const client = (0, context_1.usePHCMS)();
38
32
  return (0, react_query_1.useQuery)({
@@ -75,9 +69,13 @@ const useIncrementView = () => {
75
69
  exports.useIncrementView = useIncrementView;
76
70
  const useCreateContent = () => {
77
71
  const client = (0, context_1.usePHCMS)();
72
+ const { channelUid } = (0, context_1.usePHCMSContext)();
78
73
  const queryClient = (0, react_query_1.useQueryClient)();
79
74
  return (0, react_query_1.useMutation)({
80
- mutationFn: (data) => client.content.create(data),
75
+ mutationFn: (data) => client.content.create({
76
+ channelUid: data.channelUid || channelUid,
77
+ ...data,
78
+ }),
81
79
  onSuccess: () => {
82
80
  queryClient.invalidateQueries({ queryKey: exports.contentKeys.lists() });
83
81
  },
@@ -152,7 +150,6 @@ const useToggleLike = () => {
152
150
  onSettled: (data, error, uid) => {
153
151
  // Invalidate the lists so they fetch the latest liked status and like counts
154
152
  queryClient.invalidateQueries({ queryKey: exports.contentKeys.lists() });
155
- queryClient.invalidateQueries({ queryKey: exports.contentKeys.geoLists() });
156
153
  },
157
154
  });
158
155
  };
@@ -70,7 +70,7 @@ const context_1 = require("../context");
70
70
  */
71
71
  const useFirebaseAuthSync = (options) => {
72
72
  const { firebaseAuth, logoutOnFirebaseSignOut = true, onSyncSuccess, onSyncError, } = options;
73
- const { client, isAuthenticated, isLoading, refreshUser } = (0, context_1.usePHCMSContext)();
73
+ const { client, isAuthenticated, isLoading, refreshUser, channelUid } = (0, context_1.usePHCMSContext)();
74
74
  // Use refs for values that change frequently but should not re-trigger
75
75
  // the effect (which would tear down and re-create the Firebase listener).
76
76
  const isAuthenticatedRef = (0, react_1.useRef)(isAuthenticated);
@@ -106,7 +106,7 @@ const useFirebaseAuthSync = (options) => {
106
106
  setIsSyncing(true);
107
107
  try {
108
108
  const idToken = await fbUser.getIdToken();
109
- await client.auth.loginWithFirebase({ idToken });
109
+ await client.auth.loginWithFirebase({ idToken, channelUid });
110
110
  // loginWithFirebase stores the tokens in the provider.
111
111
  // Now refresh the context so `isAuthenticated` and `user` update.
112
112
  await refreshUser();
@@ -12,9 +12,13 @@ exports.stampTourKeys = {
12
12
  };
13
13
  const useCreateStampTour = () => {
14
14
  const client = (0, context_1.usePHCMS)();
15
+ const { channelUid } = (0, context_1.usePHCMSContext)();
15
16
  const queryClient = (0, react_query_1.useQueryClient)();
16
17
  return (0, react_query_1.useMutation)({
17
- mutationFn: (data) => client.content.createStampTour(data),
18
+ mutationFn: (data) => client.content.createStampTour({
19
+ channelUid: data.channelUid || channelUid,
20
+ ...data,
21
+ }),
18
22
  onSuccess: () => {
19
23
  // Invalidate content lists since a new tour is a content item
20
24
  queryClient.invalidateQueries({ queryKey: useContent_1.contentKeys.lists() });
@@ -1,4 +1,48 @@
1
1
  import { UpdateUserProfileRequest } from '@ph-cms/api-contract';
2
+ export declare const termsKeys: {
3
+ all: readonly ["terms"];
4
+ lists: () => readonly ["terms", "list"];
5
+ };
6
+ /**
7
+ * Access the current user profile and status.
8
+ */
9
+ export declare const useUser: () => {
10
+ data: {
11
+ status: string;
12
+ uid: string;
13
+ email: string;
14
+ username: string | null;
15
+ display_name: string;
16
+ avatar_url: string | null;
17
+ phone_number: string | null;
18
+ email_verified_at: string | null;
19
+ phone_verified_at: string | null;
20
+ locale: string;
21
+ timezone: string;
22
+ role: string[];
23
+ profile_data: Record<string, any>;
24
+ last_login_at: string | null;
25
+ created_at: string;
26
+ updated_at: string;
27
+ channel_agreements?: {
28
+ channel_uid: string | null;
29
+ is_fully_compliant: boolean;
30
+ agreements: {
31
+ code: string;
32
+ version: string;
33
+ title: string;
34
+ term_id: number;
35
+ is_agreed: boolean;
36
+ is_required: boolean;
37
+ is_latest: boolean;
38
+ agreed_at: string | null;
39
+ }[];
40
+ }[] | undefined;
41
+ } | null;
42
+ isLoading: boolean;
43
+ isAuthenticated: boolean;
44
+ error: boolean;
45
+ };
2
46
  /**
3
47
  * Hook to update a user's profile.
4
48
  * Typically used by a user to update their own profile.
@@ -38,3 +82,23 @@ export declare const useUpdateProfile: () => import("@tanstack/react-query").Use
38
82
  uid: string;
39
83
  data: UpdateUserProfileRequest | Record<string, any>;
40
84
  }, unknown>;
85
+ /**
86
+ * List terms required/available for the current channel.
87
+ */
88
+ export declare const useChannelTerms: () => import("@tanstack/react-query").UseQueryResult<{
89
+ code: string;
90
+ id: number;
91
+ version: string;
92
+ title: string;
93
+ content: string;
94
+ isActive: boolean;
95
+ createdAt: string;
96
+ isRequired?: boolean | undefined;
97
+ }[], Error>;
98
+ /**
99
+ * Submit term agreements for the current user.
100
+ */
101
+ export declare const useAgreeTerms: () => import("@tanstack/react-query").UseMutationResult<void, Error, {
102
+ termCodes: string[];
103
+ channelUid?: string;
104
+ }, unknown>;
@@ -1,8 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useUpdateProfile = void 0;
3
+ exports.useAgreeTerms = exports.useChannelTerms = exports.useUpdateProfile = exports.useUser = exports.termsKeys = void 0;
4
4
  const react_query_1 = require("@tanstack/react-query");
5
5
  const context_1 = require("../context");
6
+ exports.termsKeys = {
7
+ all: ['terms'],
8
+ lists: () => [...exports.termsKeys.all, 'list'],
9
+ };
10
+ /**
11
+ * Access the current user profile and status.
12
+ */
13
+ const useUser = () => {
14
+ const { user, isLoading, isAuthenticated, isError } = (0, context_1.usePHCMSContext)();
15
+ return { data: user, isLoading, isAuthenticated, error: isError };
16
+ };
17
+ exports.useUser = useUser;
6
18
  /**
7
19
  * Hook to update a user's profile.
8
20
  * Typically used by a user to update their own profile.
@@ -19,3 +31,29 @@ const useUpdateProfile = () => {
19
31
  });
20
32
  };
21
33
  exports.useUpdateProfile = useUpdateProfile;
34
+ /**
35
+ * List terms required/available for the current channel.
36
+ */
37
+ const useChannelTerms = () => {
38
+ const { client, channelUid } = (0, context_1.usePHCMSContext)();
39
+ return (0, react_query_1.useQuery)({
40
+ queryKey: [...exports.termsKeys.all, 'channel', channelUid],
41
+ queryFn: () => client.terms.listByChannel(channelUid),
42
+ enabled: !!channelUid,
43
+ });
44
+ };
45
+ exports.useChannelTerms = useChannelTerms;
46
+ /**
47
+ * Submit term agreements for the current user.
48
+ */
49
+ const useAgreeTerms = () => {
50
+ const client = (0, context_1.usePHCMS)();
51
+ const { channelUid } = (0, context_1.usePHCMSContext)();
52
+ return (0, react_query_1.useMutation)({
53
+ mutationFn: (data) => client.terms.agree({
54
+ channelUid: data.channelUid || channelUid,
55
+ ...data,
56
+ }),
57
+ });
58
+ };
59
+ exports.useAgreeTerms = useAgreeTerms;
package/dist/index.d.ts CHANGED
@@ -13,11 +13,9 @@ export * from './modules/terms';
13
13
  export * from './modules/user';
14
14
  export * from './context';
15
15
  export * from './hooks/useAuth';
16
- export * from './hooks/useChannel';
17
16
  export * from './hooks/useContent';
18
17
  export * from './hooks/useStampTour';
19
18
  export * from './hooks/useFirebaseAuthSync';
20
19
  export * from './hooks/useMedia';
21
- export * from './hooks/useTerms';
22
20
  export * from './hooks/useUser';
23
21
  export * from './types';
package/dist/index.js CHANGED
@@ -29,11 +29,9 @@ __exportStar(require("./modules/terms"), exports);
29
29
  __exportStar(require("./modules/user"), exports);
30
30
  __exportStar(require("./context"), exports);
31
31
  __exportStar(require("./hooks/useAuth"), exports);
32
- __exportStar(require("./hooks/useChannel"), exports);
33
32
  __exportStar(require("./hooks/useContent"), exports);
34
33
  __exportStar(require("./hooks/useStampTour"), exports);
35
34
  __exportStar(require("./hooks/useFirebaseAuthSync"), exports);
36
35
  __exportStar(require("./hooks/useMedia"), exports);
37
- __exportStar(require("./hooks/useTerms"), exports);
38
36
  __exportStar(require("./hooks/useUser"), exports);
39
37
  __exportStar(require("./types"), exports);
@@ -1,4 +1,4 @@
1
- import { AuthResponse, FirebaseExchangeRequest, LoginRequest, RegisterRequest, UserDto } from "@ph-cms/api-contract";
1
+ import { AuthResponse, FirebaseExchangeRequest, LoginRequest, RegisterRequest, UserDto, AnonymousLoginRequest } from "@ph-cms/api-contract";
2
2
  import { AxiosInstance } from "axios";
3
3
  import { AuthProvider } from "../auth/interfaces";
4
4
  export declare class AuthModule {
@@ -16,10 +16,18 @@ export declare class AuthModule {
16
16
  register(data: RegisterRequest): Promise<AuthResponse>;
17
17
  me(params?: {
18
18
  channelUid?: string;
19
+ channelSlug?: string;
19
20
  }): Promise<UserDto>;
20
21
  refresh(refreshToken: string): Promise<{
21
22
  accessToken: string;
22
23
  refreshToken: string;
23
24
  }>;
25
+ loginAnonymous(data: AnonymousLoginRequest): Promise<AuthResponse>;
26
+ upgradeAnonymous(data: {
27
+ email: string;
28
+ password: string;
29
+ display_name?: string;
30
+ username?: string;
31
+ }): Promise<UserDto>;
24
32
  logout(): Promise<void>;
25
33
  }
@@ -53,6 +53,20 @@ class AuthModule {
53
53
  async refresh(refreshToken) {
54
54
  return this.client.post('/api/auth/refresh', { refreshToken });
55
55
  }
56
+ async loginAnonymous(data) {
57
+ const validation = api_contract_1.AnonymousLoginSchema.safeParse(data);
58
+ if (!validation.success) {
59
+ throw new errors_1.ValidationError("Invalid anonymous login data", validation.error.errors);
60
+ }
61
+ const response = await this.client.post('/api/auth/anonymous', data);
62
+ if (this.provider) {
63
+ this.provider.setTokens(response.accessToken, response.refreshToken);
64
+ }
65
+ return response;
66
+ }
67
+ async upgradeAnonymous(data) {
68
+ return this.client.post('/api/auth/anonymous/upgrade', data);
69
+ }
56
70
  async logout() {
57
71
  if (this.provider) {
58
72
  await this.provider.logout();
@@ -1,12 +1,10 @@
1
- import { ChannelDto, CheckHierarchyQuery, CreateChannelDto, ListChannelQuery, PagedChannelListResponse } from "@ph-cms/api-contract";
1
+ import { ChannelDto, CheckHierarchyQuery } from "@ph-cms/api-contract";
2
2
  import { AxiosInstance } from "axios";
3
3
  export declare class ChannelModule {
4
4
  private client;
5
5
  constructor(client: AxiosInstance);
6
- list(params: ListChannelQuery): Promise<PagedChannelListResponse>;
7
6
  getByUid(uid: string): Promise<ChannelDto>;
8
7
  getBySlug(slug: string): Promise<ChannelDto>;
9
- create(data: CreateChannelDto): Promise<ChannelDto>;
10
8
  update(uid: string, data: any): Promise<ChannelDto>;
11
9
  checkHierarchy(params: CheckHierarchyQuery): Promise<{
12
10
  allowed: boolean;
@@ -7,13 +7,6 @@ class ChannelModule {
7
7
  constructor(client) {
8
8
  this.client = client;
9
9
  }
10
- async list(params) {
11
- const validation = api_contract_1.ListChannelQuerySchema.safeParse(params);
12
- if (!validation.success) {
13
- throw new errors_1.ValidationError("Invalid list channel params", validation.error.errors);
14
- }
15
- return this.client.get('/api/channels', { params });
16
- }
17
10
  async getByUid(uid) {
18
11
  if (!uid)
19
12
  throw new errors_1.ValidationError("UID is required", []);
@@ -24,13 +17,6 @@ class ChannelModule {
24
17
  throw new errors_1.ValidationError("Slug is required", []);
25
18
  return this.client.get(`/api/channels/s/${slug}`);
26
19
  }
27
- async create(data) {
28
- const validation = api_contract_1.CreateChannelSchema.safeParse(data);
29
- if (!validation.success) {
30
- throw new errors_1.ValidationError("Invalid create channel params", validation.error.errors);
31
- }
32
- return this.client.post('/api/channels', data);
33
- }
34
20
  async update(uid, data) {
35
21
  // TODO: Add schema validation for update channel
36
22
  if (!uid)
@@ -1,10 +1,9 @@
1
- import { BoundsQuery, CollectStampRequest, ContentDto, CreateContentRequest, CreateStampTourRequest, LikeStatusResponse, ListContentQuery, PagedContentListResponse, StampStatusDto, ToggleLikeResponse, TourStatsDto, UpdateContentRequest, UpdateStampTourRequest } from "@ph-cms/api-contract";
1
+ import { CollectStampRequest, ContentDto, CreateContentRequest, CreateStampTourRequest, LikeStatusResponse, ListContentQuery, PagedContentListResponse, StampStatusDto, ToggleLikeResponse, TourStatsDto, UpdateContentRequest, UpdateStampTourRequest } from "@ph-cms/api-contract";
2
2
  import { AxiosInstance } from "axios";
3
3
  export declare class ContentModule {
4
4
  private client;
5
5
  constructor(client: AxiosInstance);
6
6
  list(params: ListContentQuery): Promise<PagedContentListResponse>;
7
- listGeo(bounds: BoundsQuery): Promise<ContentDto[]>;
8
7
  get(uid: string): Promise<ContentDto>;
9
8
  incrementView(uid: string): Promise<void>;
10
9
  create(data: CreateContentRequest): Promise<ContentDto>;
@@ -14,13 +14,6 @@ class ContentModule {
14
14
  }
15
15
  return this.client.get('/api/contents', { params });
16
16
  }
17
- async listGeo(bounds) {
18
- const validation = api_contract_1.BoundsQuerySchema.safeParse(bounds);
19
- if (!validation.success) {
20
- throw new errors_1.ValidationError("Invalid bounds params", validation.error.errors);
21
- }
22
- return this.client.get('/api/contents/geo', { params: bounds });
23
- }
24
17
  async get(uid) {
25
18
  if (!uid)
26
19
  throw new errors_1.ValidationError("UID is required", []);
@@ -1,9 +1,8 @@
1
1
  import { AxiosInstance } from "axios";
2
- import { TermDto, ListTermsQuery, PagedTermListResponse } from "@ph-cms/api-contract";
2
+ import { TermDto } from "@ph-cms/api-contract";
3
3
  export declare class TermsModule {
4
4
  private client;
5
5
  constructor(client: AxiosInstance);
6
- list(params?: ListTermsQuery): Promise<PagedTermListResponse>;
7
6
  get(id: number): Promise<TermDto>;
8
7
  agree(data: {
9
8
  termCodes: string[];
@@ -5,9 +5,6 @@ class TermsModule {
5
5
  constructor(client) {
6
6
  this.client = client;
7
7
  }
8
- async list(params) {
9
- return this.client.get('/api/terms', { params });
10
- }
11
8
  async get(id) {
12
9
  return this.client.get(`/api/terms/${id}`);
13
10
  }
package/dist/types.d.ts CHANGED
@@ -6,11 +6,11 @@ export type { FirebaseAuthSyncProps, UseFirebaseAuthSyncOptions, UseFirebaseAuth
6
6
  export type { StampAvailability, CheckStampAvailabilityParams } from './hooks/useStampTour';
7
7
  export type { AuthResponse, FirebaseExchangeRequest, LoginRequest, RefreshTokenRequest, RegisterRequest } from '@ph-cms/api-contract';
8
8
  export type { UserDto } from '@ph-cms/api-contract';
9
- export type { ChannelDto, CheckHierarchyQuery, CreateChannelDto, ListChannelQuery, PagedChannelListResponse } from '@ph-cms/api-contract';
9
+ export type { ChannelDto, CheckHierarchyQuery } from '@ph-cms/api-contract';
10
10
  export type { ContentDto, ContentMediaDto, CreateContentRequest, ListContentQuery, PagedContentListResponse, UpdateContentRequest } from '@ph-cms/api-contract';
11
11
  export type { HierarchySetDto } from '@ph-cms/api-contract';
12
12
  export type { PermissionPolicySetDto } from '@ph-cms/api-contract';
13
- export type { ListTermsQuery, PagedTermListResponse, TermDto } from '@ph-cms/api-contract';
14
- export type { BoundsQuery, GeoJSON } from '@ph-cms/api-contract';
13
+ export type { TermDto } from '@ph-cms/api-contract';
14
+ export type { GeoJSON } from '@ph-cms/api-contract';
15
15
  export type { MediaUploadTicketBatchRequest, MediaUploadTicketBatchResponse, MediaUploadTicketRequest, MediaUploadTicketResponse } from '@ph-cms/api-contract';
16
16
  export type { PagedResponse } from '@ph-cms/api-contract';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ph-cms/client-sdk",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "Unified PH-CMS Client SDK (React + Core)",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -21,7 +21,7 @@
21
21
  "LICENSE"
22
22
  ],
23
23
  "dependencies": {
24
- "@ph-cms/api-contract": "^0.1.3",
24
+ "@ph-cms/api-contract": "^0.1.6",
25
25
  "@tanstack/react-query": "^5.0.0",
26
26
  "axios": "^1.6.0",
27
27
  "zod": "^3.22.4"
@@ -1,65 +0,0 @@
1
- import { ListChannelQuery } from '@ph-cms/api-contract';
2
- export declare const channelKeys: {
3
- all: readonly ["channels"];
4
- lists: () => readonly ["channels", "list"];
5
- list: (params: ListChannelQuery) => readonly ["channels", "list", {
6
- status?: string | undefined;
7
- limit?: number | undefined;
8
- offset?: number | undefined;
9
- ownerUid?: string | undefined;
10
- }];
11
- };
12
- export declare const useChannelList: (params: ListChannelQuery) => import("@tanstack/react-query").UseQueryResult<{
13
- items: {
14
- status: string;
15
- uid: string;
16
- created_at: string;
17
- updated_at: string;
18
- name: string;
19
- description: string | null;
20
- slug: string;
21
- hierarchySet: {
22
- uid: string;
23
- created_at: string;
24
- updated_at: string;
25
- name: string;
26
- description: string | null;
27
- } | null;
28
- permissionPolicySet: {
29
- uid: string;
30
- name: string;
31
- description: string | null;
32
- } | null;
33
- }[];
34
- total: number;
35
- page: number;
36
- limit: number;
37
- totalPages: number;
38
- }, Error>;
39
- export declare const useCreateChannel: () => import("@tanstack/react-query").UseMutationResult<{
40
- status: string;
41
- uid: string;
42
- created_at: string;
43
- updated_at: string;
44
- name: string;
45
- description: string | null;
46
- slug: string;
47
- hierarchySet: {
48
- uid: string;
49
- created_at: string;
50
- updated_at: string;
51
- name: string;
52
- description: string | null;
53
- } | null;
54
- permissionPolicySet: {
55
- uid: string;
56
- name: string;
57
- description: string | null;
58
- } | null;
59
- }, Error, {
60
- name: string;
61
- slug: string;
62
- hierarchySetUid: string;
63
- description?: string | undefined;
64
- permissionPolicySetUid?: string | undefined;
65
- }, unknown>;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useCreateChannel = exports.useChannelList = exports.channelKeys = void 0;
4
- const react_query_1 = require("@tanstack/react-query");
5
- const context_1 = require("../context");
6
- exports.channelKeys = {
7
- all: ['channels'],
8
- lists: () => [...exports.channelKeys.all, 'list'],
9
- list: (params) => [...exports.channelKeys.lists(), params],
10
- };
11
- const useChannelList = (params) => {
12
- const client = (0, context_1.usePHCMS)();
13
- return (0, react_query_1.useQuery)({
14
- queryKey: exports.channelKeys.list(params),
15
- queryFn: () => client.channel.list(params),
16
- staleTime: 1000 * 60 * 5, // 5 minutes
17
- });
18
- };
19
- exports.useChannelList = useChannelList;
20
- const useCreateChannel = () => {
21
- const client = (0, context_1.usePHCMS)();
22
- const queryClient = (0, react_query_1.useQueryClient)();
23
- return (0, react_query_1.useMutation)({
24
- mutationFn: (data) => client.channel.create(data),
25
- onSuccess: () => {
26
- queryClient.invalidateQueries({ queryKey: exports.channelKeys.lists() });
27
- },
28
- });
29
- };
30
- exports.useCreateChannel = useCreateChannel;
@@ -1,39 +0,0 @@
1
- import { ListTermsQuery } from '@ph-cms/api-contract';
2
- export declare const termsKeys: {
3
- all: readonly ["terms"];
4
- lists: () => readonly ["terms", "list"];
5
- list: (params?: ListTermsQuery) => readonly ["terms", "list", {
6
- code?: string | undefined;
7
- limit?: number | undefined;
8
- isActive?: boolean | undefined;
9
- offset?: number | undefined;
10
- } | undefined];
11
- };
12
- export declare const useTermsList: (params?: ListTermsQuery) => import("@tanstack/react-query").UseQueryResult<{
13
- items: {
14
- code: string;
15
- id: number;
16
- version: string;
17
- title: string;
18
- content: string;
19
- isActive: boolean;
20
- createdAt: string;
21
- }[];
22
- total: number;
23
- page: number;
24
- limit: number;
25
- totalPages: number;
26
- }, Error>;
27
- export declare const useChannelTerms: (channelUid: string) => import("@tanstack/react-query").UseQueryResult<{
28
- code: string;
29
- id: number;
30
- version: string;
31
- title: string;
32
- content: string;
33
- isActive: boolean;
34
- createdAt: string;
35
- }[], Error>;
36
- export declare const useAgreeTerms: () => import("@tanstack/react-query").UseMutationResult<void, Error, {
37
- termCodes: string[];
38
- channelUid?: string;
39
- }, unknown>;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useAgreeTerms = exports.useChannelTerms = exports.useTermsList = exports.termsKeys = void 0;
4
- const react_query_1 = require("@tanstack/react-query");
5
- const context_1 = require("../context");
6
- exports.termsKeys = {
7
- all: ['terms'],
8
- lists: () => [...exports.termsKeys.all, 'list'],
9
- list: (params) => [...exports.termsKeys.lists(), params],
10
- };
11
- const useTermsList = (params) => {
12
- const client = (0, context_1.usePHCMS)();
13
- return (0, react_query_1.useQuery)({
14
- queryKey: exports.termsKeys.list(params),
15
- queryFn: () => client.terms.list(params),
16
- staleTime: 1000 * 60 * 60, // 1 hour
17
- });
18
- };
19
- exports.useTermsList = useTermsList;
20
- const useChannelTerms = (channelUid) => {
21
- const client = (0, context_1.usePHCMS)();
22
- return (0, react_query_1.useQuery)({
23
- queryKey: [...exports.termsKeys.all, 'channel', channelUid],
24
- queryFn: () => client.terms.listByChannel(channelUid),
25
- enabled: !!channelUid,
26
- });
27
- };
28
- exports.useChannelTerms = useChannelTerms;
29
- const useAgreeTerms = () => {
30
- const client = (0, context_1.usePHCMS)();
31
- return (0, react_query_1.useMutation)({
32
- mutationFn: (data) => client.terms.agree(data),
33
- });
34
- };
35
- exports.useAgreeTerms = useAgreeTerms;