@ph-cms/client-sdk 0.1.3 → 0.1.4

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 (2) hide show
  1. package/README.md +38 -84
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -8,6 +8,7 @@ This package provides:
8
8
  - Auth provider interfaces and implementations
9
9
  - React context and hooks for consuming the client in UI code
10
10
  - **Integrated React Query support** (from v0.1.1)
11
+ - **Automatic Auth State Management** (from v0.1.3)
11
12
 
12
13
  ## Installation
13
14
 
@@ -15,46 +16,21 @@ This package provides:
15
16
  npm install @ph-cms/client-sdk
16
17
  ```
17
18
 
18
- > **Note:** `@tanstack/react-query` is a direct dependency from v0.1.1. You no longer need to install it manually unless you use it in your own application code.
19
+ > **Note:** `@tanstack/react-query` is a direct dependency. You no longer need to install it manually unless you use it in your own application code.
19
20
 
20
- If you use the React bindings, ensure you have `react` installed:
21
+ ## React Usage
21
22
 
22
- ```bash
23
- npm install react react-dom
24
- ```
25
-
26
- If you use Firebase auth integration:
23
+ `PHCMSProvider` automatically includes a `QueryClientProvider` and manages the global authentication state.
27
24
 
28
- ```bash
29
- npm install firebase
30
- ```
31
-
32
- ## Usage (Core SDK)
25
+ ### Basic Setup
33
26
 
34
- ```ts
35
- import { PHCMSClient } from '@ph-cms/client-sdk';
27
+ ```tsx
28
+ import { PHCMSClient, PHCMSProvider } from '@ph-cms/client-sdk';
36
29
 
37
30
  const client = new PHCMSClient({
38
31
  baseURL: 'https://api.example.com',
39
32
  });
40
33
 
41
- // Use the modules directly
42
- const contents = await client.content.list({
43
- page: 1,
44
- limit: 20,
45
- });
46
- ```
47
-
48
- ## React Usage (v0.1.1+)
49
-
50
- From version 0.1.1, `PHCMSProvider` automatically includes a `QueryClientProvider`. You don't need to wrap your app with `QueryClientProvider` manually to use PH-CMS hooks.
51
-
52
- ### Basic Setup
53
-
54
- ```tsx
55
- import { PHCMSClient, PHCMSProvider } from '@ph-cms/client-sdk';
56
- import { client } from './lib/sdk'; // Your pre-configured client
57
-
58
34
  export function App() {
59
35
  return (
60
36
  <PHCMSProvider client={client}>
@@ -64,73 +40,62 @@ export function App() {
64
40
  }
65
41
  ```
66
42
 
67
- ### Using Hooks
43
+ ### Authentication State (`useAuth`)
44
+
45
+ From v0.1.3, the `useAuth` hook provides a unified interface for both authentication state and actions.
68
46
 
69
47
  ```tsx
70
- import { useContent, useUser } from '@ph-cms/client-sdk';
48
+ import { useAuth } from '@ph-cms/client-sdk';
49
+
50
+ function ProfileComponent() {
51
+ const {
52
+ user,
53
+ isAuthenticated,
54
+ isLoading,
55
+ login,
56
+ logout
57
+ } = useAuth();
71
58
 
72
- function MyComponent() {
73
- const { data: user, isLoading: userLoading } = useUser();
74
- const { data: contents, isLoading: contentLoading } = useContent();
59
+ if (isLoading) return <div>Checking auth...</div>;
75
60
 
76
- if (userLoading || contentLoading) return <div>Loading...</div>;
61
+ if (!isAuthenticated) {
62
+ return <button onClick={() => login({ email: '...', password: '...' })}>Login</button>;
63
+ }
77
64
 
78
65
  return (
79
66
  <div>
80
- <h1>Hello, {user?.email}</h1>
81
- <ul>
82
- {contents?.items.map(item => (
83
- <li key={item.uid}>{item.title}</li>
84
- ))}
85
- </ul>
67
+ <h1>Welcome, {user?.display_name}</h1>
68
+ <button onClick={() => logout()}>Logout</button>
86
69
  </div>
87
70
  );
88
71
  }
89
72
  ```
90
73
 
91
- ### Custom QueryClient (Optional)
92
-
93
- If your application already uses React Query and you want to share the cache/settings:
74
+ ### Using Data Hooks
94
75
 
95
76
  ```tsx
96
- import { QueryClient } from '@tanstack/react-query';
97
- import { PHCMSClient, PHCMSProvider } from '@ph-cms/client-sdk';
98
-
99
- const queryClient = new QueryClient();
100
- const client = new PHCMSClient({ baseURL: '...' });
101
-
102
- export function App() {
103
- return (
104
- <PHCMSProvider client={client} queryClient={queryClient}>
105
- {/* Both your app and PH-CMS hooks will use the same queryClient */}
106
- <YourComponents />
107
- </PHCMSProvider>
108
- );
109
- }
110
- ```
77
+ import { useContentList, useContentDetail } from '@ph-cms/client-sdk';
111
78
 
112
- ## Admin SDK (@ph-cms/client-sdk-admin)
79
+ function ContentList() {
80
+ const { data, isLoading } = useContentList({ limit: 10 });
113
81
 
114
- For administrative tasks, use `@ph-cms/client-sdk-admin`. It follows the same provider pattern:
82
+ if (isLoading) return <div>Loading...</div>;
115
83
 
116
- ```tsx
117
- import { PHCMSAdminProvider } from '@ph-cms/client-sdk-admin';
118
- import { adminClient } from './lib/sdk';
119
-
120
- export function App() {
121
84
  return (
122
- <PHCMSAdminProvider client={adminClient}>
123
- <AdminComponents />
124
- </PHCMSAdminProvider>
85
+ <ul>
86
+ {data?.content.map(item => (
87
+ <li key={item.uid}>{item.title}</li>
88
+ ))}
89
+ </ul>
125
90
  );
126
91
  }
127
92
  ```
128
93
 
129
- ## Media & File Upload (v0.1.2+)
94
+ ## Media & File Upload
130
95
 
131
96
  Uploading media files follows a 3-step process: Request a Ticket -> Upload to S3 -> Create/Update Content.
132
97
 
133
- ### 1. Simple Workflow Example
98
+ ### Simple Workflow Example
134
99
 
135
100
  ```tsx
136
101
  import { useMediaUploadTickets, useUploadToS3, useCreateContent } from '@ph-cms/client-sdk';
@@ -149,8 +114,6 @@ function MediaUploader() {
149
114
  filename: file.name,
150
115
  contentType: file.type,
151
116
  fileSize: file.size,
152
- // width: 1024, (optional)
153
- // height: 768 (optional)
154
117
  }]);
155
118
 
156
119
  const { mediaUid, uploadUrl } = tickets[0];
@@ -160,7 +123,6 @@ function MediaUploader() {
160
123
 
161
124
  // Step 3: Use the mediaUid to create content
162
125
  await createContent({
163
- channelSlug: 'my-channel',
164
126
  type: 'post',
165
127
  title: 'Post with image',
166
128
  mediaAttachments: [mediaUid]
@@ -171,14 +133,6 @@ function MediaUploader() {
171
133
  }
172
134
  ```
173
135
 
174
- ### 2. Supported Media Types
175
- The system automatically classifies media based on the `contentType`:
176
- - `image/*` -> `image`
177
- - `video/*` -> `video`
178
- - `audio/*` -> `audio`
179
- - `application/pdf`, `.docx`, etc. -> `document`
180
- - Others -> `file`
181
-
182
136
  ## License
183
137
 
184
138
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ph-cms/client-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Unified PH-CMS Client SDK (React + Core)",
5
5
  "keywords": [],
6
6
  "license": "MIT",