@reopt-ai/brandapp-sdk 3.1.0 → 3.4.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.
- package/CHANGELOG.md +147 -0
- package/README.md +39 -14
- package/dist/abort--nOBFN4M.js +50 -0
- package/dist/ai/index.d.ts +2 -314
- package/dist/ai/index.js +3 -7
- package/dist/ai-provider/index.d.ts +79 -163
- package/dist/ai-provider/index.js +752 -671
- package/dist/auth/index.d.ts +27 -27
- package/dist/auth/index.js +41 -33
- package/dist/better-auth/client.d.ts +6 -5
- package/dist/better-auth/client.js +28 -5
- package/dist/better-auth/index.d.ts +19 -17
- package/dist/better-auth/index.js +180 -133
- package/dist/client-B1q5P8rv.js +83 -0
- package/dist/client-B9QHVhdM.js +77 -0
- package/dist/client-BGGd_cpV.d.ts +103 -0
- package/dist/client-BJcy1V1a.js +140 -0
- package/dist/client-Beivhucf.js +55 -0
- package/dist/client-BruP5_nU.d.ts +147 -0
- package/dist/client-D-yNxNfk.js +28 -0
- package/dist/client-D0eBxh8j.d.ts +284 -0
- package/dist/client-D3RHHUUW.d.ts +207 -0
- package/dist/client-D6gs61w8.d.ts +53 -0
- package/dist/client-DBnK7ooQ.js +86 -0
- package/dist/client-DDw5yz_h.d.ts +53 -0
- package/dist/client-DPmoKuR9.js +305 -0
- package/dist/client-DsdakibF.js +503 -0
- package/dist/client-Dxg8_DIH.d.ts +71 -0
- package/dist/client-EbhUIhHq.js +53 -0
- package/dist/client-lk6wBu_0.d.ts +48 -0
- package/dist/client-p49ol9pg.d.ts +124 -0
- package/dist/cms/index.d.ts +52 -108
- package/dist/cms/index.js +105 -84
- package/dist/config-CRytOPPl.d.ts +394 -0
- package/dist/config-Cw0a3-C8.js +487 -0
- package/dist/dev/index.d.ts +2 -509
- package/dist/dev/index.js +2740 -2873
- package/dist/eav/coerce.d.ts +3 -1
- package/dist/eav/coerce.js +72 -46
- package/dist/eav/index.d.ts +72 -100
- package/dist/eav/index.js +158 -125
- package/dist/eav/migrate.d.ts +112 -109
- package/dist/eav/migrate.js +230 -196
- package/dist/eav/schema.d.ts +111 -150
- package/dist/eav/schema.js +624 -603
- package/dist/encoding-Bwfm3iaE.js +21 -0
- package/dist/{errors-DIAS8Rsl.d.ts → errors-CRCcErNC.d.ts} +55 -53
- package/dist/feedback/index.d.ts +2 -132
- package/dist/feedback/index.js +3 -5
- package/dist/files/index.d.ts +14 -14
- package/dist/files/index.js +41 -24
- package/dist/http-client-QKUvvirs.js +386 -0
- package/dist/index-DrVaKfhs.d.ts +456 -0
- package/dist/index-Z6OGcurJ.d.ts +169 -0
- package/dist/index.d.ts +6 -221
- package/dist/index.js +119 -70
- package/dist/logout/index.d.ts +109 -0
- package/dist/logout/index.js +264 -0
- package/dist/plans/index.d.ts +2 -236
- package/dist/plans/index.js +3 -5
- package/dist/push/index.d.ts +2 -79
- package/dist/push/index.js +3 -5
- package/dist/query-BvbCiGWb.js +35 -0
- package/dist/react/hooks.d.ts +97 -95
- package/dist/react/hooks.js +742 -356
- package/dist/sse-parser-FMjxM7sY.js +86 -0
- package/dist/terms/index.d.ts +3 -79
- package/dist/terms/index.js +3 -5
- package/dist/testing/index.d.ts +52 -104
- package/dist/testing/index.js +94 -72
- package/dist/types-B-SMkH6s.d.ts +26 -0
- package/dist/types-BXDcoJHG.d.ts +131 -0
- package/dist/types-BrghN2rJ.d.ts +105 -0
- package/dist/types-DjDRszNj.js +11 -0
- package/dist/webhooks/index.d.ts +77 -47
- package/dist/webhooks/index.js +150 -127
- package/docs/api-reference.md +179 -2
- package/docs/dev-server.md +19 -18
- package/docs/errors.md +72 -15
- package/docs/logout.md +166 -0
- package/package.json +10 -5
- package/dist/chunk-2Q654O63.js +0 -350
- package/dist/chunk-F7BXBTZI.js +0 -54
- package/dist/chunk-IJOXTBIE.js +0 -599
- package/dist/chunk-JWXUVQRC.js +0 -157
- package/dist/chunk-L4DHB36G.js +0 -75
- package/dist/chunk-MRQY45U5.js +0 -465
- package/dist/chunk-N5JVE4WX.js +0 -449
- package/dist/chunk-O3PUWIDJ.js +0 -105
- package/dist/chunk-POLKEOYH.js +0 -63
- package/dist/chunk-R5CCGDUH.js +0 -49
- package/dist/chunk-RBHP7IZF.js +0 -96
- package/dist/chunk-REIKXSMY.js +0 -7
- package/dist/chunk-T7YTITRJ.js +0 -112
- package/dist/chunk-V73GORO3.js +0 -81
- package/dist/chunk-VRNBYSWU.js +0 -32
- package/dist/client-BkcO-0C2.d.ts +0 -216
- package/dist/client-CN5_tNOC.d.ts +0 -147
- package/dist/client-DttyeM_h.d.ts +0 -102
- package/dist/config-CtxyJsDR.d.ts +0 -397
- package/dist/typed-client-BxOVIiMU.d.ts +0 -40
- package/dist/types-6E3ZLL9X.d.ts +0 -24
- package/dist/types-DskYLVb8.d.ts +0 -104
- package/dist/types-ckmDDW3N.d.ts +0 -129
package/dist/react/hooks.js
CHANGED
|
@@ -1,421 +1,807 @@
|
|
|
1
|
-
|
|
2
|
-
import { useQuery, useInfiniteQuery, useQueryClient, useMutation } from '@tanstack/react-query';
|
|
1
|
+
"use client";
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
5
|
+
|
|
6
|
+
//#region src/react/use-ai-stream.ts
|
|
7
|
+
/**
|
|
8
|
+
* React hook for AI text streaming via BrandApp SDK.
|
|
9
|
+
*
|
|
10
|
+
* Uses `sdk.ai.streamWithMetadata()` internally to provide
|
|
11
|
+
* incremental text accumulation, abort support, and usage metadata.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* const { text, isStreaming, generate, stop } = useAiStream(sdk);
|
|
16
|
+
*
|
|
17
|
+
* return (
|
|
18
|
+
* <div>
|
|
19
|
+
* <button onClick={() => generate({ messages: [{ role: "user", content: "Hello" }] })}>
|
|
20
|
+
* Generate
|
|
21
|
+
* </button>
|
|
22
|
+
* <button onClick={stop} disabled={!isStreaming}>Stop</button>
|
|
23
|
+
* <p>{text}</p>
|
|
24
|
+
* </div>
|
|
25
|
+
* );
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
const hasRaf = typeof requestAnimationFrame === "function";
|
|
5
29
|
function useAiStream(sdk, options) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
30
|
+
const [text, setText] = useState("");
|
|
31
|
+
const [isStreaming, setIsStreaming] = useState(false);
|
|
32
|
+
const [error, setError] = useState(null);
|
|
33
|
+
const [metadata, setMetadata] = useState(null);
|
|
34
|
+
const controllerRef = useRef(null);
|
|
35
|
+
const optionsRef = useRef(options);
|
|
36
|
+
const pendingTextRef = useRef("");
|
|
37
|
+
const rafRef = useRef(null);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
optionsRef.current = options;
|
|
40
|
+
}, [options]);
|
|
41
|
+
const cancelTextFlush = useCallback(() => {
|
|
42
|
+
if (rafRef.current !== null) {
|
|
43
|
+
cancelAnimationFrame(rafRef.current);
|
|
44
|
+
rafRef.current = null;
|
|
45
|
+
}
|
|
46
|
+
}, []);
|
|
47
|
+
const commitText = useCallback(() => {
|
|
48
|
+
cancelTextFlush();
|
|
49
|
+
setText(pendingTextRef.current);
|
|
50
|
+
}, [cancelTextFlush]);
|
|
51
|
+
const scheduleTextFlush = useCallback(() => {
|
|
52
|
+
if (!hasRaf) {
|
|
53
|
+
setText(pendingTextRef.current);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (rafRef.current !== null) return;
|
|
57
|
+
rafRef.current = requestAnimationFrame(() => {
|
|
58
|
+
rafRef.current = null;
|
|
59
|
+
setText(pendingTextRef.current);
|
|
60
|
+
});
|
|
61
|
+
}, []);
|
|
62
|
+
const stop = useCallback(() => {
|
|
63
|
+
cancelTextFlush();
|
|
64
|
+
controllerRef.current?.abort();
|
|
65
|
+
controllerRef.current = null;
|
|
66
|
+
}, [cancelTextFlush]);
|
|
67
|
+
const reset = useCallback(() => {
|
|
68
|
+
stop();
|
|
69
|
+
pendingTextRef.current = "";
|
|
70
|
+
setText("");
|
|
71
|
+
setError(null);
|
|
72
|
+
setMetadata(null);
|
|
73
|
+
setIsStreaming(false);
|
|
74
|
+
}, [stop]);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
return () => {
|
|
77
|
+
cancelTextFlush();
|
|
78
|
+
controllerRef.current?.abort();
|
|
79
|
+
controllerRef.current = null;
|
|
80
|
+
};
|
|
81
|
+
}, [cancelTextFlush]);
|
|
82
|
+
return {
|
|
83
|
+
text,
|
|
84
|
+
isStreaming,
|
|
85
|
+
error,
|
|
86
|
+
metadata,
|
|
87
|
+
generate: useCallback((completionOptions) => {
|
|
88
|
+
stop();
|
|
89
|
+
const controller = new AbortController();
|
|
90
|
+
controllerRef.current = controller;
|
|
91
|
+
pendingTextRef.current = "";
|
|
92
|
+
setText("");
|
|
93
|
+
setError(null);
|
|
94
|
+
setMetadata(null);
|
|
95
|
+
setIsStreaming(true);
|
|
96
|
+
const { textStream, metadata: metaPromise } = sdk.ai.streamWithMetadata({
|
|
97
|
+
...completionOptions,
|
|
98
|
+
signal: controller.signal
|
|
99
|
+
});
|
|
100
|
+
(async () => {
|
|
101
|
+
try {
|
|
102
|
+
let accumulated = "";
|
|
103
|
+
for await (const chunk of textStream) {
|
|
104
|
+
if (controller.signal.aborted) break;
|
|
105
|
+
accumulated += chunk;
|
|
106
|
+
pendingTextRef.current = accumulated;
|
|
107
|
+
scheduleTextFlush();
|
|
108
|
+
optionsRef.current?.onChunk?.(chunk);
|
|
109
|
+
}
|
|
110
|
+
const meta = await metaPromise;
|
|
111
|
+
if (!controller.signal.aborted) {
|
|
112
|
+
commitText();
|
|
113
|
+
setMetadata(meta);
|
|
114
|
+
optionsRef.current?.onFinish?.(accumulated, meta);
|
|
115
|
+
}
|
|
116
|
+
} catch (err) {
|
|
117
|
+
if (!controller.signal.aborted) {
|
|
118
|
+
commitText();
|
|
119
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
120
|
+
setError(e);
|
|
121
|
+
optionsRef.current?.onError?.(e);
|
|
122
|
+
}
|
|
123
|
+
} finally {
|
|
124
|
+
if (controllerRef.current === controller) {
|
|
125
|
+
setIsStreaming(false);
|
|
126
|
+
controllerRef.current = null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
})();
|
|
130
|
+
}, [
|
|
131
|
+
sdk,
|
|
132
|
+
stop,
|
|
133
|
+
scheduleTextFlush,
|
|
134
|
+
commitText
|
|
135
|
+
]),
|
|
136
|
+
stop,
|
|
137
|
+
reset
|
|
138
|
+
};
|
|
106
139
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/react/hooks.ts
|
|
143
|
+
const keys = {
|
|
144
|
+
all: ["reopt"],
|
|
145
|
+
entities: (brandappId) => [
|
|
146
|
+
...keys.all,
|
|
147
|
+
"entities",
|
|
148
|
+
brandappId
|
|
149
|
+
],
|
|
150
|
+
entity: (entityId) => [
|
|
151
|
+
...keys.all,
|
|
152
|
+
"entity",
|
|
153
|
+
entityId
|
|
154
|
+
],
|
|
155
|
+
records: (entityId, query) => [
|
|
156
|
+
...keys.all,
|
|
157
|
+
"records",
|
|
158
|
+
entityId,
|
|
159
|
+
query
|
|
160
|
+
],
|
|
161
|
+
recordsInfinite: (entityId, query) => [
|
|
162
|
+
...keys.all,
|
|
163
|
+
"recordsInfinite",
|
|
164
|
+
entityId,
|
|
165
|
+
query
|
|
166
|
+
],
|
|
167
|
+
record: (entityId, recordId) => [
|
|
168
|
+
...keys.all,
|
|
169
|
+
"record",
|
|
170
|
+
entityId,
|
|
171
|
+
recordId
|
|
172
|
+
],
|
|
173
|
+
recordCount: (entityId, query) => [
|
|
174
|
+
...keys.all,
|
|
175
|
+
"recordCount",
|
|
176
|
+
entityId,
|
|
177
|
+
query
|
|
178
|
+
],
|
|
179
|
+
recordsPrefix: (entityId) => [
|
|
180
|
+
...keys.all,
|
|
181
|
+
"records",
|
|
182
|
+
entityId
|
|
183
|
+
],
|
|
184
|
+
recordsInfinitePrefix: (entityId) => [
|
|
185
|
+
...keys.all,
|
|
186
|
+
"recordsInfinite",
|
|
187
|
+
entityId
|
|
188
|
+
],
|
|
189
|
+
recordCountPrefix: (entityId) => [
|
|
190
|
+
...keys.all,
|
|
191
|
+
"recordCount",
|
|
192
|
+
entityId
|
|
193
|
+
],
|
|
194
|
+
aiCredits: (brandappId) => [
|
|
195
|
+
...keys.all,
|
|
196
|
+
"ai",
|
|
197
|
+
"credits",
|
|
198
|
+
brandappId
|
|
199
|
+
],
|
|
200
|
+
aiModels: (brandappId) => [
|
|
201
|
+
...keys.all,
|
|
202
|
+
"ai",
|
|
203
|
+
"models",
|
|
204
|
+
brandappId
|
|
205
|
+
],
|
|
206
|
+
aiAgents: (brandappId) => [
|
|
207
|
+
...keys.all,
|
|
208
|
+
"ai",
|
|
209
|
+
"agents",
|
|
210
|
+
brandappId
|
|
211
|
+
],
|
|
212
|
+
posts: (brandappId, query) => [
|
|
213
|
+
...keys.all,
|
|
214
|
+
"posts",
|
|
215
|
+
brandappId,
|
|
216
|
+
query
|
|
217
|
+
],
|
|
218
|
+
post: (postId) => [
|
|
219
|
+
...keys.all,
|
|
220
|
+
"post",
|
|
221
|
+
postId
|
|
222
|
+
],
|
|
223
|
+
postGroups: (brandappId, query) => [
|
|
224
|
+
...keys.all,
|
|
225
|
+
"postGroups",
|
|
226
|
+
brandappId,
|
|
227
|
+
query
|
|
228
|
+
],
|
|
229
|
+
postGroup: (groupId) => [
|
|
230
|
+
...keys.all,
|
|
231
|
+
"postGroup",
|
|
232
|
+
groupId
|
|
233
|
+
],
|
|
234
|
+
tags: (brandappId, query) => [
|
|
235
|
+
...keys.all,
|
|
236
|
+
"tags",
|
|
237
|
+
brandappId,
|
|
238
|
+
query
|
|
239
|
+
],
|
|
240
|
+
files: (brandappId, query) => [
|
|
241
|
+
...keys.all,
|
|
242
|
+
"files",
|
|
243
|
+
brandappId,
|
|
244
|
+
query
|
|
245
|
+
],
|
|
246
|
+
file: (fileId) => [
|
|
247
|
+
...keys.all,
|
|
248
|
+
"file",
|
|
249
|
+
fileId
|
|
250
|
+
]
|
|
124
251
|
};
|
|
252
|
+
/**
|
|
253
|
+
* List every EAV entity defined for the current brandapp, including their
|
|
254
|
+
* attribute metadata. Cached for 5 minutes since the schema rarely changes
|
|
255
|
+
* within a session.
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```tsx
|
|
259
|
+
* function EntityPicker() {
|
|
260
|
+
* const sdk = useContext(SdkContext);
|
|
261
|
+
* const { data: entities, isPending } = useEavEntities(sdk);
|
|
262
|
+
* if (isPending) return <Spinner />;
|
|
263
|
+
* return (
|
|
264
|
+
* <select>
|
|
265
|
+
* {entities?.map((e) => <option key={e.id}>{e.name}</option>)}
|
|
266
|
+
* </select>
|
|
267
|
+
* );
|
|
268
|
+
* }
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
125
271
|
function useEavEntities(sdk, options) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
});
|
|
272
|
+
return useQuery({
|
|
273
|
+
queryKey: keys.entities(sdk.config.brandappId),
|
|
274
|
+
queryFn: () => sdk.eav.entities.list(),
|
|
275
|
+
staleTime: 300 * 1e3,
|
|
276
|
+
...options
|
|
277
|
+
});
|
|
133
278
|
}
|
|
134
279
|
function useEavEntity(sdk, entityId, options) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
280
|
+
return useQuery({
|
|
281
|
+
queryKey: keys.entity(entityId),
|
|
282
|
+
queryFn: () => sdk.eav.entities.get(entityId),
|
|
283
|
+
staleTime: 300 * 1e3,
|
|
284
|
+
enabled: !!entityId,
|
|
285
|
+
...options
|
|
286
|
+
});
|
|
142
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* List records for an entity with optional filters and pagination.
|
|
290
|
+
*
|
|
291
|
+
* The `query` object is part of the cache key, so changing filters will
|
|
292
|
+
* fetch a fresh page rather than reuse a stale one. For cursor-style
|
|
293
|
+
* pagination prefer `useEavRecordsInfinite`.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```tsx
|
|
297
|
+
* import { where } from "@reopt-ai/brandapp-sdk/eav";
|
|
298
|
+
*
|
|
299
|
+
* function ActiveContacts({ entityId }: { entityId: string }) {
|
|
300
|
+
* const sdk = useContext(SdkContext);
|
|
301
|
+
* const { data, isPending } = useEavRecords(sdk, entityId, {
|
|
302
|
+
* filters: [where("status").eq("active")],
|
|
303
|
+
* limit: 50,
|
|
304
|
+
* });
|
|
305
|
+
* if (isPending) return <Spinner />;
|
|
306
|
+
* return <RecordTable records={data?.records ?? []} total={data?.total} />;
|
|
307
|
+
* }
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
143
310
|
function useEavRecords(sdk, entityId, query, options) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
311
|
+
return useQuery({
|
|
312
|
+
queryKey: keys.records(entityId, query),
|
|
313
|
+
queryFn: () => sdk.eav.records.list(entityId, query),
|
|
314
|
+
enabled: !!entityId,
|
|
315
|
+
...options
|
|
316
|
+
});
|
|
150
317
|
}
|
|
151
318
|
function useEavRecordsInfinite(sdk, entityId, query, options) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
319
|
+
return useInfiniteQuery({
|
|
320
|
+
queryKey: keys.recordsInfinite(entityId, query),
|
|
321
|
+
queryFn: ({ pageParam }) => sdk.eav.records.list(entityId, {
|
|
322
|
+
...query,
|
|
323
|
+
page: pageParam
|
|
324
|
+
}),
|
|
325
|
+
initialPageParam: 1,
|
|
326
|
+
getNextPageParam: (lastPage) => lastPage.page < lastPage.totalPages ? lastPage.page + 1 : void 0,
|
|
327
|
+
enabled: !!entityId,
|
|
328
|
+
...options
|
|
329
|
+
});
|
|
160
330
|
}
|
|
161
331
|
function useEavRecord(sdk, entityId, recordId, options) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
332
|
+
return useQuery({
|
|
333
|
+
queryKey: keys.record(entityId, recordId),
|
|
334
|
+
queryFn: () => sdk.eav.records.get(entityId, recordId),
|
|
335
|
+
enabled: !!entityId && !!recordId,
|
|
336
|
+
...options
|
|
337
|
+
});
|
|
168
338
|
}
|
|
169
339
|
function useEavRecordCount(sdk, entityId, query, options) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
340
|
+
return useQuery({
|
|
341
|
+
queryKey: keys.recordCount(entityId, query),
|
|
342
|
+
queryFn: () => sdk.eav.records.count(entityId, query),
|
|
343
|
+
enabled: !!entityId,
|
|
344
|
+
...options
|
|
345
|
+
});
|
|
176
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* Create a single record. Automatically invalidates the records list and
|
|
349
|
+
* count caches for this entity on success.
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ```tsx
|
|
353
|
+
* function NewContactForm({ entityId }: { entityId: string }) {
|
|
354
|
+
* const sdk = useContext(SdkContext);
|
|
355
|
+
* const create = useCreateRecord(sdk, entityId);
|
|
356
|
+
*
|
|
357
|
+
* return (
|
|
358
|
+
* <form
|
|
359
|
+
* onSubmit={async (e) => {
|
|
360
|
+
* e.preventDefault();
|
|
361
|
+
* const data = new FormData(e.currentTarget);
|
|
362
|
+
* await create.mutateAsync({
|
|
363
|
+
* values: {
|
|
364
|
+
* name: data.get("name") as string,
|
|
365
|
+
* email: data.get("email") as string,
|
|
366
|
+
* },
|
|
367
|
+
* });
|
|
368
|
+
* }}
|
|
369
|
+
* >
|
|
370
|
+
* <input name="name" />
|
|
371
|
+
* <input name="email" type="email" />
|
|
372
|
+
* <button disabled={create.isPending}>Save</button>
|
|
373
|
+
* {create.error ? <ErrorBanner error={create.error} /> : null}
|
|
374
|
+
* </form>
|
|
375
|
+
* );
|
|
376
|
+
* }
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
177
379
|
function useCreateRecord(sdk, entityId, options) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
380
|
+
const queryClient = useQueryClient();
|
|
381
|
+
return useMutation({
|
|
382
|
+
mutationFn: (input) => sdk.eav.records.create(entityId, input),
|
|
383
|
+
onSuccess: () => {
|
|
384
|
+
queryClient.invalidateQueries({ queryKey: keys.recordsPrefix(entityId) });
|
|
385
|
+
queryClient.invalidateQueries({ queryKey: keys.recordsInfinitePrefix(entityId) });
|
|
386
|
+
queryClient.invalidateQueries({ queryKey: keys.recordCountPrefix(entityId) });
|
|
387
|
+
},
|
|
388
|
+
...options
|
|
389
|
+
});
|
|
187
390
|
}
|
|
188
391
|
function useUpdateRecord(sdk, entityId, options) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
});
|
|
200
|
-
},
|
|
201
|
-
...options
|
|
202
|
-
});
|
|
392
|
+
const queryClient = useQueryClient();
|
|
393
|
+
return useMutation({
|
|
394
|
+
mutationFn: ({ recordId, input }) => sdk.eav.records.update(entityId, recordId, input),
|
|
395
|
+
onSuccess: (_, variables) => {
|
|
396
|
+
queryClient.invalidateQueries({ queryKey: keys.recordsPrefix(entityId) });
|
|
397
|
+
queryClient.invalidateQueries({ queryKey: keys.recordsInfinitePrefix(entityId) });
|
|
398
|
+
queryClient.invalidateQueries({ queryKey: keys.record(entityId, variables.recordId) });
|
|
399
|
+
},
|
|
400
|
+
...options
|
|
401
|
+
});
|
|
203
402
|
}
|
|
403
|
+
/**
|
|
404
|
+
* Delete a record by id. Pass the recordId directly to `mutateAsync`.
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```tsx
|
|
408
|
+
* const remove = useDeleteRecord(sdk, entityId);
|
|
409
|
+
* <button onClick={() => remove.mutate(record.id)}>Delete</button>
|
|
410
|
+
* ```
|
|
411
|
+
*/
|
|
204
412
|
function useDeleteRecord(sdk, entityId, options) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
413
|
+
const queryClient = useQueryClient();
|
|
414
|
+
return useMutation({
|
|
415
|
+
mutationFn: (recordId) => sdk.eav.records.delete(entityId, recordId),
|
|
416
|
+
onSuccess: () => {
|
|
417
|
+
queryClient.invalidateQueries({ queryKey: keys.recordsPrefix(entityId) });
|
|
418
|
+
queryClient.invalidateQueries({ queryKey: keys.recordsInfinitePrefix(entityId) });
|
|
419
|
+
queryClient.invalidateQueries({ queryKey: keys.recordCountPrefix(entityId) });
|
|
420
|
+
},
|
|
421
|
+
...options
|
|
422
|
+
});
|
|
214
423
|
}
|
|
424
|
+
/**
|
|
425
|
+
* 레코드 upsert mutation. 필터에 매칭되는 레코드가 있으면 업데이트, 없으면 생성.
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```tsx
|
|
429
|
+
* const upsert = useUpsertRecord(sdk, entityId);
|
|
430
|
+
* await upsert.mutateAsync({
|
|
431
|
+
* filters: [{ attributeId: attrs.key, operator: "eq", value: "theme" }],
|
|
432
|
+
* values: { [attrs.key]: "theme", [attrs.value]: "dark" },
|
|
433
|
+
* });
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
215
436
|
function useUpsertRecord(sdk, entityId, options) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
437
|
+
const queryClient = useQueryClient();
|
|
438
|
+
return useMutation({
|
|
439
|
+
mutationFn: (input) => sdk.eav.records.upsert(entityId, input),
|
|
440
|
+
onSuccess: () => {
|
|
441
|
+
queryClient.invalidateQueries({ queryKey: keys.recordsPrefix(entityId) });
|
|
442
|
+
queryClient.invalidateQueries({ queryKey: keys.recordsInfinitePrefix(entityId) });
|
|
443
|
+
queryClient.invalidateQueries({ queryKey: keys.recordCountPrefix(entityId) });
|
|
444
|
+
},
|
|
445
|
+
...options
|
|
446
|
+
});
|
|
225
447
|
}
|
|
448
|
+
/**
|
|
449
|
+
* 최대 100개 레코드를 한 번에 생성하는 mutation.
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* ```tsx
|
|
453
|
+
* const bulkCreate = useBulkCreateRecords(sdk, entityId);
|
|
454
|
+
* await bulkCreate.mutateAsync([
|
|
455
|
+
* { values: { name: "Alice" } },
|
|
456
|
+
* { values: { name: "Bob" } },
|
|
457
|
+
* ]);
|
|
458
|
+
* ```
|
|
459
|
+
*/
|
|
226
460
|
function useBulkCreateRecords(sdk, entityId, options) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
461
|
+
const queryClient = useQueryClient();
|
|
462
|
+
return useMutation({
|
|
463
|
+
mutationFn: (records) => sdk.eav.records.bulkCreate(entityId, records),
|
|
464
|
+
onSuccess: () => {
|
|
465
|
+
queryClient.invalidateQueries({ queryKey: keys.recordsPrefix(entityId) });
|
|
466
|
+
queryClient.invalidateQueries({ queryKey: keys.recordsInfinitePrefix(entityId) });
|
|
467
|
+
queryClient.invalidateQueries({ queryKey: keys.recordCountPrefix(entityId) });
|
|
468
|
+
},
|
|
469
|
+
...options
|
|
470
|
+
});
|
|
236
471
|
}
|
|
472
|
+
/**
|
|
473
|
+
* 최대 100개 레코드를 한 번에 업데이트하는 mutation.
|
|
474
|
+
*/
|
|
237
475
|
function useBulkUpdateRecords(sdk, entityId, options) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
},
|
|
249
|
-
...options
|
|
250
|
-
});
|
|
476
|
+
const queryClient = useQueryClient();
|
|
477
|
+
return useMutation({
|
|
478
|
+
mutationFn: (updates) => sdk.eav.records.bulkUpdate(entityId, updates),
|
|
479
|
+
onSuccess: (_data, variables) => {
|
|
480
|
+
queryClient.invalidateQueries({ queryKey: keys.recordsPrefix(entityId) });
|
|
481
|
+
queryClient.invalidateQueries({ queryKey: keys.recordsInfinitePrefix(entityId) });
|
|
482
|
+
for (const { id } of variables) queryClient.invalidateQueries({ queryKey: keys.record(entityId, id) });
|
|
483
|
+
},
|
|
484
|
+
...options
|
|
485
|
+
});
|
|
251
486
|
}
|
|
487
|
+
/**
|
|
488
|
+
* 최대 100개 레코드를 한 번에 삭제하는 mutation. 삭제된 레코드 수를 반환.
|
|
489
|
+
*/
|
|
252
490
|
function useBulkDeleteRecords(sdk, entityId, options) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
491
|
+
const queryClient = useQueryClient();
|
|
492
|
+
return useMutation({
|
|
493
|
+
mutationFn: (ids) => sdk.eav.records.bulkDelete(entityId, ids),
|
|
494
|
+
onSuccess: () => {
|
|
495
|
+
queryClient.invalidateQueries({ queryKey: keys.recordsPrefix(entityId) });
|
|
496
|
+
queryClient.invalidateQueries({ queryKey: keys.recordsInfinitePrefix(entityId) });
|
|
497
|
+
queryClient.invalidateQueries({ queryKey: keys.recordCountPrefix(entityId) });
|
|
498
|
+
},
|
|
499
|
+
...options
|
|
500
|
+
});
|
|
262
501
|
}
|
|
502
|
+
/**
|
|
503
|
+
* 필터에 매칭되는 모든 레코드를 삭제하는 mutation. 삭제된 수를 반환.
|
|
504
|
+
*/
|
|
263
505
|
function useDeleteRecordsWhere(sdk, entityId, options) {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
506
|
+
const queryClient = useQueryClient();
|
|
507
|
+
return useMutation({
|
|
508
|
+
mutationFn: (input) => sdk.eav.records.deleteWhere(entityId, input),
|
|
509
|
+
onSuccess: () => {
|
|
510
|
+
queryClient.invalidateQueries({ queryKey: keys.recordsPrefix(entityId) });
|
|
511
|
+
queryClient.invalidateQueries({ queryKey: keys.recordsInfinitePrefix(entityId) });
|
|
512
|
+
queryClient.invalidateQueries({ queryKey: keys.recordCountPrefix(entityId) });
|
|
513
|
+
},
|
|
514
|
+
...options
|
|
515
|
+
});
|
|
273
516
|
}
|
|
517
|
+
/**
|
|
518
|
+
* BrandApp AI 크레딧 잔액 조회
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* ```tsx
|
|
522
|
+
* const { data: credits } = useAiCredits(sdk);
|
|
523
|
+
* // credits?.balance, credits?.limit, credits?.status
|
|
524
|
+
* ```
|
|
525
|
+
*/
|
|
274
526
|
function useAiCredits(sdk, options) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
});
|
|
527
|
+
return useQuery({
|
|
528
|
+
queryKey: keys.aiCredits(sdk.config.brandappId),
|
|
529
|
+
queryFn: () => sdk.ai.credits(),
|
|
530
|
+
staleTime: 30 * 1e3,
|
|
531
|
+
...options
|
|
532
|
+
});
|
|
282
533
|
}
|
|
534
|
+
/**
|
|
535
|
+
* BrandApp AI 사용 가능 모델 목록
|
|
536
|
+
*
|
|
537
|
+
* @example
|
|
538
|
+
* ```tsx
|
|
539
|
+
* const { data: models } = useAiModels(sdk);
|
|
540
|
+
* // models?.map(m => m.id)
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
283
543
|
function useAiModels(sdk, options) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
});
|
|
544
|
+
return useQuery({
|
|
545
|
+
queryKey: keys.aiModels(sdk.config.brandappId),
|
|
546
|
+
queryFn: () => sdk.ai.models(),
|
|
547
|
+
staleTime: 300 * 1e3,
|
|
548
|
+
...options
|
|
549
|
+
});
|
|
291
550
|
}
|
|
551
|
+
/**
|
|
552
|
+
* BrandApp에서 사용 가능한 커스텀 에이전트 목록
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
* ```tsx
|
|
556
|
+
* const { data: agents } = useAiAgents(sdk);
|
|
557
|
+
* // agents?.map(a => ({ id: a.id, name: a.name, defaultModel: a.defaultModel }))
|
|
558
|
+
* ```
|
|
559
|
+
*/
|
|
292
560
|
function useAiAgents(sdk, options) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
});
|
|
561
|
+
return useQuery({
|
|
562
|
+
queryKey: keys.aiAgents(sdk.config.brandappId),
|
|
563
|
+
queryFn: () => sdk.ai.agents(),
|
|
564
|
+
staleTime: 300 * 1e3,
|
|
565
|
+
...options
|
|
566
|
+
});
|
|
300
567
|
}
|
|
568
|
+
/**
|
|
569
|
+
* AI 텍스트 생성 (non-streaming) mutation
|
|
570
|
+
*
|
|
571
|
+
* @example
|
|
572
|
+
* ```tsx
|
|
573
|
+
* const completion = useAiCompletion(sdk);
|
|
574
|
+
*
|
|
575
|
+
* const handleSubmit = () => {
|
|
576
|
+
* completion.mutate({
|
|
577
|
+
* messages: [{ role: "user", content: "안녕하세요" }],
|
|
578
|
+
* model: "anthropic/claude-haiku-4.5",
|
|
579
|
+
* });
|
|
580
|
+
* };
|
|
581
|
+
* // completion.data?.message.content
|
|
582
|
+
* ```
|
|
583
|
+
*/
|
|
301
584
|
function useAiCompletion(sdk, options) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
return options?.onSuccess?.(...args);
|
|
312
|
-
}
|
|
313
|
-
});
|
|
585
|
+
const queryClient = useQueryClient();
|
|
586
|
+
return useMutation({
|
|
587
|
+
mutationFn: (input) => sdk.ai.complete(input),
|
|
588
|
+
...options,
|
|
589
|
+
onSuccess: (...args) => {
|
|
590
|
+
queryClient.invalidateQueries({ queryKey: keys.aiCredits(sdk.config.brandappId) });
|
|
591
|
+
return options?.onSuccess?.(...args);
|
|
592
|
+
}
|
|
593
|
+
});
|
|
314
594
|
}
|
|
595
|
+
/**
|
|
596
|
+
* AI 이미지 생성 mutation
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* ```tsx
|
|
600
|
+
* const imageGen = useAiImageGenerate(sdk);
|
|
601
|
+
*
|
|
602
|
+
* const handleGenerate = () => {
|
|
603
|
+
* imageGen.mutate({
|
|
604
|
+
* prompt: "브랜드 배너 이미지",
|
|
605
|
+
* style: "minimalist",
|
|
606
|
+
* aspectRatio: "16:9",
|
|
607
|
+
* });
|
|
608
|
+
* };
|
|
609
|
+
* // imageGen.data?.url
|
|
610
|
+
* ```
|
|
611
|
+
*/
|
|
315
612
|
function useAiImageGenerate(sdk, options) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
});
|
|
613
|
+
const queryClient = useQueryClient();
|
|
614
|
+
return useMutation({
|
|
615
|
+
mutationFn: (input) => sdk.ai.generateImage(input),
|
|
616
|
+
...options,
|
|
617
|
+
onSuccess: (...args) => {
|
|
618
|
+
queryClient.invalidateQueries({ queryKey: keys.aiCredits(sdk.config.brandappId) });
|
|
619
|
+
return options?.onSuccess?.(...args);
|
|
620
|
+
}
|
|
621
|
+
});
|
|
327
622
|
}
|
|
623
|
+
/**
|
|
624
|
+
* Post 목록 조회
|
|
625
|
+
*
|
|
626
|
+
* @example
|
|
627
|
+
* ```tsx
|
|
628
|
+
* const { data } = usePostList(sdk, { status: "published", limit: 10 });
|
|
629
|
+
* // data?.records (Post[]), data?.total
|
|
630
|
+
* ```
|
|
631
|
+
*/
|
|
328
632
|
function usePostList(sdk, query, options) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
633
|
+
return useQuery({
|
|
634
|
+
queryKey: keys.posts(sdk.config.brandappId, query),
|
|
635
|
+
queryFn: () => sdk.cms.posts.list(query),
|
|
636
|
+
...options
|
|
637
|
+
});
|
|
334
638
|
}
|
|
639
|
+
/**
|
|
640
|
+
* 단일 Post 조회 (with document content)
|
|
641
|
+
*
|
|
642
|
+
* @example
|
|
643
|
+
* ```tsx
|
|
644
|
+
* const { data: post } = usePost(sdk, postId);
|
|
645
|
+
* // post?.title, post?.document.contentRich
|
|
646
|
+
* ```
|
|
647
|
+
*/
|
|
335
648
|
function usePost(sdk, postId, options) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
649
|
+
return useQuery({
|
|
650
|
+
queryKey: keys.post(postId),
|
|
651
|
+
queryFn: () => sdk.cms.posts.get(postId),
|
|
652
|
+
enabled: !!postId,
|
|
653
|
+
...options
|
|
654
|
+
});
|
|
342
655
|
}
|
|
656
|
+
/**
|
|
657
|
+
* PostGroup 목록 조회
|
|
658
|
+
*
|
|
659
|
+
* @example
|
|
660
|
+
* ```tsx
|
|
661
|
+
* const { data } = usePostGroupList(sdk, { sortBy: "name" });
|
|
662
|
+
* // data?.records (PostGroup[]), data?.total
|
|
663
|
+
* ```
|
|
664
|
+
*/
|
|
343
665
|
function usePostGroupList(sdk, query, options) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
666
|
+
return useQuery({
|
|
667
|
+
queryKey: keys.postGroups(sdk.config.brandappId, query),
|
|
668
|
+
queryFn: () => sdk.cms.postGroups.list(query),
|
|
669
|
+
...options
|
|
670
|
+
});
|
|
349
671
|
}
|
|
672
|
+
/**
|
|
673
|
+
* 단일 PostGroup 조회
|
|
674
|
+
*
|
|
675
|
+
* @example
|
|
676
|
+
* ```tsx
|
|
677
|
+
* const { data: group } = usePostGroup(sdk, groupId);
|
|
678
|
+
* // group?.name, group?.postCount
|
|
679
|
+
* ```
|
|
680
|
+
*/
|
|
350
681
|
function usePostGroup(sdk, groupId, options) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
682
|
+
return useQuery({
|
|
683
|
+
queryKey: keys.postGroup(groupId),
|
|
684
|
+
queryFn: () => sdk.cms.postGroups.get(groupId),
|
|
685
|
+
enabled: !!groupId,
|
|
686
|
+
...options
|
|
687
|
+
});
|
|
357
688
|
}
|
|
689
|
+
/**
|
|
690
|
+
* Slug 기반 단일 Post 조회. 외부 사이트의 `/blog/[slug]` 같은 라우트에서
|
|
691
|
+
* id 매핑 없이 사용. (서버 컴포넌트에서는 `sdk.cms.posts.getBySlug`를
|
|
692
|
+
* 직접 호출하는 편이 추가 hop을 피할 수 있다.)
|
|
693
|
+
*
|
|
694
|
+
* @example
|
|
695
|
+
* ```tsx
|
|
696
|
+
* const { data: post } = usePostBySlug(sdk, slug);
|
|
697
|
+
* ```
|
|
698
|
+
*/
|
|
358
699
|
function usePostBySlug(sdk, slug, opts, options) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
700
|
+
return useQuery({
|
|
701
|
+
queryKey: [
|
|
702
|
+
...keys.all,
|
|
703
|
+
"postBySlug",
|
|
704
|
+
sdk.config.brandappId,
|
|
705
|
+
slug,
|
|
706
|
+
opts
|
|
707
|
+
],
|
|
708
|
+
queryFn: () => sdk.cms.posts.getBySlug(slug, opts),
|
|
709
|
+
enabled: !!slug,
|
|
710
|
+
...options
|
|
711
|
+
});
|
|
371
712
|
}
|
|
713
|
+
/**
|
|
714
|
+
* Brand 범위에서 사용된 포스트 태그 목록.
|
|
715
|
+
*
|
|
716
|
+
* @example
|
|
717
|
+
* ```tsx
|
|
718
|
+
* const { data: tags } = useCmsTags(sdk, { groupId: blogId });
|
|
719
|
+
* // tags?.[0]: { id, text, postCount }
|
|
720
|
+
* ```
|
|
721
|
+
*/
|
|
372
722
|
function useCmsTags(sdk, query, options) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
723
|
+
return useQuery({
|
|
724
|
+
queryKey: keys.tags(sdk.config.brandappId, query),
|
|
725
|
+
queryFn: () => sdk.cms.tags.list(query),
|
|
726
|
+
...options
|
|
727
|
+
});
|
|
378
728
|
}
|
|
729
|
+
/**
|
|
730
|
+
* 파일 목록 조회
|
|
731
|
+
*
|
|
732
|
+
* @example
|
|
733
|
+
* ```tsx
|
|
734
|
+
* const { data } = useFiles(sdk, { contentType: "image/*", sortBy: "createdAt" });
|
|
735
|
+
* // data?.data (FileInfo[]), data?.meta
|
|
736
|
+
* ```
|
|
737
|
+
*/
|
|
379
738
|
function useFiles(sdk, query, options) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
739
|
+
return useQuery({
|
|
740
|
+
queryKey: keys.files(sdk.config.brandappId, query),
|
|
741
|
+
queryFn: () => sdk.files.list(query),
|
|
742
|
+
...options
|
|
743
|
+
});
|
|
385
744
|
}
|
|
745
|
+
/**
|
|
746
|
+
* 단일 파일 조회
|
|
747
|
+
*
|
|
748
|
+
* @example
|
|
749
|
+
* ```tsx
|
|
750
|
+
* const { data: file } = useFile(sdk, fileId);
|
|
751
|
+
* // file?.name, file?.url
|
|
752
|
+
* ```
|
|
753
|
+
*/
|
|
386
754
|
function useFile(sdk, fileId, options) {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
755
|
+
return useQuery({
|
|
756
|
+
queryKey: keys.file(fileId),
|
|
757
|
+
queryFn: () => sdk.files.get(fileId),
|
|
758
|
+
enabled: !!fileId,
|
|
759
|
+
...options
|
|
760
|
+
});
|
|
393
761
|
}
|
|
762
|
+
/**
|
|
763
|
+
* 파일 삭제 mutation
|
|
764
|
+
*
|
|
765
|
+
* @example
|
|
766
|
+
* ```tsx
|
|
767
|
+
* const deleteFile = useDeleteFile(sdk);
|
|
768
|
+
* await deleteFile.mutateAsync("file-uuid");
|
|
769
|
+
* ```
|
|
770
|
+
*/
|
|
394
771
|
function useDeleteFile(sdk, options) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
...options
|
|
404
|
-
});
|
|
772
|
+
const queryClient = useQueryClient();
|
|
773
|
+
return useMutation({
|
|
774
|
+
mutationFn: (fileId) => sdk.files.delete(fileId),
|
|
775
|
+
onSuccess: () => {
|
|
776
|
+
queryClient.invalidateQueries({ queryKey: keys.files(sdk.config.brandappId) });
|
|
777
|
+
},
|
|
778
|
+
...options
|
|
779
|
+
});
|
|
405
780
|
}
|
|
781
|
+
/**
|
|
782
|
+
* 파일 업로드 mutation
|
|
783
|
+
*
|
|
784
|
+
* @example
|
|
785
|
+
* ```tsx
|
|
786
|
+
* const upload = useUploadFile(sdk);
|
|
787
|
+
* const file = await upload.mutateAsync({
|
|
788
|
+
* file: blob,
|
|
789
|
+
* options: { name: "banner.png" },
|
|
790
|
+
* });
|
|
791
|
+
* console.log(file.url);
|
|
792
|
+
* ```
|
|
793
|
+
*/
|
|
406
794
|
function useUploadFile(sdk, options) {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
...options
|
|
416
|
-
});
|
|
795
|
+
const queryClient = useQueryClient();
|
|
796
|
+
return useMutation({
|
|
797
|
+
mutationFn: (input) => sdk.files.upload(input.file, input.options),
|
|
798
|
+
onSuccess: () => {
|
|
799
|
+
queryClient.invalidateQueries({ queryKey: keys.files(sdk.config.brandappId) });
|
|
800
|
+
},
|
|
801
|
+
...options
|
|
802
|
+
});
|
|
417
803
|
}
|
|
418
804
|
|
|
805
|
+
//#endregion
|
|
419
806
|
export { keys as reoptQueryKeys, useAiAgents, useAiCompletion, useAiCredits, useAiImageGenerate, useAiModels, useAiStream, useBulkCreateRecords, useBulkDeleteRecords, useBulkUpdateRecords, useCmsTags, useCreateRecord, useDeleteFile, useDeleteRecord, useDeleteRecordsWhere, useEavEntities, useEavEntity, useEavRecord, useEavRecordCount, useEavRecords, useEavRecordsInfinite, useFile, useFiles, usePost, usePostBySlug, usePostGroup, usePostGroupList, usePostList, useUpdateRecord, useUploadFile, useUpsertRecord };
|
|
420
|
-
//# sourceMappingURL=hooks.js.map
|
|
421
807
|
//# sourceMappingURL=hooks.js.map
|