@reopt-ai/brandapp-sdk 3.3.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.
Files changed (102) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +10 -1
  3. package/dist/abort--nOBFN4M.js +50 -0
  4. package/dist/ai/index.d.ts +2 -314
  5. package/dist/ai/index.js +3 -8
  6. package/dist/ai-provider/index.d.ts +79 -163
  7. package/dist/ai-provider/index.js +752 -685
  8. package/dist/auth/index.d.ts +27 -27
  9. package/dist/auth/index.js +41 -34
  10. package/dist/better-auth/client.d.ts +6 -5
  11. package/dist/better-auth/client.js +28 -5
  12. package/dist/better-auth/index.d.ts +19 -17
  13. package/dist/better-auth/index.js +180 -144
  14. package/dist/client-B1q5P8rv.js +83 -0
  15. package/dist/client-B9QHVhdM.js +77 -0
  16. package/dist/client-BGGd_cpV.d.ts +103 -0
  17. package/dist/client-BJcy1V1a.js +140 -0
  18. package/dist/client-Beivhucf.js +55 -0
  19. package/dist/client-BruP5_nU.d.ts +147 -0
  20. package/dist/client-D-yNxNfk.js +28 -0
  21. package/dist/client-D0eBxh8j.d.ts +284 -0
  22. package/dist/client-D3RHHUUW.d.ts +207 -0
  23. package/dist/client-D6gs61w8.d.ts +53 -0
  24. package/dist/client-DBnK7ooQ.js +86 -0
  25. package/dist/client-DDw5yz_h.d.ts +53 -0
  26. package/dist/client-DPmoKuR9.js +305 -0
  27. package/dist/client-DsdakibF.js +503 -0
  28. package/dist/client-Dxg8_DIH.d.ts +71 -0
  29. package/dist/client-EbhUIhHq.js +53 -0
  30. package/dist/client-lk6wBu_0.d.ts +48 -0
  31. package/dist/client-p49ol9pg.d.ts +124 -0
  32. package/dist/cms/index.d.ts +52 -108
  33. package/dist/cms/index.js +103 -86
  34. package/dist/config-CRytOPPl.d.ts +394 -0
  35. package/dist/config-Cw0a3-C8.js +487 -0
  36. package/dist/dev/index.d.ts +2 -528
  37. package/dist/dev/index.js +2731 -2967
  38. package/dist/eav/coerce.d.ts +3 -1
  39. package/dist/eav/coerce.js +72 -46
  40. package/dist/eav/index.d.ts +72 -100
  41. package/dist/eav/index.js +158 -126
  42. package/dist/eav/migrate.d.ts +112 -109
  43. package/dist/eav/migrate.js +230 -196
  44. package/dist/eav/schema.d.ts +111 -150
  45. package/dist/eav/schema.js +624 -603
  46. package/dist/encoding-Bwfm3iaE.js +21 -0
  47. package/dist/{errors-BjDFIyA6.d.ts → errors-CRCcErNC.d.ts} +55 -53
  48. package/dist/feedback/index.d.ts +2 -132
  49. package/dist/feedback/index.js +3 -6
  50. package/dist/files/index.d.ts +14 -14
  51. package/dist/files/index.js +41 -25
  52. package/dist/http-client-QKUvvirs.js +386 -0
  53. package/dist/index-DrVaKfhs.d.ts +456 -0
  54. package/dist/index-Z6OGcurJ.d.ts +169 -0
  55. package/dist/index.d.ts +6 -230
  56. package/dist/index.js +119 -71
  57. package/dist/logout/index.d.ts +56 -53
  58. package/dist/logout/index.js +232 -289
  59. package/dist/plans/index.d.ts +2 -236
  60. package/dist/plans/index.js +3 -6
  61. package/dist/push/index.d.ts +2 -79
  62. package/dist/push/index.js +3 -6
  63. package/dist/query-BvbCiGWb.js +35 -0
  64. package/dist/react/hooks.d.ts +97 -99
  65. package/dist/react/hooks.js +742 -404
  66. package/dist/sse-parser-FMjxM7sY.js +86 -0
  67. package/dist/terms/index.d.ts +3 -79
  68. package/dist/terms/index.js +3 -6
  69. package/dist/testing/index.d.ts +52 -104
  70. package/dist/testing/index.js +94 -72
  71. package/dist/types-B-SMkH6s.d.ts +26 -0
  72. package/dist/types-BXDcoJHG.d.ts +131 -0
  73. package/dist/types-BrghN2rJ.d.ts +105 -0
  74. package/dist/types-DjDRszNj.js +11 -0
  75. package/dist/webhooks/index.d.ts +77 -50
  76. package/dist/webhooks/index.js +150 -127
  77. package/docs/api-reference.md +87 -6
  78. package/package.json +6 -5
  79. package/dist/chunk-2LSCQHAU.js +0 -21
  80. package/dist/chunk-4U4ZPPL4.js +0 -599
  81. package/dist/chunk-55KHY5GH.js +0 -96
  82. package/dist/chunk-C5VTRZWX.js +0 -458
  83. package/dist/chunk-F7BXBTZI.js +0 -54
  84. package/dist/chunk-FJUCWXX3.js +0 -350
  85. package/dist/chunk-H33OTQEN.js +0 -112
  86. package/dist/chunk-L4DHB36G.js +0 -75
  87. package/dist/chunk-OG7R3UAR.js +0 -105
  88. package/dist/chunk-PF24XU54.js +0 -32
  89. package/dist/chunk-QN3QD67K.js +0 -49
  90. package/dist/chunk-REIKXSMY.js +0 -7
  91. package/dist/chunk-UGBBXCZE.js +0 -157
  92. package/dist/chunk-UVT2E6KD.js +0 -81
  93. package/dist/chunk-YPLT3RFL.js +0 -63
  94. package/dist/chunk-YTKSAWV2.js +0 -463
  95. package/dist/client-BkcO-0C2.d.ts +0 -216
  96. package/dist/client-CN5_tNOC.d.ts +0 -147
  97. package/dist/client-DttyeM_h.d.ts +0 -102
  98. package/dist/config-CtxyJsDR.d.ts +0 -397
  99. package/dist/typed-client-BxOVIiMU.d.ts +0 -40
  100. package/dist/types-6E3ZLL9X.d.ts +0 -24
  101. package/dist/types-DskYLVb8.d.ts +0 -104
  102. package/dist/types-ckmDDW3N.d.ts +0 -129
@@ -1,469 +1,807 @@
1
- import { useState, useRef, useEffect, useCallback } from 'react';
2
- import { useQuery, useInfiniteQuery, useQueryClient, useMutation } from '@tanstack/react-query';
1
+ "use client";
3
2
 
4
- var hasRaf = typeof requestAnimationFrame === "function";
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
- const [text, setText] = useState("");
7
- const [isStreaming, setIsStreaming] = useState(false);
8
- const [error, setError] = useState(null);
9
- const [metadata, setMetadata] = useState(null);
10
- const controllerRef = useRef(null);
11
- const optionsRef = useRef(options);
12
- const pendingTextRef = useRef("");
13
- const rafRef = useRef(null);
14
- useEffect(() => {
15
- optionsRef.current = options;
16
- }, [options]);
17
- const cancelTextFlush = useCallback(() => {
18
- if (rafRef.current !== null) {
19
- cancelAnimationFrame(rafRef.current);
20
- rafRef.current = null;
21
- }
22
- }, []);
23
- const commitText = useCallback(() => {
24
- cancelTextFlush();
25
- setText(pendingTextRef.current);
26
- }, [cancelTextFlush]);
27
- const scheduleTextFlush = useCallback(() => {
28
- if (!hasRaf) {
29
- setText(pendingTextRef.current);
30
- return;
31
- }
32
- if (rafRef.current !== null) return;
33
- rafRef.current = requestAnimationFrame(() => {
34
- rafRef.current = null;
35
- setText(pendingTextRef.current);
36
- });
37
- }, []);
38
- const stop = useCallback(() => {
39
- cancelTextFlush();
40
- controllerRef.current?.abort();
41
- controllerRef.current = null;
42
- }, [cancelTextFlush]);
43
- const reset = useCallback(() => {
44
- stop();
45
- pendingTextRef.current = "";
46
- setText("");
47
- setError(null);
48
- setMetadata(null);
49
- setIsStreaming(false);
50
- }, [stop]);
51
- useEffect(() => {
52
- return () => {
53
- cancelTextFlush();
54
- controllerRef.current?.abort();
55
- controllerRef.current = null;
56
- };
57
- }, [cancelTextFlush]);
58
- const generate = useCallback(
59
- (completionOptions) => {
60
- stop();
61
- const controller = new AbortController();
62
- controllerRef.current = controller;
63
- pendingTextRef.current = "";
64
- setText("");
65
- setError(null);
66
- setMetadata(null);
67
- setIsStreaming(true);
68
- const { textStream, metadata: metaPromise } = sdk.ai.streamWithMetadata({
69
- ...completionOptions,
70
- signal: controller.signal
71
- });
72
- (async () => {
73
- try {
74
- let accumulated = "";
75
- for await (const chunk of textStream) {
76
- if (controller.signal.aborted) break;
77
- accumulated += chunk;
78
- pendingTextRef.current = accumulated;
79
- scheduleTextFlush();
80
- optionsRef.current?.onChunk?.(chunk);
81
- }
82
- const meta = await metaPromise;
83
- if (!controller.signal.aborted) {
84
- commitText();
85
- setMetadata(meta);
86
- optionsRef.current?.onFinish?.(accumulated, meta);
87
- }
88
- } catch (err) {
89
- if (!controller.signal.aborted) {
90
- commitText();
91
- const e = err instanceof Error ? err : new Error(String(err));
92
- setError(e);
93
- optionsRef.current?.onError?.(e);
94
- }
95
- } finally {
96
- if (controllerRef.current === controller) {
97
- setIsStreaming(false);
98
- controllerRef.current = null;
99
- }
100
- }
101
- })();
102
- },
103
- [sdk, stop, scheduleTextFlush, commitText]
104
- );
105
- return { text, isStreaming, error, metadata, generate, stop, reset };
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
- var keys = {
108
- all: ["reopt"],
109
- entities: (brandappId) => [...keys.all, "entities", brandappId],
110
- entity: (entityId) => [...keys.all, "entity", entityId],
111
- records: (entityId, query) => [...keys.all, "records", entityId, query],
112
- // Infinite lists get a DISTINCT namespace: in TanStack v5 useQuery and
113
- // useInfiniteQuery share one QueryCache keyed by queryHash, so a shared key
114
- // would collide (PaginatedResponse vs InfiniteData) if both hooks mount for
115
- // the same entity+query.
116
- recordsInfinite: (entityId, query) => [...keys.all, "recordsInfinite", entityId, query],
117
- record: (entityId, recordId) => [...keys.all, "record", entityId, recordId],
118
- recordCount: (entityId, query) => [...keys.all, "recordCount", entityId, query],
119
- // Length-3 invalidation prefixes. partialMatchKey only prefix-matches a
120
- // SHORTER key, so `keys.records(entityId)` (trailing `undefined`) fails to
121
- // match a list queried WITH a query object. These match every finite /
122
- // infinite record list + count for an entity regardless of its query object.
123
- recordsPrefix: (entityId) => [...keys.all, "records", entityId],
124
- recordsInfinitePrefix: (entityId) => [...keys.all, "recordsInfinite", entityId],
125
- recordCountPrefix: (entityId) => [...keys.all, "recordCount", entityId],
126
- aiCredits: (brandappId) => [...keys.all, "ai", "credits", brandappId],
127
- aiModels: (brandappId) => [...keys.all, "ai", "models", brandappId],
128
- aiAgents: (brandappId) => [...keys.all, "ai", "agents", brandappId],
129
- posts: (brandappId, query) => [...keys.all, "posts", brandappId, query],
130
- post: (postId) => [...keys.all, "post", postId],
131
- postGroups: (brandappId, query) => [...keys.all, "postGroups", brandappId, query],
132
- postGroup: (groupId) => [...keys.all, "postGroup", groupId],
133
- tags: (brandappId, query) => [...keys.all, "tags", brandappId, query],
134
- files: (brandappId, query) => [...keys.all, "files", brandappId, query],
135
- file: (fileId) => [...keys.all, "file", fileId]
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
+ ]
136
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
+ */
137
271
  function useEavEntities(sdk, options) {
138
- return useQuery({
139
- queryKey: keys.entities(sdk.config.brandappId),
140
- queryFn: () => sdk.eav.entities.list(),
141
- staleTime: 5 * 60 * 1e3,
142
- // 5 min — schema rarely changes
143
- ...options
144
- });
272
+ return useQuery({
273
+ queryKey: keys.entities(sdk.config.brandappId),
274
+ queryFn: () => sdk.eav.entities.list(),
275
+ staleTime: 300 * 1e3,
276
+ ...options
277
+ });
145
278
  }
146
279
  function useEavEntity(sdk, entityId, options) {
147
- return useQuery({
148
- queryKey: keys.entity(entityId),
149
- queryFn: () => sdk.eav.entities.get(entityId),
150
- staleTime: 5 * 60 * 1e3,
151
- enabled: !!entityId,
152
- ...options
153
- });
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
+ });
154
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
+ */
155
310
  function useEavRecords(sdk, entityId, query, options) {
156
- return useQuery({
157
- queryKey: keys.records(entityId, query),
158
- queryFn: () => sdk.eav.records.list(entityId, query),
159
- enabled: !!entityId,
160
- ...options
161
- });
311
+ return useQuery({
312
+ queryKey: keys.records(entityId, query),
313
+ queryFn: () => sdk.eav.records.list(entityId, query),
314
+ enabled: !!entityId,
315
+ ...options
316
+ });
162
317
  }
163
318
  function useEavRecordsInfinite(sdk, entityId, query, options) {
164
- return useInfiniteQuery({
165
- queryKey: keys.recordsInfinite(entityId, query),
166
- queryFn: ({ pageParam }) => sdk.eav.records.list(entityId, { ...query, page: pageParam }),
167
- initialPageParam: 1,
168
- getNextPageParam: (lastPage) => lastPage.page < lastPage.totalPages ? lastPage.page + 1 : void 0,
169
- enabled: !!entityId,
170
- ...options
171
- });
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
+ });
172
330
  }
173
331
  function useEavRecord(sdk, entityId, recordId, options) {
174
- return useQuery({
175
- queryKey: keys.record(entityId, recordId),
176
- queryFn: () => sdk.eav.records.get(entityId, recordId),
177
- enabled: !!entityId && !!recordId,
178
- ...options
179
- });
332
+ return useQuery({
333
+ queryKey: keys.record(entityId, recordId),
334
+ queryFn: () => sdk.eav.records.get(entityId, recordId),
335
+ enabled: !!entityId && !!recordId,
336
+ ...options
337
+ });
180
338
  }
181
339
  function useEavRecordCount(sdk, entityId, query, options) {
182
- return useQuery({
183
- queryKey: keys.recordCount(entityId, query),
184
- queryFn: () => sdk.eav.records.count(entityId, query),
185
- enabled: !!entityId,
186
- ...options
187
- });
340
+ return useQuery({
341
+ queryKey: keys.recordCount(entityId, query),
342
+ queryFn: () => sdk.eav.records.count(entityId, query),
343
+ enabled: !!entityId,
344
+ ...options
345
+ });
188
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
+ */
189
379
  function useCreateRecord(sdk, entityId, options) {
190
- const queryClient = useQueryClient();
191
- return useMutation({
192
- mutationFn: (input) => sdk.eav.records.create(entityId, input),
193
- onSuccess: () => {
194
- queryClient.invalidateQueries({ queryKey: keys.recordsPrefix(entityId) });
195
- queryClient.invalidateQueries({
196
- queryKey: keys.recordsInfinitePrefix(entityId)
197
- });
198
- queryClient.invalidateQueries({
199
- queryKey: keys.recordCountPrefix(entityId)
200
- });
201
- },
202
- ...options
203
- });
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
+ });
204
390
  }
205
391
  function useUpdateRecord(sdk, entityId, options) {
206
- const queryClient = useQueryClient();
207
- return useMutation({
208
- mutationFn: ({
209
- recordId,
210
- input
211
- }) => sdk.eav.records.update(entityId, recordId, input),
212
- onSuccess: (_, variables) => {
213
- queryClient.invalidateQueries({ queryKey: keys.recordsPrefix(entityId) });
214
- queryClient.invalidateQueries({
215
- queryKey: keys.recordsInfinitePrefix(entityId)
216
- });
217
- queryClient.invalidateQueries({
218
- queryKey: keys.record(entityId, variables.recordId)
219
- });
220
- },
221
- ...options
222
- });
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
+ });
223
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
+ */
224
412
  function useDeleteRecord(sdk, entityId, options) {
225
- const queryClient = useQueryClient();
226
- return useMutation({
227
- mutationFn: (recordId) => sdk.eav.records.delete(entityId, recordId),
228
- onSuccess: () => {
229
- queryClient.invalidateQueries({ queryKey: keys.recordsPrefix(entityId) });
230
- queryClient.invalidateQueries({
231
- queryKey: keys.recordsInfinitePrefix(entityId)
232
- });
233
- queryClient.invalidateQueries({
234
- queryKey: keys.recordCountPrefix(entityId)
235
- });
236
- },
237
- ...options
238
- });
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
+ });
239
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
+ */
240
436
  function useUpsertRecord(sdk, entityId, options) {
241
- const queryClient = useQueryClient();
242
- return useMutation({
243
- mutationFn: (input) => sdk.eav.records.upsert(entityId, input),
244
- onSuccess: () => {
245
- queryClient.invalidateQueries({ queryKey: keys.recordsPrefix(entityId) });
246
- queryClient.invalidateQueries({
247
- queryKey: keys.recordsInfinitePrefix(entityId)
248
- });
249
- queryClient.invalidateQueries({
250
- queryKey: keys.recordCountPrefix(entityId)
251
- });
252
- },
253
- ...options
254
- });
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
+ });
255
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
+ */
256
460
  function useBulkCreateRecords(sdk, entityId, options) {
257
- const queryClient = useQueryClient();
258
- return useMutation({
259
- mutationFn: (records) => sdk.eav.records.bulkCreate(entityId, records),
260
- onSuccess: () => {
261
- queryClient.invalidateQueries({ queryKey: keys.recordsPrefix(entityId) });
262
- queryClient.invalidateQueries({
263
- queryKey: keys.recordsInfinitePrefix(entityId)
264
- });
265
- queryClient.invalidateQueries({
266
- queryKey: keys.recordCountPrefix(entityId)
267
- });
268
- },
269
- ...options
270
- });
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
+ });
271
471
  }
472
+ /**
473
+ * 최대 100개 레코드를 한 번에 업데이트하는 mutation.
474
+ */
272
475
  function useBulkUpdateRecords(sdk, entityId, options) {
273
- const queryClient = useQueryClient();
274
- return useMutation({
275
- mutationFn: (updates) => sdk.eav.records.bulkUpdate(entityId, updates),
276
- onSuccess: (_data, variables) => {
277
- queryClient.invalidateQueries({ queryKey: keys.recordsPrefix(entityId) });
278
- queryClient.invalidateQueries({
279
- queryKey: keys.recordsInfinitePrefix(entityId)
280
- });
281
- for (const { id } of variables) {
282
- queryClient.invalidateQueries({
283
- queryKey: keys.record(entityId, id)
284
- });
285
- }
286
- },
287
- ...options
288
- });
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
+ });
289
486
  }
487
+ /**
488
+ * 최대 100개 레코드를 한 번에 삭제하는 mutation. 삭제된 레코드 수를 반환.
489
+ */
290
490
  function useBulkDeleteRecords(sdk, entityId, options) {
291
- const queryClient = useQueryClient();
292
- return useMutation({
293
- mutationFn: (ids) => sdk.eav.records.bulkDelete(entityId, ids),
294
- onSuccess: () => {
295
- queryClient.invalidateQueries({ queryKey: keys.recordsPrefix(entityId) });
296
- queryClient.invalidateQueries({
297
- queryKey: keys.recordsInfinitePrefix(entityId)
298
- });
299
- queryClient.invalidateQueries({
300
- queryKey: keys.recordCountPrefix(entityId)
301
- });
302
- },
303
- ...options
304
- });
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
+ });
305
501
  }
502
+ /**
503
+ * 필터에 매칭되는 모든 레코드를 삭제하는 mutation. 삭제된 수를 반환.
504
+ */
306
505
  function useDeleteRecordsWhere(sdk, entityId, options) {
307
- const queryClient = useQueryClient();
308
- return useMutation({
309
- mutationFn: (input) => sdk.eav.records.deleteWhere(entityId, input),
310
- onSuccess: () => {
311
- queryClient.invalidateQueries({ queryKey: keys.recordsPrefix(entityId) });
312
- queryClient.invalidateQueries({
313
- queryKey: keys.recordsInfinitePrefix(entityId)
314
- });
315
- queryClient.invalidateQueries({
316
- queryKey: keys.recordCountPrefix(entityId)
317
- });
318
- },
319
- ...options
320
- });
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
+ });
321
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
+ */
322
526
  function useAiCredits(sdk, options) {
323
- return useQuery({
324
- queryKey: keys.aiCredits(sdk.config.brandappId),
325
- queryFn: () => sdk.ai.credits(),
326
- staleTime: 30 * 1e3,
327
- // 30초 — 크레딧은 자주 변동
328
- ...options
329
- });
527
+ return useQuery({
528
+ queryKey: keys.aiCredits(sdk.config.brandappId),
529
+ queryFn: () => sdk.ai.credits(),
530
+ staleTime: 30 * 1e3,
531
+ ...options
532
+ });
330
533
  }
534
+ /**
535
+ * BrandApp AI 사용 가능 모델 목록
536
+ *
537
+ * @example
538
+ * ```tsx
539
+ * const { data: models } = useAiModels(sdk);
540
+ * // models?.map(m => m.id)
541
+ * ```
542
+ */
331
543
  function useAiModels(sdk, options) {
332
- return useQuery({
333
- queryKey: keys.aiModels(sdk.config.brandappId),
334
- queryFn: () => sdk.ai.models(),
335
- staleTime: 5 * 60 * 1e3,
336
- // 5분 — 모델 목록은 자주 안 바뀜
337
- ...options
338
- });
544
+ return useQuery({
545
+ queryKey: keys.aiModels(sdk.config.brandappId),
546
+ queryFn: () => sdk.ai.models(),
547
+ staleTime: 300 * 1e3,
548
+ ...options
549
+ });
339
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
+ */
340
560
  function useAiAgents(sdk, options) {
341
- return useQuery({
342
- queryKey: keys.aiAgents(sdk.config.brandappId),
343
- queryFn: () => sdk.ai.agents(),
344
- staleTime: 5 * 60 * 1e3,
345
- // 5분 — 에이전트 목록은 자주 안 바뀜
346
- ...options
347
- });
561
+ return useQuery({
562
+ queryKey: keys.aiAgents(sdk.config.brandappId),
563
+ queryFn: () => sdk.ai.agents(),
564
+ staleTime: 300 * 1e3,
565
+ ...options
566
+ });
348
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
+ */
349
584
  function useAiCompletion(sdk, options) {
350
- const queryClient = useQueryClient();
351
- return useMutation({
352
- mutationFn: (input) => sdk.ai.complete(input),
353
- ...options,
354
- // 크레딧이 차감됐으므로 잔액 쿼리를 무효화(배지 즉시 갱신). caller onSuccess 병합.
355
- onSuccess: (...args) => {
356
- queryClient.invalidateQueries({
357
- queryKey: keys.aiCredits(sdk.config.brandappId)
358
- });
359
- return options?.onSuccess?.(...args);
360
- }
361
- });
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
+ });
362
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
+ */
363
612
  function useAiImageGenerate(sdk, options) {
364
- const queryClient = useQueryClient();
365
- return useMutation({
366
- mutationFn: (input) => sdk.ai.generateImage(input),
367
- ...options,
368
- onSuccess: (...args) => {
369
- queryClient.invalidateQueries({
370
- queryKey: keys.aiCredits(sdk.config.brandappId)
371
- });
372
- return options?.onSuccess?.(...args);
373
- }
374
- });
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
+ });
375
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
+ */
376
632
  function usePostList(sdk, query, options) {
377
- return useQuery({
378
- queryKey: keys.posts(sdk.config.brandappId, query),
379
- queryFn: () => sdk.cms.posts.list(query),
380
- ...options
381
- });
633
+ return useQuery({
634
+ queryKey: keys.posts(sdk.config.brandappId, query),
635
+ queryFn: () => sdk.cms.posts.list(query),
636
+ ...options
637
+ });
382
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
+ */
383
648
  function usePost(sdk, postId, options) {
384
- return useQuery({
385
- queryKey: keys.post(postId),
386
- queryFn: () => sdk.cms.posts.get(postId),
387
- enabled: !!postId,
388
- ...options
389
- });
649
+ return useQuery({
650
+ queryKey: keys.post(postId),
651
+ queryFn: () => sdk.cms.posts.get(postId),
652
+ enabled: !!postId,
653
+ ...options
654
+ });
390
655
  }
656
+ /**
657
+ * PostGroup 목록 조회
658
+ *
659
+ * @example
660
+ * ```tsx
661
+ * const { data } = usePostGroupList(sdk, { sortBy: "name" });
662
+ * // data?.records (PostGroup[]), data?.total
663
+ * ```
664
+ */
391
665
  function usePostGroupList(sdk, query, options) {
392
- return useQuery({
393
- queryKey: keys.postGroups(sdk.config.brandappId, query),
394
- queryFn: () => sdk.cms.postGroups.list(query),
395
- ...options
396
- });
666
+ return useQuery({
667
+ queryKey: keys.postGroups(sdk.config.brandappId, query),
668
+ queryFn: () => sdk.cms.postGroups.list(query),
669
+ ...options
670
+ });
397
671
  }
672
+ /**
673
+ * 단일 PostGroup 조회
674
+ *
675
+ * @example
676
+ * ```tsx
677
+ * const { data: group } = usePostGroup(sdk, groupId);
678
+ * // group?.name, group?.postCount
679
+ * ```
680
+ */
398
681
  function usePostGroup(sdk, groupId, options) {
399
- return useQuery({
400
- queryKey: keys.postGroup(groupId),
401
- queryFn: () => sdk.cms.postGroups.get(groupId),
402
- enabled: !!groupId,
403
- ...options
404
- });
682
+ return useQuery({
683
+ queryKey: keys.postGroup(groupId),
684
+ queryFn: () => sdk.cms.postGroups.get(groupId),
685
+ enabled: !!groupId,
686
+ ...options
687
+ });
405
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
+ */
406
699
  function usePostBySlug(sdk, slug, opts, options) {
407
- return useQuery({
408
- queryKey: [
409
- ...keys.all,
410
- "postBySlug",
411
- sdk.config.brandappId,
412
- slug,
413
- opts
414
- ],
415
- queryFn: () => sdk.cms.posts.getBySlug(slug, opts),
416
- enabled: !!slug,
417
- ...options
418
- });
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
+ });
419
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
+ */
420
722
  function useCmsTags(sdk, query, options) {
421
- return useQuery({
422
- queryKey: keys.tags(sdk.config.brandappId, query),
423
- queryFn: () => sdk.cms.tags.list(query),
424
- ...options
425
- });
723
+ return useQuery({
724
+ queryKey: keys.tags(sdk.config.brandappId, query),
725
+ queryFn: () => sdk.cms.tags.list(query),
726
+ ...options
727
+ });
426
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
+ */
427
738
  function useFiles(sdk, query, options) {
428
- return useQuery({
429
- queryKey: keys.files(sdk.config.brandappId, query),
430
- queryFn: () => sdk.files.list(query),
431
- ...options
432
- });
739
+ return useQuery({
740
+ queryKey: keys.files(sdk.config.brandappId, query),
741
+ queryFn: () => sdk.files.list(query),
742
+ ...options
743
+ });
433
744
  }
745
+ /**
746
+ * 단일 파일 조회
747
+ *
748
+ * @example
749
+ * ```tsx
750
+ * const { data: file } = useFile(sdk, fileId);
751
+ * // file?.name, file?.url
752
+ * ```
753
+ */
434
754
  function useFile(sdk, fileId, options) {
435
- return useQuery({
436
- queryKey: keys.file(fileId),
437
- queryFn: () => sdk.files.get(fileId),
438
- enabled: !!fileId,
439
- ...options
440
- });
755
+ return useQuery({
756
+ queryKey: keys.file(fileId),
757
+ queryFn: () => sdk.files.get(fileId),
758
+ enabled: !!fileId,
759
+ ...options
760
+ });
441
761
  }
762
+ /**
763
+ * 파일 삭제 mutation
764
+ *
765
+ * @example
766
+ * ```tsx
767
+ * const deleteFile = useDeleteFile(sdk);
768
+ * await deleteFile.mutateAsync("file-uuid");
769
+ * ```
770
+ */
442
771
  function useDeleteFile(sdk, options) {
443
- const queryClient = useQueryClient();
444
- return useMutation({
445
- mutationFn: (fileId) => sdk.files.delete(fileId),
446
- onSuccess: () => {
447
- queryClient.invalidateQueries({
448
- queryKey: keys.files(sdk.config.brandappId)
449
- });
450
- },
451
- ...options
452
- });
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
+ });
453
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
+ */
454
794
  function useUploadFile(sdk, options) {
455
- const queryClient = useQueryClient();
456
- return useMutation({
457
- mutationFn: (input) => sdk.files.upload(input.file, input.options),
458
- onSuccess: () => {
459
- queryClient.invalidateQueries({
460
- queryKey: keys.files(sdk.config.brandappId)
461
- });
462
- },
463
- ...options
464
- });
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
+ });
465
803
  }
466
804
 
805
+ //#endregion
467
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 };
468
- //# sourceMappingURL=hooks.js.map
469
807
  //# sourceMappingURL=hooks.js.map