@ph-cms/client-sdk 0.1.1 → 0.1.2

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
@@ -2,24 +2,25 @@
2
2
 
3
3
  Unified PH-CMS client SDK for browser and React applications.
4
4
 
5
- This package is intended to be published to npm and provides:
5
+ This package provides:
6
6
 
7
7
  - A typed API client
8
8
  - Auth provider interfaces and implementations
9
9
  - React context and hooks for consuming the client in UI code
10
+ - **Integrated React Query support** (from v0.1.1)
10
11
 
11
12
  ## Installation
12
13
 
13
- Install the SDK itself with its runtime dependencies:
14
-
15
14
  ```bash
16
- npm install @ph-cms/client-sdk @ph-cms/api-contract axios zod
15
+ npm install @ph-cms/client-sdk
17
16
  ```
18
17
 
19
- If you use the React bindings, also install the peer dependencies:
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
+
20
+ If you use the React bindings, ensure you have `react` installed:
20
21
 
21
22
  ```bash
22
- npm install react @tanstack/react-query
23
+ npm install react react-dom
23
24
  ```
24
25
 
25
26
  If you use Firebase auth integration:
@@ -28,7 +29,7 @@ If you use Firebase auth integration:
28
29
  npm install firebase
29
30
  ```
30
31
 
31
- ## Usage
32
+ ## Usage (Core SDK)
32
33
 
33
34
  ```ts
34
35
  import { PHCMSClient } from '@ph-cms/client-sdk';
@@ -37,36 +38,94 @@ const client = new PHCMSClient({
37
38
  baseURL: 'https://api.example.com',
38
39
  });
39
40
 
41
+ // Use the modules directly
40
42
  const contents = await client.content.list({
41
43
  page: 1,
42
44
  limit: 20,
43
45
  });
44
46
  ```
45
47
 
46
- ## React Usage
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.
47
51
 
48
- `react` and `@tanstack/react-query` are peer dependencies, so your application must provide them.
52
+ ### Basic Setup
49
53
 
50
54
  ```tsx
51
- import { PHCMSClient, PHCMSProvider, usePHCMS } from '@ph-cms/client-sdk';
55
+ import { PHCMSClient, PHCMSProvider } from '@ph-cms/client-sdk';
56
+ import { client } from './lib/sdk'; // Your pre-configured client
52
57
 
53
- const client = new PHCMSClient({ baseURL: 'https://api.example.com' });
58
+ export function App() {
59
+ return (
60
+ <PHCMSProvider client={client}>
61
+ <YourComponents />
62
+ </PHCMSProvider>
63
+ );
64
+ }
65
+ ```
66
+
67
+ ### Using Hooks
68
+
69
+ ```tsx
70
+ import { useContent, useUser } from '@ph-cms/client-sdk';
54
71
 
55
- function ContentCount() {
56
- const sdk = usePHCMS();
57
- // Use sdk.content / sdk.auth / sdk.channel / sdk.terms here.
58
- return null;
72
+ function MyComponent() {
73
+ const { data: user, isLoading: userLoading } = useUser();
74
+ const { data: contents, isLoading: contentLoading } = useContent();
75
+
76
+ if (userLoading || contentLoading) return <div>Loading...</div>;
77
+
78
+ return (
79
+ <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>
86
+ </div>
87
+ );
59
88
  }
89
+ ```
90
+
91
+ ### Custom QueryClient (Optional)
92
+
93
+ If your application already uses React Query and you want to share the cache/settings:
94
+
95
+ ```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: '...' });
60
101
 
61
102
  export function App() {
62
103
  return (
63
- <PHCMSProvider client={client}>
64
- <ContentCount />
104
+ <PHCMSProvider client={client} queryClient={queryClient}>
105
+ {/* Both your app and PH-CMS hooks will use the same queryClient */}
106
+ <YourComponents />
65
107
  </PHCMSProvider>
66
108
  );
67
109
  }
68
110
  ```
69
111
 
112
+ ## Admin SDK (@ph-cms/client-sdk-admin)
113
+
114
+ For administrative tasks, use `@ph-cms/client-sdk-admin`. It follows the same provider pattern:
115
+
116
+ ```tsx
117
+ import { PHCMSAdminProvider } from '@ph-cms/client-sdk-admin';
118
+ import { adminClient } from './lib/sdk';
119
+
120
+ export function App() {
121
+ return (
122
+ <PHCMSAdminProvider client={adminClient}>
123
+ <AdminComponents />
124
+ </PHCMSAdminProvider>
125
+ );
126
+ }
127
+ ```
128
+
70
129
  ## License
71
130
 
72
131
  MIT
package/dist/client.d.ts CHANGED
@@ -4,6 +4,7 @@ import { AuthModule } from './modules/auth';
4
4
  import { ContentModule } from './modules/content';
5
5
  import { ChannelModule } from './modules/channel';
6
6
  import { TermsModule } from './modules/terms';
7
+ import { MediaModule } from './modules/media';
7
8
  export interface PHCMSClientConfig {
8
9
  baseURL: string;
9
10
  apiPrefix?: string;
@@ -17,5 +18,6 @@ export declare class PHCMSClient {
17
18
  readonly content: ContentModule;
18
19
  readonly channel: ChannelModule;
19
20
  readonly terms: TermsModule;
21
+ readonly media: MediaModule;
20
22
  constructor(config: PHCMSClientConfig);
21
23
  }
package/dist/client.js CHANGED
@@ -10,6 +10,7 @@ const auth_1 = require("./modules/auth");
10
10
  const content_1 = require("./modules/content");
11
11
  const channel_1 = require("./modules/channel");
12
12
  const terms_1 = require("./modules/terms");
13
+ const media_1 = require("./modules/media");
13
14
  class PHCMSClient {
14
15
  constructor(config) {
15
16
  this.config = config;
@@ -69,6 +70,7 @@ class PHCMSClient {
69
70
  this.content = new content_1.ContentModule(this.axiosInstance);
70
71
  this.channel = new channel_1.ChannelModule(this.axiosInstance);
71
72
  this.terms = new terms_1.TermsModule(this.axiosInstance);
73
+ this.media = new media_1.MediaModule(this.axiosInstance);
72
74
  }
73
75
  }
74
76
  exports.PHCMSClient = PHCMSClient;
@@ -0,0 +1,32 @@
1
+ export declare const mediaKeys: {
2
+ all: readonly ["media"];
3
+ details: () => readonly ["media", "detail"];
4
+ detail: (uid: string) => readonly ["media", "detail", string];
5
+ };
6
+ export declare const useMediaUploadTickets: () => import("@tanstack/react-query").UseMutationResult<{
7
+ mediaUid: string;
8
+ uploadUrl: string;
9
+ expiresAt: number;
10
+ }[], Error, {
11
+ filename: string;
12
+ contentType: string;
13
+ fileSize: number;
14
+ width?: number | undefined;
15
+ height?: number | undefined;
16
+ }[], unknown>;
17
+ export declare const useUploadToS3: () => import("@tanstack/react-query").UseMutationResult<void, Error, {
18
+ url: string;
19
+ file: File | Blob;
20
+ }, unknown>;
21
+ export declare const useMediaDetail: (uid: string) => import("@tanstack/react-query").UseQueryResult<{
22
+ uid: string;
23
+ type: "image" | "video" | "audio" | "document" | "file";
24
+ url: string;
25
+ name: string;
26
+ mimeType: string;
27
+ size: number;
28
+ order: number;
29
+ width?: number | undefined;
30
+ height?: number | undefined;
31
+ description?: string | null | undefined;
32
+ }, Error>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMediaDetail = exports.useUploadToS3 = exports.useMediaUploadTickets = exports.mediaKeys = void 0;
4
+ const react_query_1 = require("@tanstack/react-query");
5
+ const context_1 = require("../context");
6
+ exports.mediaKeys = {
7
+ all: ['media'],
8
+ details: () => [...exports.mediaKeys.all, 'detail'],
9
+ detail: (uid) => [...exports.mediaKeys.details(), uid],
10
+ };
11
+ const useMediaUploadTickets = () => {
12
+ const client = (0, context_1.usePHCMS)();
13
+ return (0, react_query_1.useMutation)({
14
+ mutationFn: (data) => client.media.getUploadTickets(data),
15
+ });
16
+ };
17
+ exports.useMediaUploadTickets = useMediaUploadTickets;
18
+ const useUploadToS3 = () => {
19
+ const client = (0, context_1.usePHCMS)();
20
+ return (0, react_query_1.useMutation)({
21
+ mutationFn: ({ url, file }) => client.media.uploadToS3(url, file),
22
+ });
23
+ };
24
+ exports.useUploadToS3 = useUploadToS3;
25
+ const useMediaDetail = (uid) => {
26
+ const client = (0, context_1.usePHCMS)();
27
+ return (0, react_query_1.useQuery)({
28
+ queryKey: exports.mediaKeys.detail(uid),
29
+ queryFn: () => client.media.getMedia(uid),
30
+ enabled: !!uid,
31
+ });
32
+ };
33
+ exports.useMediaDetail = useMediaDetail;
package/dist/index.d.ts CHANGED
@@ -7,9 +7,11 @@ export * from './modules/auth';
7
7
  export * from './modules/content';
8
8
  export * from './modules/channel';
9
9
  export * from './modules/terms';
10
+ export * from './modules/media';
10
11
  export * from './context';
11
12
  export * from './hooks/useAuth';
12
13
  export * from './hooks/useContent';
13
14
  export * from './hooks/useChannel';
14
15
  export * from './hooks/useTerms';
16
+ export * from './hooks/useMedia';
15
17
  export * from './types';
package/dist/index.js CHANGED
@@ -23,9 +23,11 @@ __exportStar(require("./modules/auth"), exports);
23
23
  __exportStar(require("./modules/content"), exports);
24
24
  __exportStar(require("./modules/channel"), exports);
25
25
  __exportStar(require("./modules/terms"), exports);
26
+ __exportStar(require("./modules/media"), exports);
26
27
  __exportStar(require("./context"), exports);
27
28
  __exportStar(require("./hooks/useAuth"), exports);
28
29
  __exportStar(require("./hooks/useContent"), exports);
29
30
  __exportStar(require("./hooks/useChannel"), exports);
30
31
  __exportStar(require("./hooks/useTerms"), exports);
32
+ __exportStar(require("./hooks/useMedia"), exports);
31
33
  __exportStar(require("./types"), exports);
@@ -0,0 +1,20 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { MediaUploadTicketBatchRequest, MediaUploadTicketBatchResponse, ContentMediaDto } from "@ph-cms/api-contract";
3
+ export declare class MediaModule {
4
+ private client;
5
+ constructor(client: AxiosInstance);
6
+ /**
7
+ * 미디어 업로드 티켓(Presigned URL) 발급 요청
8
+ */
9
+ getUploadTickets(data: MediaUploadTicketBatchRequest): Promise<MediaUploadTicketBatchResponse>;
10
+ /**
11
+ * 미디어 상세 정보 조회
12
+ */
13
+ getMedia(uid: string): Promise<ContentMediaDto>;
14
+ /**
15
+ * S3 Presigned URL을 사용하여 파일 직접 업로드
16
+ * @param url getUploadTickets를 통해 발급받은 uploadUrl
17
+ * @param file 업로드할 파일 객체 (File 또는 Blob)
18
+ */
19
+ uploadToS3(url: string, file: File | Blob): Promise<void>;
20
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MediaModule = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const api_contract_1 = require("@ph-cms/api-contract");
9
+ const errors_1 = require("../errors");
10
+ class MediaModule {
11
+ constructor(client) {
12
+ this.client = client;
13
+ }
14
+ /**
15
+ * 미디어 업로드 티켓(Presigned URL) 발급 요청
16
+ */
17
+ async getUploadTickets(data) {
18
+ const validation = api_contract_1.MediaUploadTicketBatchRequestSchema.safeParse(data);
19
+ if (!validation.success) {
20
+ throw new errors_1.ValidationError("Invalid upload ticket request", validation.error.errors);
21
+ }
22
+ return this.client.post('/api/media/upload-tickets', data);
23
+ }
24
+ /**
25
+ * 미디어 상세 정보 조회
26
+ */
27
+ async getMedia(uid) {
28
+ if (!uid)
29
+ throw new errors_1.ValidationError("Media UID is required", []);
30
+ return this.client.get(`/api/media/${uid}`);
31
+ }
32
+ /**
33
+ * S3 Presigned URL을 사용하여 파일 직접 업로드
34
+ * @param url getUploadTickets를 통해 발급받은 uploadUrl
35
+ * @param file 업로드할 파일 객체 (File 또는 Blob)
36
+ */
37
+ async uploadToS3(url, file) {
38
+ if (!url)
39
+ throw new errors_1.ValidationError("Upload URL is required", []);
40
+ // CMS API 전용 interceptor가 없는 순수 axios 인스턴스로 요청
41
+ // S3는 PUT 메서드를 사용하며, 티켓 발급 시 지정한 Content-Type과 일치해야 함
42
+ await axios_1.default.put(url, file, {
43
+ headers: {
44
+ 'Content-Type': file.type,
45
+ },
46
+ });
47
+ }
48
+ }
49
+ exports.MediaModule = MediaModule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ph-cms/client-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
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.0",
24
+ "@ph-cms/api-contract": "^0.1.1",
25
25
  "@tanstack/react-query": "^5.0.0",
26
26
  "axios": "^1.6.0",
27
27
  "zod": "^3.22.4"