@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,350 @@
|
|
|
1
|
+
import { parseSSEStream } from './chunk-L4DHB36G.js';
|
|
2
|
+
import { createManagedAbort } from './chunk-F7BXBTZI.js';
|
|
3
|
+
import { BaseHttpClient } from './chunk-DI6QJPTQ.js';
|
|
4
|
+
import { validateConfig, ReoptSDKError, mapHttpStatusToError, SDK_VERSION } from './chunk-J5Y2GSJF.js';
|
|
5
|
+
|
|
6
|
+
// src/ai/client.ts
|
|
7
|
+
var ReoptAiClient = class {
|
|
8
|
+
http;
|
|
9
|
+
/**
|
|
10
|
+
* Idle (inactivity) timeout for streaming, in ms — the maximum gap allowed
|
|
11
|
+
* *between* SSE chunks, not a deadline on the whole generation. A long but
|
|
12
|
+
* healthy generation keeps resetting this; only a genuine stall aborts.
|
|
13
|
+
*/
|
|
14
|
+
streamIdleTimeout;
|
|
15
|
+
constructor(config) {
|
|
16
|
+
validateConfig(config);
|
|
17
|
+
const pathPrefix = `/api/v1/brandapp/${config.brandappId}/ai`;
|
|
18
|
+
this.http = new BaseHttpClient(config, pathPrefix);
|
|
19
|
+
this.streamIdleTimeout = config.timeout ?? 6e4;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* AI 텍스트 생성 (non-streaming)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const result = await sdk.ai.complete({
|
|
27
|
+
* messages: [{ role: "user", content: "Hello" }],
|
|
28
|
+
* model: "anthropic/claude-haiku-4.5",
|
|
29
|
+
* maxTokens: 1024,
|
|
30
|
+
* });
|
|
31
|
+
* console.log(result.message.content);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
async complete(options) {
|
|
35
|
+
const response = await this.http.fetch(
|
|
36
|
+
"POST",
|
|
37
|
+
"/chat/completions",
|
|
38
|
+
{
|
|
39
|
+
model: options.model,
|
|
40
|
+
agentId: options.agentId,
|
|
41
|
+
messages: options.messages,
|
|
42
|
+
maxTokens: options.maxTokens,
|
|
43
|
+
temperature: options.temperature,
|
|
44
|
+
stream: false,
|
|
45
|
+
customerId: options.customerId
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
return response.data;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* AI 텍스트 생성 (SSE 스트리밍)
|
|
52
|
+
*
|
|
53
|
+
* async generator로 텍스트 청크를 반환합니다.
|
|
54
|
+
* 사용량 메타데이터가 필요하면 `streamWithMetadata()`를 사용하세요.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* for await (const chunk of sdk.ai.stream({
|
|
59
|
+
* messages: [{ role: "user", content: "Hello" }],
|
|
60
|
+
* })) {
|
|
61
|
+
* process.stdout.write(chunk);
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
async *stream(options) {
|
|
66
|
+
const { response, managed, requestId } = await this.fetchSSE(options);
|
|
67
|
+
if (!response.body) {
|
|
68
|
+
managed.cleanup();
|
|
69
|
+
throw new ReoptSDKError("No response body", 0, "STREAM_ERROR");
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
for await (const { event, data } of parseSSEStream(response.body)) {
|
|
73
|
+
managed.kick();
|
|
74
|
+
if (event === "text-delta") {
|
|
75
|
+
yield data;
|
|
76
|
+
} else if (event === "error") {
|
|
77
|
+
const ctx = { requestId };
|
|
78
|
+
try {
|
|
79
|
+
const err = JSON.parse(data);
|
|
80
|
+
if (typeof err.status === "number") {
|
|
81
|
+
throw mapHttpStatusToError(
|
|
82
|
+
err.status,
|
|
83
|
+
err.code,
|
|
84
|
+
err.message,
|
|
85
|
+
ctx
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
throw new ReoptSDKError(
|
|
89
|
+
err.message ?? "Stream error",
|
|
90
|
+
0,
|
|
91
|
+
err.code ?? "STREAM_ERROR",
|
|
92
|
+
ctx
|
|
93
|
+
);
|
|
94
|
+
} catch (e) {
|
|
95
|
+
if (e instanceof ReoptSDKError) throw e;
|
|
96
|
+
throw new ReoptSDKError(data, 0, "STREAM_ERROR", ctx);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} catch (e) {
|
|
101
|
+
throw mapStreamError(e, managed);
|
|
102
|
+
} finally {
|
|
103
|
+
managed.cleanup();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* AI 텍스트 생성 (SSE 스트리밍 + 메타데이터)
|
|
108
|
+
*
|
|
109
|
+
* 텍스트 청크와 함께 최종 사용량/크레딧 메타데이터를 반환합니다.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const { textStream, metadata } = sdk.ai.streamWithMetadata({
|
|
114
|
+
* messages: [{ role: "user", content: "Hello" }],
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* let text = "";
|
|
118
|
+
* for await (const chunk of textStream) {
|
|
119
|
+
* text += chunk;
|
|
120
|
+
* }
|
|
121
|
+
*
|
|
122
|
+
* const meta = await metadata;
|
|
123
|
+
* console.log(`사용 크레딧: ${meta?.usage.creditCost}`);
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
streamWithMetadata(options) {
|
|
127
|
+
let resolveMeta;
|
|
128
|
+
const metadata = new Promise((r) => {
|
|
129
|
+
resolveMeta = r;
|
|
130
|
+
});
|
|
131
|
+
let settled = false;
|
|
132
|
+
const settle = (v) => {
|
|
133
|
+
if (settled) return;
|
|
134
|
+
settled = true;
|
|
135
|
+
resolveMeta(v);
|
|
136
|
+
};
|
|
137
|
+
const self = this;
|
|
138
|
+
async function* gen() {
|
|
139
|
+
const { response, managed, requestId } = await self.fetchSSE(options);
|
|
140
|
+
if (!response.body) {
|
|
141
|
+
managed.cleanup();
|
|
142
|
+
settle(null);
|
|
143
|
+
throw new ReoptSDKError("No response body", 0, "STREAM_ERROR");
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
for await (const { event, data } of parseSSEStream(response.body)) {
|
|
147
|
+
managed.kick();
|
|
148
|
+
if (event === "text-delta") {
|
|
149
|
+
yield data;
|
|
150
|
+
} else if (event === "done") {
|
|
151
|
+
try {
|
|
152
|
+
settle(JSON.parse(data));
|
|
153
|
+
} catch {
|
|
154
|
+
settle(null);
|
|
155
|
+
}
|
|
156
|
+
} else if (event === "error") {
|
|
157
|
+
const ctx = { requestId };
|
|
158
|
+
try {
|
|
159
|
+
const err = JSON.parse(data);
|
|
160
|
+
if (typeof err.status === "number") {
|
|
161
|
+
throw mapHttpStatusToError(
|
|
162
|
+
err.status,
|
|
163
|
+
err.code,
|
|
164
|
+
err.message,
|
|
165
|
+
ctx
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
throw new ReoptSDKError(
|
|
169
|
+
err.message ?? "Stream error",
|
|
170
|
+
0,
|
|
171
|
+
err.code ?? "STREAM_ERROR",
|
|
172
|
+
ctx
|
|
173
|
+
);
|
|
174
|
+
} catch (e) {
|
|
175
|
+
if (e instanceof ReoptSDKError) throw e;
|
|
176
|
+
throw new ReoptSDKError(data, 0, "STREAM_ERROR", ctx);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
} catch (e) {
|
|
181
|
+
throw mapStreamError(e, managed);
|
|
182
|
+
} finally {
|
|
183
|
+
settle(null);
|
|
184
|
+
managed.cleanup();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return { textStream: gen(), metadata };
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* 이미지 생성
|
|
191
|
+
*
|
|
192
|
+
* BrandApp의 AI 크레딧으로 이미지를 생성합니다.
|
|
193
|
+
* 생성된 이미지는 자동으로 Vercel Blob에 저장되고 URL이 반환됩니다.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* const image = await sdk.ai.generateImage({
|
|
198
|
+
* prompt: "브랜드 배너 이미지",
|
|
199
|
+
* style: "minimalist",
|
|
200
|
+
* aspectRatio: "16:9",
|
|
201
|
+
* });
|
|
202
|
+
* console.log(image.url); // https://...blob.vercel-storage.com/...
|
|
203
|
+
* console.log(image.size); // 12345 (bytes)
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
async generateImage(options) {
|
|
207
|
+
const response = await this.http.fetch(
|
|
208
|
+
"POST",
|
|
209
|
+
"/images/generate",
|
|
210
|
+
{
|
|
211
|
+
prompt: options.prompt,
|
|
212
|
+
negativePrompt: options.negativePrompt,
|
|
213
|
+
style: options.style,
|
|
214
|
+
aspectRatio: options.aspectRatio ?? "1:1",
|
|
215
|
+
model: options.model,
|
|
216
|
+
customerId: options.customerId
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
return response.data;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* 크레딧 잔액 조회
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* const credits = await sdk.ai.credits();
|
|
227
|
+
* console.log(`${credits.balance} / ${credits.limit} (${credits.status})`);
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
async credits() {
|
|
231
|
+
const response = await this.http.fetch(
|
|
232
|
+
"GET",
|
|
233
|
+
"/credits"
|
|
234
|
+
);
|
|
235
|
+
return response.data;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* 사용 가능 모델 목록 조회
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* const models = await sdk.ai.models();
|
|
243
|
+
* models.forEach(m => console.log(`${m.id} (${m.tierLabel})`));
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
async models() {
|
|
247
|
+
const response = await this.http.fetch(
|
|
248
|
+
"GET",
|
|
249
|
+
"/models"
|
|
250
|
+
);
|
|
251
|
+
return response.data;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* 사용 가능한 커스텀 에이전트 목록 조회
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```ts
|
|
258
|
+
* const agents = await sdk.ai.agents();
|
|
259
|
+
* for (const agent of agents) {
|
|
260
|
+
* console.log(`${agent.name}: ${agent.description}`);
|
|
261
|
+
* }
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
async agents() {
|
|
265
|
+
const response = await this.http.fetch(
|
|
266
|
+
"GET",
|
|
267
|
+
"/agents"
|
|
268
|
+
);
|
|
269
|
+
return response.data;
|
|
270
|
+
}
|
|
271
|
+
// ---------------------------------------------------------------------------
|
|
272
|
+
// Internal: SSE fetch (BaseHttpClient는 JSON 전용이므로 직접 fetch)
|
|
273
|
+
// ---------------------------------------------------------------------------
|
|
274
|
+
async fetchSSE(options) {
|
|
275
|
+
const url = `${this.http.requestBaseUrl}/chat/completions`;
|
|
276
|
+
const requestId = globalThis.crypto?.randomUUID?.() ?? `sdk-${SDK_VERSION}-${url.length}`;
|
|
277
|
+
const ctx = { method: "POST", url, requestId };
|
|
278
|
+
const maxConnectAttempts = 2;
|
|
279
|
+
let lastConnectError;
|
|
280
|
+
for (let attempt = 0; attempt < maxConnectAttempts; attempt++) {
|
|
281
|
+
const managed = createManagedAbort({
|
|
282
|
+
timeoutMs: this.streamIdleTimeout,
|
|
283
|
+
external: options.signal,
|
|
284
|
+
idle: true
|
|
285
|
+
});
|
|
286
|
+
try {
|
|
287
|
+
const response = await globalThis.fetch(url, {
|
|
288
|
+
method: "POST",
|
|
289
|
+
headers: {
|
|
290
|
+
Authorization: this.http.authorizationHeader,
|
|
291
|
+
"Content-Type": "application/json",
|
|
292
|
+
Accept: "text/event-stream",
|
|
293
|
+
"X-SDK-Version": `brandapp-sdk/${SDK_VERSION}`,
|
|
294
|
+
"X-Request-Id": requestId,
|
|
295
|
+
"Idempotency-Key": requestId
|
|
296
|
+
},
|
|
297
|
+
body: JSON.stringify({
|
|
298
|
+
model: options.model,
|
|
299
|
+
agentId: options.agentId,
|
|
300
|
+
messages: options.messages,
|
|
301
|
+
maxTokens: options.maxTokens,
|
|
302
|
+
temperature: options.temperature,
|
|
303
|
+
stream: true,
|
|
304
|
+
customerId: options.customerId
|
|
305
|
+
}),
|
|
306
|
+
signal: managed.signal
|
|
307
|
+
});
|
|
308
|
+
if (!response.ok) {
|
|
309
|
+
const body = await response.json().catch(() => ({}));
|
|
310
|
+
const err = body?.error ?? {};
|
|
311
|
+
managed.cleanup();
|
|
312
|
+
throw mapHttpStatusToError(
|
|
313
|
+
response.status,
|
|
314
|
+
err.code,
|
|
315
|
+
err.message ?? `HTTP ${response.status}`,
|
|
316
|
+
ctx
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
return { response, managed, requestId };
|
|
320
|
+
} catch (e) {
|
|
321
|
+
managed.cleanup();
|
|
322
|
+
if (e instanceof ReoptSDKError) throw e;
|
|
323
|
+
if (managed.timedOut || options.signal?.aborted) {
|
|
324
|
+
throw mapStreamError(e, managed);
|
|
325
|
+
}
|
|
326
|
+
lastConnectError = e;
|
|
327
|
+
if (attempt < maxConnectAttempts - 1) continue;
|
|
328
|
+
throw mapStreamError(e, managed);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
throw mapStreamError(lastConnectError, void 0);
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
function mapStreamError(e, managed) {
|
|
335
|
+
if (e instanceof ReoptSDKError) return e;
|
|
336
|
+
if (e instanceof Error && e.name === "AbortError") {
|
|
337
|
+
if (managed?.timedOut) {
|
|
338
|
+
return new ReoptSDKError("Stream request timed out", 408, "TIMEOUT");
|
|
339
|
+
}
|
|
340
|
+
return new ReoptSDKError("Stream cancelled by caller", 0, "CANCELLED");
|
|
341
|
+
}
|
|
342
|
+
return e;
|
|
343
|
+
}
|
|
344
|
+
function createReoptAiClient(config) {
|
|
345
|
+
return new ReoptAiClient(config);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export { ReoptAiClient, createReoptAiClient };
|
|
349
|
+
//# sourceMappingURL=chunk-KU2LN5SE.js.map
|
|
350
|
+
//# sourceMappingURL=chunk-KU2LN5SE.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// src/core/sse-parser.ts
|
|
2
|
+
function createSSELineProcessor(onEvent) {
|
|
3
|
+
let buffer = "";
|
|
4
|
+
let currentEvent = "";
|
|
5
|
+
let dataBuffer = "";
|
|
6
|
+
function processLine(line) {
|
|
7
|
+
const stripped = line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
8
|
+
if (stripped.startsWith("event:")) {
|
|
9
|
+
const raw = stripped.slice(6);
|
|
10
|
+
currentEvent = raw.startsWith(" ") ? raw.slice(1) : raw;
|
|
11
|
+
} else if (stripped.startsWith("data:")) {
|
|
12
|
+
const raw = stripped.slice(5);
|
|
13
|
+
const data = raw.startsWith(" ") ? raw.slice(1) : raw;
|
|
14
|
+
dataBuffer = dataBuffer ? dataBuffer + "\n" + data : data;
|
|
15
|
+
} else if (stripped === "") {
|
|
16
|
+
if (dataBuffer) {
|
|
17
|
+
onEvent({ event: currentEvent, data: dataBuffer });
|
|
18
|
+
}
|
|
19
|
+
currentEvent = "";
|
|
20
|
+
dataBuffer = "";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
feed(chunk) {
|
|
25
|
+
buffer += chunk;
|
|
26
|
+
const lines = buffer.split("\n");
|
|
27
|
+
buffer = lines.pop() ?? "";
|
|
28
|
+
for (const line of lines) processLine(line);
|
|
29
|
+
},
|
|
30
|
+
/**
|
|
31
|
+
* Flush any buffered input at stream end.
|
|
32
|
+
* Processes the last partial line (if any) and emits a final event
|
|
33
|
+
* if a data buffer is still pending.
|
|
34
|
+
*/
|
|
35
|
+
flush() {
|
|
36
|
+
if (buffer.length > 0) {
|
|
37
|
+
processLine(buffer);
|
|
38
|
+
buffer = "";
|
|
39
|
+
}
|
|
40
|
+
if (dataBuffer) {
|
|
41
|
+
onEvent({ event: currentEvent, data: dataBuffer });
|
|
42
|
+
currentEvent = "";
|
|
43
|
+
dataBuffer = "";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async function* parseSSEStream(body) {
|
|
49
|
+
const reader = body.getReader();
|
|
50
|
+
const decoder = new TextDecoder();
|
|
51
|
+
const pending = [];
|
|
52
|
+
const processor = createSSELineProcessor((event) => {
|
|
53
|
+
pending.push(event);
|
|
54
|
+
});
|
|
55
|
+
try {
|
|
56
|
+
while (true) {
|
|
57
|
+
const { done, value } = await reader.read();
|
|
58
|
+
if (done) break;
|
|
59
|
+
processor.feed(decoder.decode(value, { stream: true }));
|
|
60
|
+
while (pending.length > 0) {
|
|
61
|
+
yield pending.shift();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
processor.flush();
|
|
65
|
+
while (pending.length > 0) {
|
|
66
|
+
yield pending.shift();
|
|
67
|
+
}
|
|
68
|
+
} finally {
|
|
69
|
+
reader.releaseLock();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { createSSELineProcessor, parseSSEStream };
|
|
74
|
+
//# sourceMappingURL=chunk-L4DHB36G.js.map
|
|
75
|
+
//# sourceMappingURL=chunk-L4DHB36G.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { BaseHttpClient } from './chunk-DI6QJPTQ.js';
|
|
2
|
+
|
|
3
|
+
// src/auth/client.ts
|
|
4
|
+
function unwrap(body) {
|
|
5
|
+
if (body && typeof body === "object" && "data" in body) {
|
|
6
|
+
const withData = body;
|
|
7
|
+
if (withData.data !== void 0) return withData.data;
|
|
8
|
+
}
|
|
9
|
+
return body;
|
|
10
|
+
}
|
|
11
|
+
var ReoptAuthClient = class {
|
|
12
|
+
/**
|
|
13
|
+
* Root client for `/api/auth/*` endpoints (OIDC userinfo, etc). Pinned to
|
|
14
|
+
* the id server because Better Auth's handler is only mounted there.
|
|
15
|
+
*/
|
|
16
|
+
rootHttp;
|
|
17
|
+
/** Brandapp-scoped client — prefixed for per-brandapp endpoints. */
|
|
18
|
+
brandappHttp;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.rootHttp = new BaseHttpClient(config, "", { useIdServer: true });
|
|
21
|
+
this.brandappHttp = new BaseHttpClient(
|
|
22
|
+
config,
|
|
23
|
+
`/api/v1/brandapp/${config.brandappId}`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Upsert the Customer ↔ reoptUser link for the OAuth user represented by
|
|
28
|
+
* the supplied access token.
|
|
29
|
+
*/
|
|
30
|
+
async linkCurrentUser(accessToken) {
|
|
31
|
+
const body = await this.brandappHttp.fetch("POST", "/external-auth", {}, { bearerToken: accessToken });
|
|
32
|
+
return unwrap(body);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Soft-withdraw the current OAuth user from this Brandapp: BrandappCustomer
|
|
36
|
+
* flips to `churned`, the Brand↔Customer junction is removed, all
|
|
37
|
+
* terms-consents move to `withdrawn`, and any Stripe subscription is
|
|
38
|
+
* cancelled. The Customer record itself is retained so re-linking later
|
|
39
|
+
* restores the same customerId (see `linkCurrentUser`).
|
|
40
|
+
*/
|
|
41
|
+
async withdrawCurrentUser(accessToken) {
|
|
42
|
+
const body = await this.brandappHttp.fetch("DELETE", "/external-auth", void 0, { bearerToken: accessToken });
|
|
43
|
+
return unwrap(body);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Fetch the OIDC userinfo claims for the supplied access token.
|
|
47
|
+
*/
|
|
48
|
+
async getUserInfo(accessToken) {
|
|
49
|
+
return this.rootHttp.fetch(
|
|
50
|
+
"GET",
|
|
51
|
+
"/api/auth/oauth2/userinfo",
|
|
52
|
+
void 0,
|
|
53
|
+
{ bearerToken: accessToken }
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
function createReoptAuthClient(config) {
|
|
58
|
+
return new ReoptAuthClient(config);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { ReoptAuthClient, createReoptAuthClient };
|
|
62
|
+
//# sourceMappingURL=chunk-PJZB4VP7.js.map
|
|
63
|
+
//# sourceMappingURL=chunk-PJZB4VP7.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// src/better-auth/types.ts
|
|
2
|
+
var REOPT_PROVIDER_ID = "reopt";
|
|
3
|
+
var REOPT_DEFAULT_SCOPES = ["openid", "profile", "email"];
|
|
4
|
+
|
|
5
|
+
export { REOPT_DEFAULT_SCOPES, REOPT_PROVIDER_ID };
|
|
6
|
+
//# sourceMappingURL=chunk-REIKXSMY.js.map
|
|
7
|
+
//# sourceMappingURL=chunk-REIKXSMY.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { BaseHttpClient } from './chunk-DI6QJPTQ.js';
|
|
2
|
+
|
|
3
|
+
// src/plans/client.ts
|
|
4
|
+
function unwrap(body) {
|
|
5
|
+
if (body && typeof body === "object" && "data" in body) {
|
|
6
|
+
const withData = body;
|
|
7
|
+
if (withData.data !== void 0) return withData.data;
|
|
8
|
+
}
|
|
9
|
+
return body;
|
|
10
|
+
}
|
|
11
|
+
var ReoptPlansClient = class {
|
|
12
|
+
http;
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.http = new BaseHttpClient(
|
|
15
|
+
config,
|
|
16
|
+
`/api/v1/brandapp/${config.brandappId}/plans`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* List active plans for this Brandapp (the customer-facing catalog). Works
|
|
21
|
+
* with either Basic Auth (default) or Bearer Auth — pass `accessToken` when
|
|
22
|
+
* calling from a handler that already has the customer's OAuth token to avoid
|
|
23
|
+
* sending app credentials.
|
|
24
|
+
*/
|
|
25
|
+
async list(accessToken) {
|
|
26
|
+
const body = await this.http.fetch(
|
|
27
|
+
"GET",
|
|
28
|
+
"",
|
|
29
|
+
void 0,
|
|
30
|
+
accessToken ? { bearerToken: accessToken } : void 0
|
|
31
|
+
);
|
|
32
|
+
return unwrap(body);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Fetch the current plan / entitlement for the OAuth customer represented by
|
|
36
|
+
* `accessToken`. Returns `null` when the customer has no active plan.
|
|
37
|
+
*/
|
|
38
|
+
async getMyPlan(accessToken) {
|
|
39
|
+
const body = await this.http.fetch(
|
|
40
|
+
"GET",
|
|
41
|
+
"/me/plan",
|
|
42
|
+
void 0,
|
|
43
|
+
{ bearerToken: accessToken }
|
|
44
|
+
);
|
|
45
|
+
return unwrap(body);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
function createReoptPlansClient(config) {
|
|
49
|
+
return new ReoptPlansClient(config);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { ReoptPlansClient, createReoptPlansClient };
|
|
53
|
+
//# sourceMappingURL=chunk-T2WXHAAC.js.map
|
|
54
|
+
//# sourceMappingURL=chunk-T2WXHAAC.js.map
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { BaseHttpClient } from './chunk-DI6QJPTQ.js';
|
|
2
|
+
|
|
3
|
+
// src/terms/client.ts
|
|
4
|
+
function unwrap(body) {
|
|
5
|
+
if (body && typeof body === "object" && "data" in body) {
|
|
6
|
+
const withData = body;
|
|
7
|
+
if (withData.data !== void 0) return withData.data;
|
|
8
|
+
}
|
|
9
|
+
return body;
|
|
10
|
+
}
|
|
11
|
+
function isListOptions(value) {
|
|
12
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
13
|
+
}
|
|
14
|
+
function buildListQuery(options) {
|
|
15
|
+
const params = new URLSearchParams();
|
|
16
|
+
if (options.country) params.set("country", options.country);
|
|
17
|
+
if (options.locale) params.set("locale", options.locale);
|
|
18
|
+
if (options.jurisdiction) params.set("jurisdiction", options.jurisdiction);
|
|
19
|
+
const qs = params.toString();
|
|
20
|
+
return qs ? `?${qs}` : "";
|
|
21
|
+
}
|
|
22
|
+
var ReoptTermsClient = class {
|
|
23
|
+
http;
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.http = new BaseHttpClient(
|
|
26
|
+
config,
|
|
27
|
+
`/api/v1/brandapp/${config.brandappId}/terms`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* List active terms for this Brandapp with their currently-published
|
|
32
|
+
* version. Works with either Basic Auth (default) or Bearer Auth — when
|
|
33
|
+
* called from a server handler that has the user's access token, pass
|
|
34
|
+
* `accessToken` to avoid sending app credentials.
|
|
35
|
+
*
|
|
36
|
+
* Accepts either an `accessToken` string (legacy) or an options object
|
|
37
|
+
* (`country`/`locale`/`jurisdiction`/`accessToken`) for jurisdiction-aware
|
|
38
|
+
* matching. When `country` / `locale` are omitted, the server falls back to
|
|
39
|
+
* request headers (`x-vercel-ip-country`, `Accept-Language`).
|
|
40
|
+
*
|
|
41
|
+
* Returns the matched terms array. For matching metadata
|
|
42
|
+
* (jurisdiction, locale, source) use {@link listWithMeta}.
|
|
43
|
+
*/
|
|
44
|
+
async list(optionsOrToken) {
|
|
45
|
+
const response = await this.listWithMeta(optionsOrToken);
|
|
46
|
+
return response.terms;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Same as {@link list} but returns the full {@link TermsListResponse} including
|
|
50
|
+
* matched jurisdiction, country and locale — useful for displaying "약관이
|
|
51
|
+
* 어떤 국가 기준으로 적용됐는지" hint in the signup UX.
|
|
52
|
+
*/
|
|
53
|
+
async listWithMeta(optionsOrToken) {
|
|
54
|
+
const options = isListOptions(optionsOrToken) ? optionsOrToken : optionsOrToken ? { accessToken: optionsOrToken } : {};
|
|
55
|
+
const query = buildListQuery(options);
|
|
56
|
+
const path = query || "";
|
|
57
|
+
const body = await this.http.fetch(
|
|
58
|
+
"GET",
|
|
59
|
+
path,
|
|
60
|
+
void 0,
|
|
61
|
+
options.accessToken ? { bearerToken: options.accessToken } : void 0
|
|
62
|
+
);
|
|
63
|
+
return unwrap(body);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Fetch the consent history (granted / withdrawn / pendingReConsent) for
|
|
67
|
+
* the OAuth user represented by `accessToken`.
|
|
68
|
+
*/
|
|
69
|
+
async listMyConsents(accessToken) {
|
|
70
|
+
const body = await this.http.fetch(
|
|
71
|
+
"GET",
|
|
72
|
+
"/me/consents",
|
|
73
|
+
void 0,
|
|
74
|
+
{ bearerToken: accessToken }
|
|
75
|
+
);
|
|
76
|
+
return unwrap(body);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Record consent for one or more terms versions. The server rejects the
|
|
80
|
+
* call with `REQUIRED_NOT_CONSENTED` (422) if any required term is missing
|
|
81
|
+
* or marked as `consented: false`.
|
|
82
|
+
*/
|
|
83
|
+
async consent(input, accessToken) {
|
|
84
|
+
const body = await this.http.fetch(
|
|
85
|
+
"POST",
|
|
86
|
+
"/me/consents",
|
|
87
|
+
input,
|
|
88
|
+
{ bearerToken: accessToken }
|
|
89
|
+
);
|
|
90
|
+
return unwrap(body);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Withdraw a previously-granted consent. The server returns 409 for
|
|
94
|
+
* required terms or already-withdrawn records.
|
|
95
|
+
*/
|
|
96
|
+
async withdraw(consentId, accessToken) {
|
|
97
|
+
const body = await this.http.fetch(
|
|
98
|
+
"DELETE",
|
|
99
|
+
`/me/consents/${encodeURIComponent(consentId)}`,
|
|
100
|
+
void 0,
|
|
101
|
+
{ bearerToken: accessToken }
|
|
102
|
+
);
|
|
103
|
+
return unwrap(body);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
function createReoptTermsClient(config) {
|
|
107
|
+
return new ReoptTermsClient(config);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { ReoptTermsClient, createReoptTermsClient };
|
|
111
|
+
//# sourceMappingURL=chunk-TUKIYH4Q.js.map
|
|
112
|
+
//# sourceMappingURL=chunk-TUKIYH4Q.js.map
|