@reopt-ai/brandapp-sdk 3.0.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 +574 -0
- package/LICENSE +21 -0
- package/README.md +468 -0
- package/dist/ai/index.d.ts +314 -0
- package/dist/ai/index.js +7 -0
- package/dist/ai-provider/index.d.ts +196 -0
- package/dist/ai-provider/index.js +703 -0
- package/dist/auth/index.d.ts +76 -0
- package/dist/auth/index.js +40 -0
- package/dist/better-auth/client.d.ts +29 -0
- package/dist/better-auth/client.js +10 -0
- package/dist/better-auth/index.d.ts +82 -0
- package/dist/better-auth/index.js +145 -0
- package/dist/chunk-6FLYVNZI.js +32 -0
- package/dist/chunk-6KPKZ7ZB.js +49 -0
- package/dist/chunk-DI6QJPTQ.js +449 -0
- package/dist/chunk-E457LO5A.js +599 -0
- package/dist/chunk-F7BXBTZI.js +54 -0
- package/dist/chunk-J5Y2GSJF.js +443 -0
- package/dist/chunk-K3YVJE6E.js +96 -0
- package/dist/chunk-KU2LN5SE.js +350 -0
- package/dist/chunk-L4DHB36G.js +75 -0
- package/dist/chunk-PJZB4VP7.js +63 -0
- package/dist/chunk-REIKXSMY.js +7 -0
- package/dist/chunk-T2WXHAAC.js +54 -0
- package/dist/chunk-TUKIYH4Q.js +112 -0
- package/dist/chunk-WSEROZVO.js +81 -0
- package/dist/chunk-YRGLBM6V.js +157 -0
- package/dist/client-BkcO-0C2.d.ts +216 -0
- package/dist/client-CN5_tNOC.d.ts +147 -0
- package/dist/client-DttyeM_h.d.ts +102 -0
- package/dist/cms/index.d.ts +137 -0
- package/dist/cms/index.js +101 -0
- package/dist/config-CtxyJsDR.d.ts +397 -0
- package/dist/dev/index.d.ts +509 -0
- package/dist/dev/index.js +3071 -0
- package/dist/eav/coerce.d.ts +42 -0
- package/dist/eav/coerce.js +65 -0
- package/dist/eav/index.d.ts +214 -0
- package/dist/eav/index.js +147 -0
- package/dist/eav/migrate.d.ts +236 -0
- package/dist/eav/migrate.js +219 -0
- package/dist/eav/schema.d.ts +260 -0
- package/dist/eav/schema.js +656 -0
- package/dist/errors-5hd5ZR-M.d.ts +158 -0
- package/dist/feedback/index.d.ts +132 -0
- package/dist/feedback/index.js +5 -0
- package/dist/files/index.d.ts +54 -0
- package/dist/files/index.js +31 -0
- package/dist/index.d.ts +221 -0
- package/dist/index.js +84 -0
- package/dist/plans/index.d.ts +140 -0
- package/dist/plans/index.js +5 -0
- package/dist/push/index.d.ts +79 -0
- package/dist/push/index.js +5 -0
- package/dist/react/hooks.d.ts +376 -0
- package/dist/react/hooks.js +421 -0
- package/dist/terms/index.d.ts +79 -0
- package/dist/terms/index.js +5 -0
- package/dist/testing/index.d.ts +154 -0
- package/dist/testing/index.js +81 -0
- package/dist/typed-client-BxOVIiMU.d.ts +40 -0
- package/dist/types-6E3ZLL9X.d.ts +24 -0
- package/dist/types-DskYLVb8.d.ts +104 -0
- package/dist/types-ckmDDW3N.d.ts +129 -0
- package/dist/webhooks/index.d.ts +140 -0
- package/dist/webhooks/index.js +142 -0
- package/docs/api-reference.md +557 -0
- package/docs/cms.md +318 -0
- package/docs/dev-server.md +164 -0
- package/docs/environment.md +211 -0
- package/docs/errors.md +290 -0
- package/docs/files.md +272 -0
- package/docs/migration.md +315 -0
- package/docs/testing.md +163 -0
- package/package.json +173 -0
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
2
|
+
import { useQuery, useInfiniteQuery, useQueryClient, useMutation } from '@tanstack/react-query';
|
|
3
|
+
|
|
4
|
+
var hasRaf = typeof requestAnimationFrame === "function";
|
|
5
|
+
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 };
|
|
106
|
+
}
|
|
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
|
+
record: (entityId, recordId) => [...keys.all, "record", entityId, recordId],
|
|
113
|
+
recordCount: (entityId, query) => [...keys.all, "recordCount", entityId, query],
|
|
114
|
+
aiCredits: (brandappId) => [...keys.all, "ai", "credits", brandappId],
|
|
115
|
+
aiModels: (brandappId) => [...keys.all, "ai", "models", brandappId],
|
|
116
|
+
aiAgents: (brandappId) => [...keys.all, "ai", "agents", brandappId],
|
|
117
|
+
posts: (brandappId, query) => [...keys.all, "posts", brandappId, query],
|
|
118
|
+
post: (postId) => [...keys.all, "post", postId],
|
|
119
|
+
postGroups: (brandappId, query) => [...keys.all, "postGroups", brandappId, query],
|
|
120
|
+
postGroup: (groupId) => [...keys.all, "postGroup", groupId],
|
|
121
|
+
tags: (brandappId, query) => [...keys.all, "tags", brandappId, query],
|
|
122
|
+
files: (brandappId, query) => [...keys.all, "files", brandappId, query],
|
|
123
|
+
file: (fileId) => [...keys.all, "file", fileId]
|
|
124
|
+
};
|
|
125
|
+
function useEavEntities(sdk, options) {
|
|
126
|
+
return useQuery({
|
|
127
|
+
queryKey: keys.entities(sdk.config.brandappId),
|
|
128
|
+
queryFn: () => sdk.eav.entities.list(),
|
|
129
|
+
staleTime: 5 * 60 * 1e3,
|
|
130
|
+
// 5 min — schema rarely changes
|
|
131
|
+
...options
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function useEavEntity(sdk, entityId, options) {
|
|
135
|
+
return useQuery({
|
|
136
|
+
queryKey: keys.entity(entityId),
|
|
137
|
+
queryFn: () => sdk.eav.entities.get(entityId),
|
|
138
|
+
staleTime: 5 * 60 * 1e3,
|
|
139
|
+
enabled: !!entityId,
|
|
140
|
+
...options
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function useEavRecords(sdk, entityId, query, options) {
|
|
144
|
+
return useQuery({
|
|
145
|
+
queryKey: keys.records(entityId, query),
|
|
146
|
+
queryFn: () => sdk.eav.records.list(entityId, query),
|
|
147
|
+
enabled: !!entityId,
|
|
148
|
+
...options
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function useEavRecordsInfinite(sdk, entityId, query, options) {
|
|
152
|
+
return useInfiniteQuery({
|
|
153
|
+
queryKey: keys.records(entityId, query),
|
|
154
|
+
queryFn: ({ pageParam }) => sdk.eav.records.list(entityId, { ...query, page: pageParam }),
|
|
155
|
+
initialPageParam: 1,
|
|
156
|
+
getNextPageParam: (lastPage) => lastPage.page < lastPage.totalPages ? lastPage.page + 1 : void 0,
|
|
157
|
+
enabled: !!entityId,
|
|
158
|
+
...options
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function useEavRecord(sdk, entityId, recordId, options) {
|
|
162
|
+
return useQuery({
|
|
163
|
+
queryKey: keys.record(entityId, recordId),
|
|
164
|
+
queryFn: () => sdk.eav.records.get(entityId, recordId),
|
|
165
|
+
enabled: !!entityId && !!recordId,
|
|
166
|
+
...options
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function useEavRecordCount(sdk, entityId, query, options) {
|
|
170
|
+
return useQuery({
|
|
171
|
+
queryKey: keys.recordCount(entityId, query),
|
|
172
|
+
queryFn: () => sdk.eav.records.count(entityId, query),
|
|
173
|
+
enabled: !!entityId,
|
|
174
|
+
...options
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function useCreateRecord(sdk, entityId, options) {
|
|
178
|
+
const queryClient = useQueryClient();
|
|
179
|
+
return useMutation({
|
|
180
|
+
mutationFn: (input) => sdk.eav.records.create(entityId, input),
|
|
181
|
+
onSuccess: () => {
|
|
182
|
+
queryClient.invalidateQueries({ queryKey: keys.records(entityId) });
|
|
183
|
+
queryClient.invalidateQueries({ queryKey: keys.recordCount(entityId) });
|
|
184
|
+
},
|
|
185
|
+
...options
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
function useUpdateRecord(sdk, entityId, options) {
|
|
189
|
+
const queryClient = useQueryClient();
|
|
190
|
+
return useMutation({
|
|
191
|
+
mutationFn: ({
|
|
192
|
+
recordId,
|
|
193
|
+
input
|
|
194
|
+
}) => sdk.eav.records.update(entityId, recordId, input),
|
|
195
|
+
onSuccess: (_, variables) => {
|
|
196
|
+
queryClient.invalidateQueries({ queryKey: keys.records(entityId) });
|
|
197
|
+
queryClient.invalidateQueries({
|
|
198
|
+
queryKey: keys.record(entityId, variables.recordId)
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
...options
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
function useDeleteRecord(sdk, entityId, options) {
|
|
205
|
+
const queryClient = useQueryClient();
|
|
206
|
+
return useMutation({
|
|
207
|
+
mutationFn: (recordId) => sdk.eav.records.delete(entityId, recordId),
|
|
208
|
+
onSuccess: () => {
|
|
209
|
+
queryClient.invalidateQueries({ queryKey: keys.records(entityId) });
|
|
210
|
+
queryClient.invalidateQueries({ queryKey: keys.recordCount(entityId) });
|
|
211
|
+
},
|
|
212
|
+
...options
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
function useUpsertRecord(sdk, entityId, options) {
|
|
216
|
+
const queryClient = useQueryClient();
|
|
217
|
+
return useMutation({
|
|
218
|
+
mutationFn: (input) => sdk.eav.records.upsert(entityId, input),
|
|
219
|
+
onSuccess: () => {
|
|
220
|
+
queryClient.invalidateQueries({ queryKey: keys.records(entityId) });
|
|
221
|
+
queryClient.invalidateQueries({ queryKey: keys.recordCount(entityId) });
|
|
222
|
+
},
|
|
223
|
+
...options
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
function useBulkCreateRecords(sdk, entityId, options) {
|
|
227
|
+
const queryClient = useQueryClient();
|
|
228
|
+
return useMutation({
|
|
229
|
+
mutationFn: (records) => sdk.eav.records.bulkCreate(entityId, records),
|
|
230
|
+
onSuccess: () => {
|
|
231
|
+
queryClient.invalidateQueries({ queryKey: keys.records(entityId) });
|
|
232
|
+
queryClient.invalidateQueries({ queryKey: keys.recordCount(entityId) });
|
|
233
|
+
},
|
|
234
|
+
...options
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
function useBulkUpdateRecords(sdk, entityId, options) {
|
|
238
|
+
const queryClient = useQueryClient();
|
|
239
|
+
return useMutation({
|
|
240
|
+
mutationFn: (updates) => sdk.eav.records.bulkUpdate(entityId, updates),
|
|
241
|
+
onSuccess: (_data, variables) => {
|
|
242
|
+
queryClient.invalidateQueries({ queryKey: keys.records(entityId) });
|
|
243
|
+
for (const { id } of variables) {
|
|
244
|
+
queryClient.invalidateQueries({
|
|
245
|
+
queryKey: keys.record(entityId, id)
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
...options
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
function useBulkDeleteRecords(sdk, entityId, options) {
|
|
253
|
+
const queryClient = useQueryClient();
|
|
254
|
+
return useMutation({
|
|
255
|
+
mutationFn: (ids) => sdk.eav.records.bulkDelete(entityId, ids),
|
|
256
|
+
onSuccess: () => {
|
|
257
|
+
queryClient.invalidateQueries({ queryKey: keys.records(entityId) });
|
|
258
|
+
queryClient.invalidateQueries({ queryKey: keys.recordCount(entityId) });
|
|
259
|
+
},
|
|
260
|
+
...options
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
function useDeleteRecordsWhere(sdk, entityId, options) {
|
|
264
|
+
const queryClient = useQueryClient();
|
|
265
|
+
return useMutation({
|
|
266
|
+
mutationFn: (input) => sdk.eav.records.deleteWhere(entityId, input),
|
|
267
|
+
onSuccess: () => {
|
|
268
|
+
queryClient.invalidateQueries({ queryKey: keys.records(entityId) });
|
|
269
|
+
queryClient.invalidateQueries({ queryKey: keys.recordCount(entityId) });
|
|
270
|
+
},
|
|
271
|
+
...options
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
function useAiCredits(sdk, options) {
|
|
275
|
+
return useQuery({
|
|
276
|
+
queryKey: keys.aiCredits(sdk.config.brandappId),
|
|
277
|
+
queryFn: () => sdk.ai.credits(),
|
|
278
|
+
staleTime: 30 * 1e3,
|
|
279
|
+
// 30초 — 크레딧은 자주 변동
|
|
280
|
+
...options
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
function useAiModels(sdk, options) {
|
|
284
|
+
return useQuery({
|
|
285
|
+
queryKey: keys.aiModels(sdk.config.brandappId),
|
|
286
|
+
queryFn: () => sdk.ai.models(),
|
|
287
|
+
staleTime: 5 * 60 * 1e3,
|
|
288
|
+
// 5분 — 모델 목록은 자주 안 바뀜
|
|
289
|
+
...options
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
function useAiAgents(sdk, options) {
|
|
293
|
+
return useQuery({
|
|
294
|
+
queryKey: keys.aiAgents(sdk.config.brandappId),
|
|
295
|
+
queryFn: () => sdk.ai.agents(),
|
|
296
|
+
staleTime: 5 * 60 * 1e3,
|
|
297
|
+
// 5분 — 에이전트 목록은 자주 안 바뀜
|
|
298
|
+
...options
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
function useAiCompletion(sdk, options) {
|
|
302
|
+
const queryClient = useQueryClient();
|
|
303
|
+
return useMutation({
|
|
304
|
+
mutationFn: (input) => sdk.ai.complete(input),
|
|
305
|
+
...options,
|
|
306
|
+
// 크레딧이 차감됐으므로 잔액 쿼리를 무효화(배지 즉시 갱신). caller onSuccess 병합.
|
|
307
|
+
onSuccess: (...args) => {
|
|
308
|
+
queryClient.invalidateQueries({
|
|
309
|
+
queryKey: keys.aiCredits(sdk.config.brandappId)
|
|
310
|
+
});
|
|
311
|
+
return options?.onSuccess?.(...args);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
function useAiImageGenerate(sdk, options) {
|
|
316
|
+
const queryClient = useQueryClient();
|
|
317
|
+
return useMutation({
|
|
318
|
+
mutationFn: (input) => sdk.ai.generateImage(input),
|
|
319
|
+
...options,
|
|
320
|
+
onSuccess: (...args) => {
|
|
321
|
+
queryClient.invalidateQueries({
|
|
322
|
+
queryKey: keys.aiCredits(sdk.config.brandappId)
|
|
323
|
+
});
|
|
324
|
+
return options?.onSuccess?.(...args);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
function usePostList(sdk, query, options) {
|
|
329
|
+
return useQuery({
|
|
330
|
+
queryKey: keys.posts(sdk.config.brandappId, query),
|
|
331
|
+
queryFn: () => sdk.cms.posts.list(query),
|
|
332
|
+
...options
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
function usePost(sdk, postId, options) {
|
|
336
|
+
return useQuery({
|
|
337
|
+
queryKey: keys.post(postId),
|
|
338
|
+
queryFn: () => sdk.cms.posts.get(postId),
|
|
339
|
+
enabled: !!postId,
|
|
340
|
+
...options
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
function usePostGroupList(sdk, query, options) {
|
|
344
|
+
return useQuery({
|
|
345
|
+
queryKey: keys.postGroups(sdk.config.brandappId, query),
|
|
346
|
+
queryFn: () => sdk.cms.postGroups.list(query),
|
|
347
|
+
...options
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
function usePostGroup(sdk, groupId, options) {
|
|
351
|
+
return useQuery({
|
|
352
|
+
queryKey: keys.postGroup(groupId),
|
|
353
|
+
queryFn: () => sdk.cms.postGroups.get(groupId),
|
|
354
|
+
enabled: !!groupId,
|
|
355
|
+
...options
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
function usePostBySlug(sdk, slug, opts, options) {
|
|
359
|
+
return useQuery({
|
|
360
|
+
queryKey: [
|
|
361
|
+
...keys.all,
|
|
362
|
+
"postBySlug",
|
|
363
|
+
sdk.config.brandappId,
|
|
364
|
+
slug,
|
|
365
|
+
opts
|
|
366
|
+
],
|
|
367
|
+
queryFn: () => sdk.cms.posts.getBySlug(slug, opts),
|
|
368
|
+
enabled: !!slug,
|
|
369
|
+
...options
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
function useCmsTags(sdk, query, options) {
|
|
373
|
+
return useQuery({
|
|
374
|
+
queryKey: keys.tags(sdk.config.brandappId, query),
|
|
375
|
+
queryFn: () => sdk.cms.tags.list(query),
|
|
376
|
+
...options
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
function useFiles(sdk, query, options) {
|
|
380
|
+
return useQuery({
|
|
381
|
+
queryKey: keys.files(sdk.config.brandappId, query),
|
|
382
|
+
queryFn: () => sdk.files.list(query),
|
|
383
|
+
...options
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
function useFile(sdk, fileId, options) {
|
|
387
|
+
return useQuery({
|
|
388
|
+
queryKey: keys.file(fileId),
|
|
389
|
+
queryFn: () => sdk.files.get(fileId),
|
|
390
|
+
enabled: !!fileId,
|
|
391
|
+
...options
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
function useDeleteFile(sdk, options) {
|
|
395
|
+
const queryClient = useQueryClient();
|
|
396
|
+
return useMutation({
|
|
397
|
+
mutationFn: (fileId) => sdk.files.delete(fileId),
|
|
398
|
+
onSuccess: () => {
|
|
399
|
+
queryClient.invalidateQueries({
|
|
400
|
+
queryKey: keys.files(sdk.config.brandappId)
|
|
401
|
+
});
|
|
402
|
+
},
|
|
403
|
+
...options
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
function useUploadFile(sdk, options) {
|
|
407
|
+
const queryClient = useQueryClient();
|
|
408
|
+
return useMutation({
|
|
409
|
+
mutationFn: (input) => sdk.files.upload(input.file, input.options),
|
|
410
|
+
onSuccess: () => {
|
|
411
|
+
queryClient.invalidateQueries({
|
|
412
|
+
queryKey: keys.files(sdk.config.brandappId)
|
|
413
|
+
});
|
|
414
|
+
},
|
|
415
|
+
...options
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
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
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { q as ReoptSDKConfig } from '../config-CtxyJsDR.js';
|
|
2
|
+
import { L as ListTermsOptions, T as TermsItem, f as TermsListResponse, a as ConsentRecord, c as CreateConsentsRequest, d as CreateConsentsResult, W as WithdrawConsentResult } from '../types-DskYLVb8.js';
|
|
3
|
+
export { C as ConsentInput, b as ConsentStatus, e as TermsJurisdiction, g as TermsType, h as TermsVersion } from '../types-DskYLVb8.js';
|
|
4
|
+
import '../types-ckmDDW3N.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Brandapp Terms client.
|
|
8
|
+
*
|
|
9
|
+
* Lets a Brandapp fetch the agreements it has defined and record/withdraw a
|
|
10
|
+
* signed-in user's consent.
|
|
11
|
+
*
|
|
12
|
+
* - `list()` — public-ish (Basic or Bearer). Returns active terms with the
|
|
13
|
+
* currently-published version body so the caller can render them.
|
|
14
|
+
* - `listMyConsents(accessToken)` — Bearer. The user's consent history.
|
|
15
|
+
* - `consent(input, accessToken)` — Bearer. Batch-creates `granted` records.
|
|
16
|
+
* - `withdraw(consentId, accessToken)` — Bearer. Soft-revokes one record.
|
|
17
|
+
* The server rejects withdrawal of consents tied to required terms.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const sdk = createReoptSDK({ clientId, clientSecret, brandappId });
|
|
22
|
+
*
|
|
23
|
+
* // Render the agreements (no user context required):
|
|
24
|
+
* const terms = await sdk.terms.list();
|
|
25
|
+
*
|
|
26
|
+
* // After the user signs in via OAuth:
|
|
27
|
+
* await sdk.terms.consent(
|
|
28
|
+
* { consents: terms.map((t) => ({ versionId: t.currentVersion!.id, consented: true })) },
|
|
29
|
+
* accessToken,
|
|
30
|
+
* );
|
|
31
|
+
*
|
|
32
|
+
* const mine = await sdk.terms.listMyConsents(accessToken);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
declare class ReoptTermsClient {
|
|
37
|
+
private readonly http;
|
|
38
|
+
constructor(config: ReoptSDKConfig);
|
|
39
|
+
/**
|
|
40
|
+
* List active terms for this Brandapp with their currently-published
|
|
41
|
+
* version. Works with either Basic Auth (default) or Bearer Auth — when
|
|
42
|
+
* called from a server handler that has the user's access token, pass
|
|
43
|
+
* `accessToken` to avoid sending app credentials.
|
|
44
|
+
*
|
|
45
|
+
* Accepts either an `accessToken` string (legacy) or an options object
|
|
46
|
+
* (`country`/`locale`/`jurisdiction`/`accessToken`) for jurisdiction-aware
|
|
47
|
+
* matching. When `country` / `locale` are omitted, the server falls back to
|
|
48
|
+
* request headers (`x-vercel-ip-country`, `Accept-Language`).
|
|
49
|
+
*
|
|
50
|
+
* Returns the matched terms array. For matching metadata
|
|
51
|
+
* (jurisdiction, locale, source) use {@link listWithMeta}.
|
|
52
|
+
*/
|
|
53
|
+
list(optionsOrToken?: string | ListTermsOptions): Promise<TermsItem[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Same as {@link list} but returns the full {@link TermsListResponse} including
|
|
56
|
+
* matched jurisdiction, country and locale — useful for displaying "약관이
|
|
57
|
+
* 어떤 국가 기준으로 적용됐는지" hint in the signup UX.
|
|
58
|
+
*/
|
|
59
|
+
listWithMeta(optionsOrToken?: string | ListTermsOptions): Promise<TermsListResponse>;
|
|
60
|
+
/**
|
|
61
|
+
* Fetch the consent history (granted / withdrawn / pendingReConsent) for
|
|
62
|
+
* the OAuth user represented by `accessToken`.
|
|
63
|
+
*/
|
|
64
|
+
listMyConsents(accessToken: string): Promise<ConsentRecord[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Record consent for one or more terms versions. The server rejects the
|
|
67
|
+
* call with `REQUIRED_NOT_CONSENTED` (422) if any required term is missing
|
|
68
|
+
* or marked as `consented: false`.
|
|
69
|
+
*/
|
|
70
|
+
consent(input: CreateConsentsRequest, accessToken: string): Promise<CreateConsentsResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Withdraw a previously-granted consent. The server returns 409 for
|
|
73
|
+
* required terms or already-withdrawn records.
|
|
74
|
+
*/
|
|
75
|
+
withdraw(consentId: string, accessToken: string): Promise<WithdrawConsentResult>;
|
|
76
|
+
}
|
|
77
|
+
declare function createReoptTermsClient(config: ReoptSDKConfig): ReoptTermsClient;
|
|
78
|
+
|
|
79
|
+
export { ConsentRecord, CreateConsentsRequest, CreateConsentsResult, ListTermsOptions, ReoptTermsClient, TermsItem, TermsListResponse, WithdrawConsentResult, createReoptTermsClient };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { DevSchema, SeedData, SeedAllInput, SeedPostGroupInput, SeedPostInput, SeedTermsItem, DevServer } from '../dev/index.js';
|
|
2
|
+
import { ReoptSDK } from '../index.js';
|
|
3
|
+
import '../types-ckmDDW3N.js';
|
|
4
|
+
import '../types-DskYLVb8.js';
|
|
5
|
+
import '../terms/index.js';
|
|
6
|
+
import '../config-CtxyJsDR.js';
|
|
7
|
+
import '../push/index.js';
|
|
8
|
+
import '../plans/index.js';
|
|
9
|
+
import '../client-CN5_tNOC.js';
|
|
10
|
+
import '../feedback/index.js';
|
|
11
|
+
import '../client-DttyeM_h.js';
|
|
12
|
+
import '../ai/index.js';
|
|
13
|
+
import '../errors-5hd5ZR-M.js';
|
|
14
|
+
import '../typed-client-BxOVIiMU.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @reopt-ai/brandapp-sdk/testing
|
|
18
|
+
*
|
|
19
|
+
* Test utilities for BrandApp consumer projects.
|
|
20
|
+
* Provides isolated dev server instances per test suite.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { createTestSDK } from "@reopt-ai/brandapp-sdk/testing";
|
|
25
|
+
* import { describe, it, expect, beforeEach, afterAll } from "vitest";
|
|
26
|
+
*
|
|
27
|
+
* const schema = {
|
|
28
|
+
* entities: {
|
|
29
|
+
* contacts: {
|
|
30
|
+
* attributes: {
|
|
31
|
+
* name: { label: "Name", dataType: "text" },
|
|
32
|
+
* email: { label: "Email", dataType: "text" },
|
|
33
|
+
* },
|
|
34
|
+
* },
|
|
35
|
+
* },
|
|
36
|
+
* };
|
|
37
|
+
*
|
|
38
|
+
* describe("contacts", () => {
|
|
39
|
+
* const { sdk, devServer } = await createTestSDK({ schema });
|
|
40
|
+
*
|
|
41
|
+
* beforeEach(async () => {
|
|
42
|
+
* await devServer.reset();
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* afterAll(async () => {
|
|
46
|
+
* await devServer.close();
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* it("creates a contact", async () => {
|
|
50
|
+
* const entities = await sdk.eav.entities.list();
|
|
51
|
+
* expect(entities.length).toBeGreaterThan(0);
|
|
52
|
+
* });
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
type TestSDKOptions = {
|
|
58
|
+
/** EAV schema to seed entities and attributes */
|
|
59
|
+
schema?: DevSchema;
|
|
60
|
+
/** BrandApp ID (default: "test-brandapp") */
|
|
61
|
+
brandappId?: string;
|
|
62
|
+
/** EAV records initial seed (backward-compat). Use `seedAll` for posts/terms. */
|
|
63
|
+
seed?: SeedData;
|
|
64
|
+
/** Unified initial seed (postGroups, posts, entities, terms). Runs after `seed`. */
|
|
65
|
+
seedAll?: SeedAllInput;
|
|
66
|
+
/** Convenience shortcut — equivalent to `seedAll: { postGroups }`. */
|
|
67
|
+
postGroups?: SeedPostGroupInput[];
|
|
68
|
+
/** Convenience shortcut — equivalent to `seedAll: { posts }`. */
|
|
69
|
+
posts?: SeedPostInput[];
|
|
70
|
+
/** Convenience shortcut — equivalent to `seedAll: { terms }`. */
|
|
71
|
+
terms?: SeedTermsItem[];
|
|
72
|
+
};
|
|
73
|
+
type TestSDKResult = {
|
|
74
|
+
/** Pre-configured SDK instance pointing to the test server */
|
|
75
|
+
sdk: ReoptSDK;
|
|
76
|
+
/** The underlying dev server (for seed/reset/snapshot/restore) */
|
|
77
|
+
devServer: DevServer;
|
|
78
|
+
/** Base URL of the test server */
|
|
79
|
+
url: string;
|
|
80
|
+
/**
|
|
81
|
+
* Reset server data AND recreate the SDK (clears client-side caches).
|
|
82
|
+
* Use this in `beforeEach` instead of `devServer.reset()`.
|
|
83
|
+
*/
|
|
84
|
+
resetAll: () => Promise<void>;
|
|
85
|
+
};
|
|
86
|
+
type TestServerOptions = {
|
|
87
|
+
/** EAV schema to seed */
|
|
88
|
+
schema?: DevSchema;
|
|
89
|
+
/** BrandApp ID (default: "test-brandapp") */
|
|
90
|
+
brandappId?: string;
|
|
91
|
+
/** Initial seed data */
|
|
92
|
+
seed?: SeedData;
|
|
93
|
+
};
|
|
94
|
+
type TestServerResult = {
|
|
95
|
+
/** The dev server instance */
|
|
96
|
+
devServer: DevServer;
|
|
97
|
+
/** Base URL */
|
|
98
|
+
url: string;
|
|
99
|
+
/** Port */
|
|
100
|
+
port: number;
|
|
101
|
+
/** SDK config ready to pass to createReoptSDK */
|
|
102
|
+
sdkConfig: {
|
|
103
|
+
clientId: string;
|
|
104
|
+
clientSecret: string;
|
|
105
|
+
brandappId: string;
|
|
106
|
+
baseUrl: string;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Create an isolated test SDK with its own dev server.
|
|
111
|
+
* Each call spins up a new server on a random port.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* const { sdk, devServer } = await createTestSDK({ schema });
|
|
116
|
+
* // use sdk.eav, sdk.ai, sdk.files, etc.
|
|
117
|
+
* await devServer.close(); // cleanup
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
declare function createTestSDK(options?: TestSDKOptions): Promise<TestSDKResult>;
|
|
121
|
+
/**
|
|
122
|
+
* Create an isolated test server without an SDK instance.
|
|
123
|
+
* Useful when you need more control over SDK configuration.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* const { devServer, sdkConfig } = await createTestServer({ schema });
|
|
128
|
+
* const sdk = createReoptSDK({ ...sdkConfig, debug: true });
|
|
129
|
+
* await devServer.close();
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
declare function createTestServer(options?: TestServerOptions): Promise<TestServerResult>;
|
|
133
|
+
/**
|
|
134
|
+
* Create a fixture factory for repeated test data patterns.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* const fixture = createFixture({
|
|
139
|
+
* contacts: (overrides) => ({
|
|
140
|
+
* values: { name: "Test User", email: "test@example.com", ...overrides },
|
|
141
|
+
* }),
|
|
142
|
+
* });
|
|
143
|
+
*
|
|
144
|
+
* await devServer.seed({
|
|
145
|
+
* contacts: [fixture.contacts(), fixture.contacts({ name: "Alice" })],
|
|
146
|
+
* });
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
declare function createFixture<T extends Record<string, (overrides?: Record<string, unknown>) => {
|
|
150
|
+
authUserId?: string;
|
|
151
|
+
values: Record<string, unknown>;
|
|
152
|
+
}>>(factories: T): T;
|
|
153
|
+
|
|
154
|
+
export { DevSchema, DevServer, SeedAllInput, SeedData, SeedPostGroupInput, SeedPostInput, SeedTermsItem, type TestSDKOptions, type TestSDKResult, type TestServerOptions, type TestServerResult, createFixture, createTestSDK, createTestServer };
|